From 3b34d123eda5c04fee47710734a6b49cb257c5a9 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 11 Nov 2019 16:15:05 -0400 Subject: [PATCH] Added annex.allowsign option. This commit was sponsored by Ilya Shlyakhter on Patreon. --- Annex/AdjustedBranch.hs | 31 ++++++++++++++++++++----------- Annex/Branch.hs | 17 +++++++++++------ Annex/RemoteTrackingBranch.hs | 6 ++++-- Annex/View.hs | 4 +++- Assistant/MakeRepo.hs | 6 ++++-- Assistant/Threads/Committer.hs | 5 +++-- Assistant/Threads/Merger.hs | 13 ++++++++----- CHANGELOG | 6 ++++++ Command/Import.hs | 5 +++-- Config/CommitMode.hs | 18 ++++++++++++++++++ Types/GitConfig.hs | 4 +++- doc/git-annex.mdwn | 13 +++++++++++++ git-annex.cabal | 1 + 13 files changed, 97 insertions(+), 32 deletions(-) create mode 100644 Config/CommitMode.hs diff --git a/Annex/AdjustedBranch.hs b/Annex/AdjustedBranch.hs index 131f1dd708..bd4341163a 100644 --- a/Annex/AdjustedBranch.hs +++ b/Annex/AdjustedBranch.hs @@ -59,6 +59,7 @@ import Utility.Tmp.Dir import Utility.CopyFile import qualified Database.Keys import Config +import Config.CommitMode import qualified Data.Map as M @@ -224,8 +225,9 @@ adjustToCrippledFileSystem :: Annex () adjustToCrippledFileSystem = do warning "Entering an adjusted branch where files are unlocked as this filesystem does not support locked files." checkVersionSupported - whenM (isNothing <$> inRepo Git.Branch.current) $ - void $ inRepo $ Git.Branch.commitCommand Git.Branch.AutomaticCommit + whenM (isNothing <$> inRepo Git.Branch.current) $ do + cmode <- implicitCommitMode + void $ inRepo $ Git.Branch.commitCommand cmode [ Param "--quiet" , Param "--allow-empty" , Param "-m" @@ -310,12 +312,16 @@ commitAdjustedTree' :: Sha -> BasisBranch -> [Ref] -> Annex Sha commitAdjustedTree' treesha (BasisBranch basis) parents = go =<< catCommit basis where - go Nothing = inRepo mkcommit - go (Just basiscommit) = inRepo $ commitWithMetaData - (commitAuthorMetaData basiscommit) - (commitCommitterMetaData basiscommit) - mkcommit - mkcommit = Git.Branch.commitTree Git.Branch.AutomaticCommit + go Nothing = do + cmode <- implicitCommitMode + inRepo $ mkcommit cmode + go (Just basiscommit) = do + cmode <- implicitCommitMode + inRepo $ commitWithMetaData + (commitAuthorMetaData basiscommit) + (commitCommitterMetaData basiscommit) + (mkcommit cmode) + mkcommit cmode = Git.Branch.commitTree cmode adjustedBranchCommitMessage parents treesha {- This message should never be changed. -} @@ -444,7 +450,8 @@ mergeToAdjustedBranch tomerge (origbranch, adj) mergeconfig canresolvemerge comm reparent adjtree adjmergecommit (Just currentcommit) = do if (commitTree currentcommit /= adjtree) then do - c <- inRepo $ Git.Branch.commitTree Git.Branch.AutomaticCommit + cmode <- implicitCommitMode + c <- inRepo $ Git.Branch.commitTree cmode ("Merged " ++ fromRef tomerge) [adjmergecommit] (commitTree currentcommit) inRepo $ Git.Branch.update "updating adjusted branch" currbranch c @@ -534,12 +541,14 @@ reverseAdjustedCommit commitparent adj (csha, basiscommit) origbranch | length (commitParent basiscommit) > 1 = return $ Left $ "unable to propigate merge commit " ++ show csha ++ " back to " ++ show origbranch | otherwise = do + cmode <- implicitCommitMode treesha <- reverseAdjustedTree commitparent adj csha revadjcommit <- inRepo $ commitWithMetaData (commitAuthorMetaData basiscommit) (commitCommitterMetaData basiscommit) $ - Git.Branch.commitTree Git.Branch.AutomaticCommit - (commitMessage basiscommit) [commitparent] treesha + Git.Branch.commitTree cmode + (commitMessage basiscommit) + [commitparent] treesha return (Right revadjcommit) {- Adjusts the tree of the basis, changing only the files that the diff --git a/Annex/Branch.hs b/Annex/Branch.hs index b033c059cf..d520b0bff0 100644 --- a/Annex/Branch.hs +++ b/Annex/Branch.hs @@ -70,6 +70,7 @@ import Annex.Branch.Transitions import qualified Annex import Annex.Hook import Utility.Directory.Stream +import Config.CommitMode {- Name of the branch that is used to store git-annex's information. -} name :: Git.Ref @@ -109,8 +110,9 @@ getBranch = maybe (hasOrigin >>= go >>= use) return =<< branchsha [Param "branch", Param $ fromRef name, Param $ fromRef originname] fromMaybe (error $ "failed to create " ++ fromRef name) <$> branchsha - go False = withIndex' True $ - inRepo $ Git.Branch.commitAlways Git.Branch.AutomaticCommit "branch created" fullname [] + go False = withIndex' True $ do + cmode <- implicitCommitMode + inRepo $ Git.Branch.commitAlways cmode "branch created" fullname [] use sha = do setIndexSha sha return sha @@ -317,7 +319,8 @@ commitIndex jl branchref message parents = do commitIndex' :: JournalLocked -> Git.Ref -> String -> String -> Integer -> [Git.Ref] -> Annex () commitIndex' jl branchref message basemessage retrynum parents = do updateIndex jl branchref - committedref <- inRepo $ Git.Branch.commitAlways Git.Branch.AutomaticCommit message fullname parents + cmode <- implicitCommitMode + committedref <- inRepo $ Git.Branch.commitAlways cmode message fullname parents setIndexSha committedref parentrefs <- commitparents <$> catObject committedref when (racedetected branchref parentrefs) $ @@ -551,7 +554,8 @@ performTransitionsLocked jl ts neednewlocalbranch transitionedrefs = do Annex.Queue.flush if neednewlocalbranch then do - committedref <- inRepo $ Git.Branch.commitAlways Git.Branch.AutomaticCommit message fullname transitionedrefs + cmode <- implicitCommitMode + committedref <- inRepo $ Git.Branch.commitAlways cmode message fullname transitionedrefs setIndexSha committedref else do ref <- getBranch @@ -657,9 +661,10 @@ rememberTreeish treeish graftpoint = lockJournal $ \jl -> do origtree <- fromMaybe (giveup "unable to determine git-annex branch tree") <$> inRepo (Git.Ref.tree branchref) addedt <- inRepo $ Git.Tree.graftTree treeish graftpoint origtree - c <- inRepo $ Git.Branch.commitTree Git.Branch.AutomaticCommit + cmode <- implicitCommitMode + c <- inRepo $ Git.Branch.commitTree cmode "graft" [branchref] addedt - c' <- inRepo $ Git.Branch.commitTree Git.Branch.AutomaticCommit + c' <- inRepo $ Git.Branch.commitTree cmode "graft cleanup" [c] origtree inRepo $ Git.Branch.update' fullname c' -- The tree in c' is the same as the tree in branchref, diff --git a/Annex/RemoteTrackingBranch.hs b/Annex/RemoteTrackingBranch.hs index 02f0bb01b4..6c1d642f58 100644 --- a/Annex/RemoteTrackingBranch.hs +++ b/Annex/RemoteTrackingBranch.hs @@ -22,6 +22,7 @@ import qualified Git.Ref import qualified Git.Branch import Git.History import qualified Types.Remote as Remote +import Config.CommitMode import qualified Data.Set as S @@ -72,9 +73,10 @@ makeRemoteTrackingBranchMergeCommit tb commitsha = _ -> return commitsha makeRemoteTrackingBranchMergeCommit' :: Sha -> Sha -> Sha -> Annex Sha -makeRemoteTrackingBranchMergeCommit' commitsha importedhistory treesha = +makeRemoteTrackingBranchMergeCommit' commitsha importedhistory treesha = do + cmode <- implicitCommitMode inRepo $ Git.Branch.commitTree - Git.Branch.AutomaticCommit + cmode "remote tracking branch" [commitsha, importedhistory] treesha diff --git a/Annex/View.hs b/Annex/View.hs index a136b6b842..da72436a5a 100644 --- a/Annex/View.hs +++ b/Annex/View.hs @@ -30,6 +30,7 @@ import Logs.View import Utility.Glob import Types.Command import CmdLine.Action +import Config.CommitMode import qualified Data.Text as T import qualified Data.ByteString as B @@ -418,7 +419,8 @@ withViewIndex a = do genViewBranch :: View -> Annex Git.Branch genViewBranch view = withViewIndex $ do let branch = branchView view - void $ inRepo $ Git.Branch.commit Git.Branch.AutomaticCommit True (fromRef branch) branch [] + cmode <- implicitCommitMode + void $ inRepo $ Git.Branch.commit cmode True (fromRef branch) branch [] return branch withCurrentView :: (View -> Annex a) -> Annex a diff --git a/Assistant/MakeRepo.hs b/Assistant/MakeRepo.hs index 372f216630..fd768ee9f9 100644 --- a/Assistant/MakeRepo.hs +++ b/Assistant/MakeRepo.hs @@ -22,6 +22,7 @@ import Logs.PreferredContent import qualified Annex.Branch import Utility.Process.Transcript import Config +import Config.CommitMode {- Makes a new git repository. Or, if a git repository already - exists, returns False. -} @@ -53,8 +54,9 @@ initRepo True primary_assistant_repo dir desc mgroup = inDir dir $ do initRepo' desc mgroup {- Initialize the master branch, so things that expect - to have it will work, before any files are added. -} - unlessM (Git.Config.isBare <$> gitRepo) $ - void $ inRepo $ Git.Branch.commitCommand Git.Branch.AutomaticCommit + unlessM (Git.Config.isBare <$> gitRepo) $ do + cmode <- implicitCommitMode + void $ inRepo $ Git.Branch.commitCommand cmode [ Param "--quiet" , Param "--allow-empty" , Param "-m" diff --git a/Assistant/Threads/Committer.hs b/Assistant/Threads/Committer.hs index a81f21f65c..ec2aa663a1 100644 --- a/Assistant/Threads/Committer.hs +++ b/Assistant/Threads/Committer.hs @@ -36,9 +36,9 @@ import qualified Annex import Utility.InodeCache import qualified Database.Keys import qualified Command.Sync -import qualified Git.Branch import Utility.Tuple import Utility.Metered +import Config.CommitMode import Data.Time.Clock import qualified Data.Set as S @@ -231,7 +231,8 @@ commitStaged msg = do case v of Left _ -> return False Right _ -> do - ok <- Command.Sync.commitStaged Git.Branch.AutomaticCommit msg + cmode <- implicitCommitMode + ok <- Command.Sync.commitStaged cmode msg when ok $ Command.Sync.updateBranches =<< getCurrentBranch return ok diff --git a/Assistant/Threads/Merger.hs b/Assistant/Threads/Merger.hs index d1f29e7845..b602f1cdf6 100644 --- a/Assistant/Threads/Merger.hs +++ b/Assistant/Threads/Merger.hs @@ -19,6 +19,7 @@ import qualified Git import qualified Git.Branch import qualified Git.Ref import qualified Command.Sync +import Config.CommitMode {- This thread watches for changes to .git/refs/, and handles incoming - pushes. -} @@ -80,11 +81,13 @@ onChange file [ "merging", Git.fromRef changedbranch , "into", Git.fromRef b ] - void $ liftAnnex $ Command.Sync.merge - currbranch Command.Sync.mergeConfig - def - Git.Branch.AutomaticCommit - changedbranch + void $ liftAnnex $ do + cmode <- implicitCommitMode + Command.Sync.merge + currbranch Command.Sync.mergeConfig + def + cmode + changedbranch mergecurrent' _ = noop {- Is the first branch a synced branch or remote tracking branch related diff --git a/CHANGELOG b/CHANGELOG index da88c214f5..f59d029eef 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +git-annex (7.20191107) UNRELEASED; urgency=medium + + * Added annex.allowsign option. + + -- Joey Hess Mon, 11 Nov 2019 15:59:47 -0400 + git-annex (7.20191106) upstream; urgency=medium * init: Fix bug that lost modifications to unlocked files when init is diff --git a/Command/Import.hs b/Command/Import.hs index 0a77642789..74b2752116 100644 --- a/Command/Import.hs +++ b/Command/Import.hs @@ -30,9 +30,9 @@ import Utility.InodeCache import Logs.Location import Git.FilePath import Git.Types -import Git.Branch import Types.Import import Utility.Metered +import Config.CommitMode import Control.Concurrent.STM @@ -266,7 +266,8 @@ seekRemote remote branch msubdir = do Nothing -> giveup $ "Unable to find base tree for branch " ++ fromRef branch trackingcommit <- fromtrackingbranch Git.Ref.sha - let importcommitconfig = ImportCommitConfig trackingcommit AutomaticCommit importmessage + cmode <- implicitCommitMode + let importcommitconfig = ImportCommitConfig trackingcommit cmode importmessage let commitimport = commitRemote remote branch tb trackingcommit importtreeconfig importcommitconfig importabletvar <- liftIO $ newTVarIO Nothing diff --git a/Config/CommitMode.hs b/Config/CommitMode.hs new file mode 100644 index 0000000000..ef082e6f4a --- /dev/null +++ b/Config/CommitMode.hs @@ -0,0 +1,18 @@ +{- git-annex configuration + - + - Copyright 2019 Joey Hess + - + - Licensed under the GNU AGPL version 3 or higher. + -} + +module Config.CommitMode where + +import Annex.Common +import qualified Annex +import Git.Branch (CommitMode(..)) + +implicitCommitMode :: Annex CommitMode +implicitCommitMode = go . annexAllowSign <$> Annex.getGitConfig + where + go True = ManualCommit + go False = AutomaticCommit diff --git a/Types/GitConfig.hs b/Types/GitConfig.hs index 36224b14c3..6f5be1d323 100644 --- a/Types/GitConfig.hs +++ b/Types/GitConfig.hs @@ -1,6 +1,6 @@ {- git-annex configuration - - - Copyright 2012-2015 Joey Hess + - Copyright 2012-2019 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -105,6 +105,7 @@ data GitConfig = GitConfig , annexJobs :: Concurrency , annexCacheCreds :: Bool , annexAutoUpgradeRepository :: Bool + , annexAllowSign :: Bool , coreSymlinks :: Bool , coreSharedRepository :: SharedRepository , receiveDenyCurrentBranch :: DenyCurrentBranch @@ -186,6 +187,7 @@ extractGitConfig r = GitConfig parseConcurrency =<< getmaybe (annex "jobs") , annexCacheCreds = getbool (annex "cachecreds") True , annexAutoUpgradeRepository = getbool (annex "autoupgraderepository") True + , annexAllowSign = getbool (annex "allowsign") False , coreSymlinks = getbool "core.symlinks" True , coreSharedRepository = getSharedRepository r , receiveDenyCurrentBranch = getDenyCurrentBranch r diff --git a/doc/git-annex.mdwn b/doc/git-annex.mdwn index fedc6b8425..43f6560484 100644 --- a/doc/git-annex.mdwn +++ b/doc/git-annex.mdwn @@ -1028,6 +1028,19 @@ Like other git commands, git-annex is configured via `.git/config`. This works well in combination with annex.alwayscommit=false, to gather up a set of changes and commit them with a message you specify. +* `annex.allowsign` + + By default git-annex avoids gpg signing commits that it makes when + they're not the purpose of a command, but only a side effect. + That default avoids lots of gpg password prompts when + commit.gpgSign is set. A command like `git annex sync` or `git annex merge` + will gpg sign its commit, but a command like `git annex get`, + that updates the git-annex branch, will not. The assistant also avoids + signing commits. + + Setting annex.allowsign to true lets all commits be signed, as + controlled by commit.gpgSign and other git configuration. + * `annex.merge-annex-branches` By default, git-annex branches that have been pulled from remotes diff --git a/git-annex.cabal b/git-annex.cabal index 98a061b573..452a0fd18b 100644 --- a/git-annex.cabal +++ b/git-annex.cabal @@ -806,6 +806,7 @@ Executable git-annex Command.Whereis Common Config + Config.CommitMode Config.Cost Config.Files Config.DynamicConfig