avoid using --no-gpg-sign with old versions of git
and refactor some
This commit is contained in:
parent
fc67925fd7
commit
1c1f463c3a
1 changed files with 14 additions and 11 deletions
|
@ -14,6 +14,7 @@ import Git
|
||||||
import Git.Sha
|
import Git.Sha
|
||||||
import Git.Command
|
import Git.Command
|
||||||
import qualified Git.Ref
|
import qualified Git.Ref
|
||||||
|
import qualified Git.BuildVersion
|
||||||
|
|
||||||
{- The currently checked out branch.
|
{- The currently checked out branch.
|
||||||
-
|
-
|
||||||
|
@ -110,6 +111,12 @@ fastForward branch (first:rest) repo =
|
||||||
data CommitMode = ManualCommit | AutomaticCommit
|
data CommitMode = ManualCommit | AutomaticCommit
|
||||||
deriving (Eq)
|
deriving (Eq)
|
||||||
|
|
||||||
|
applyCommitMode :: CommitMode -> [CommandParam] -> [CommandParam]
|
||||||
|
applyCommitMode commitmode ps
|
||||||
|
| commitmode == AutomaticCommit && not (Git.BuildVersion.older "1.8.5") =
|
||||||
|
Param "--no-gpg-sign" : ps
|
||||||
|
| otherwise = ps
|
||||||
|
|
||||||
{- Commit via the usual git command. -}
|
{- Commit via the usual git command. -}
|
||||||
commitCommand :: CommitMode -> [CommandParam] -> Repo -> IO Bool
|
commitCommand :: CommitMode -> [CommandParam] -> Repo -> IO Bool
|
||||||
commitCommand = commitCommand' runBool
|
commitCommand = commitCommand' runBool
|
||||||
|
@ -119,11 +126,8 @@ commitQuiet :: CommitMode -> [CommandParam] -> Repo -> IO ()
|
||||||
commitQuiet commitmode ps = void . tryIO . commitCommand' runQuiet commitmode ps
|
commitQuiet commitmode ps = void . tryIO . commitCommand' runQuiet commitmode ps
|
||||||
|
|
||||||
commitCommand' :: ([CommandParam] -> Repo -> IO a) -> CommitMode -> [CommandParam] -> Repo -> IO a
|
commitCommand' :: ([CommandParam] -> Repo -> IO a) -> CommitMode -> [CommandParam] -> Repo -> IO a
|
||||||
commitCommand' runner commitmode ps = runner (Param "commit" : ps')
|
commitCommand' runner commitmode ps = runner $
|
||||||
where
|
Param "commit" : applyCommitMode commitmode ps
|
||||||
ps'
|
|
||||||
| commitmode == AutomaticCommit = Param "--no-gpg-sign" : ps
|
|
||||||
| otherwise = ps
|
|
||||||
|
|
||||||
{- Commits the index into the specified branch (or other ref),
|
{- Commits the index into the specified branch (or other ref),
|
||||||
- with the specified parent refs, and returns the committed sha.
|
- with the specified parent refs, and returns the committed sha.
|
||||||
|
@ -140,22 +144,21 @@ commit commitmode allowempty message branch parentrefs repo = do
|
||||||
pipeReadStrict [Param "write-tree"] repo
|
pipeReadStrict [Param "write-tree"] repo
|
||||||
ifM (cancommit tree)
|
ifM (cancommit tree)
|
||||||
( do
|
( do
|
||||||
sha <- getSha "commit-tree" $ pipeWriteRead
|
sha <- getSha "commit-tree" $
|
||||||
(map Param $ ["commit-tree", fromRef tree] ++ ps)
|
pipeWriteRead ([Param "commit-tree", Param (fromRef tree)] ++ ps) sendmsg repo
|
||||||
(Just $ flip hPutStr message) repo
|
|
||||||
update branch sha repo
|
update branch sha repo
|
||||||
return $ Just sha
|
return $ Just sha
|
||||||
, return Nothing
|
, return Nothing
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
ps =
|
ps = applyCommitMode commitmode $
|
||||||
(if commitmode == AutomaticCommit then ["--no-gpg-sign"] else [])
|
map Param $ concatMap (\r -> ["-p", fromRef r]) parentrefs
|
||||||
++ concatMap (\r -> ["-p", fromRef r]) parentrefs
|
|
||||||
cancommit tree
|
cancommit tree
|
||||||
| allowempty = return True
|
| allowempty = return True
|
||||||
| otherwise = case parentrefs of
|
| otherwise = case parentrefs of
|
||||||
[p] -> maybe False (tree /=) <$> Git.Ref.tree p repo
|
[p] -> maybe False (tree /=) <$> Git.Ref.tree p repo
|
||||||
_ -> return True
|
_ -> return True
|
||||||
|
sendmsg = Just $ flip hPutStr message
|
||||||
|
|
||||||
commitAlways :: CommitMode -> String -> Branch -> [Ref] -> Repo -> IO Sha
|
commitAlways :: CommitMode -> String -> Branch -> [Ref] -> Repo -> IO Sha
|
||||||
commitAlways commitmode message branch parentrefs repo = fromJust
|
commitAlways commitmode message branch parentrefs repo = fromJust
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue