Added annex.allowsign option.

This commit was sponsored by Ilya Shlyakhter on Patreon.
This commit is contained in:
Joey Hess 2019-11-11 16:15:05 -04:00
parent 02a8573bf2
commit 3b34d123ed
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
13 changed files with 97 additions and 32 deletions

View file

@ -59,6 +59,7 @@ import Utility.Tmp.Dir
import Utility.CopyFile import Utility.CopyFile
import qualified Database.Keys import qualified Database.Keys
import Config import Config
import Config.CommitMode
import qualified Data.Map as M import qualified Data.Map as M
@ -224,8 +225,9 @@ adjustToCrippledFileSystem :: Annex ()
adjustToCrippledFileSystem = do adjustToCrippledFileSystem = do
warning "Entering an adjusted branch where files are unlocked as this filesystem does not support locked files." warning "Entering an adjusted branch where files are unlocked as this filesystem does not support locked files."
checkVersionSupported checkVersionSupported
whenM (isNothing <$> inRepo Git.Branch.current) $ whenM (isNothing <$> inRepo Git.Branch.current) $ do
void $ inRepo $ Git.Branch.commitCommand Git.Branch.AutomaticCommit cmode <- implicitCommitMode
void $ inRepo $ Git.Branch.commitCommand cmode
[ Param "--quiet" [ Param "--quiet"
, Param "--allow-empty" , Param "--allow-empty"
, Param "-m" , Param "-m"
@ -310,12 +312,16 @@ commitAdjustedTree' :: Sha -> BasisBranch -> [Ref] -> Annex Sha
commitAdjustedTree' treesha (BasisBranch basis) parents = commitAdjustedTree' treesha (BasisBranch basis) parents =
go =<< catCommit basis go =<< catCommit basis
where where
go Nothing = inRepo mkcommit go Nothing = do
go (Just basiscommit) = inRepo $ commitWithMetaData cmode <- implicitCommitMode
(commitAuthorMetaData basiscommit) inRepo $ mkcommit cmode
(commitCommitterMetaData basiscommit) go (Just basiscommit) = do
mkcommit cmode <- implicitCommitMode
mkcommit = Git.Branch.commitTree Git.Branch.AutomaticCommit inRepo $ commitWithMetaData
(commitAuthorMetaData basiscommit)
(commitCommitterMetaData basiscommit)
(mkcommit cmode)
mkcommit cmode = Git.Branch.commitTree cmode
adjustedBranchCommitMessage parents treesha adjustedBranchCommitMessage parents treesha
{- This message should never be changed. -} {- This message should never be changed. -}
@ -444,7 +450,8 @@ mergeToAdjustedBranch tomerge (origbranch, adj) mergeconfig canresolvemerge comm
reparent adjtree adjmergecommit (Just currentcommit) = do reparent adjtree adjmergecommit (Just currentcommit) = do
if (commitTree currentcommit /= adjtree) if (commitTree currentcommit /= adjtree)
then do then do
c <- inRepo $ Git.Branch.commitTree Git.Branch.AutomaticCommit cmode <- implicitCommitMode
c <- inRepo $ Git.Branch.commitTree cmode
("Merged " ++ fromRef tomerge) [adjmergecommit] ("Merged " ++ fromRef tomerge) [adjmergecommit]
(commitTree currentcommit) (commitTree currentcommit)
inRepo $ Git.Branch.update "updating adjusted branch" currbranch c inRepo $ Git.Branch.update "updating adjusted branch" currbranch c
@ -534,12 +541,14 @@ reverseAdjustedCommit commitparent adj (csha, basiscommit) origbranch
| length (commitParent basiscommit) > 1 = return $ | length (commitParent basiscommit) > 1 = return $
Left $ "unable to propigate merge commit " ++ show csha ++ " back to " ++ show origbranch Left $ "unable to propigate merge commit " ++ show csha ++ " back to " ++ show origbranch
| otherwise = do | otherwise = do
cmode <- implicitCommitMode
treesha <- reverseAdjustedTree commitparent adj csha treesha <- reverseAdjustedTree commitparent adj csha
revadjcommit <- inRepo $ commitWithMetaData revadjcommit <- inRepo $ commitWithMetaData
(commitAuthorMetaData basiscommit) (commitAuthorMetaData basiscommit)
(commitCommitterMetaData basiscommit) $ (commitCommitterMetaData basiscommit) $
Git.Branch.commitTree Git.Branch.AutomaticCommit Git.Branch.commitTree cmode
(commitMessage basiscommit) [commitparent] treesha (commitMessage basiscommit)
[commitparent] treesha
return (Right revadjcommit) return (Right revadjcommit)
{- Adjusts the tree of the basis, changing only the files that the {- Adjusts the tree of the basis, changing only the files that the

View file

@ -70,6 +70,7 @@ import Annex.Branch.Transitions
import qualified Annex import qualified Annex
import Annex.Hook import Annex.Hook
import Utility.Directory.Stream import Utility.Directory.Stream
import Config.CommitMode
{- Name of the branch that is used to store git-annex's information. -} {- Name of the branch that is used to store git-annex's information. -}
name :: Git.Ref name :: Git.Ref
@ -109,8 +110,9 @@ getBranch = maybe (hasOrigin >>= go >>= use) return =<< branchsha
[Param "branch", Param $ fromRef name, Param $ fromRef originname] [Param "branch", Param $ fromRef name, Param $ fromRef originname]
fromMaybe (error $ "failed to create " ++ fromRef name) fromMaybe (error $ "failed to create " ++ fromRef name)
<$> branchsha <$> branchsha
go False = withIndex' True $ go False = withIndex' True $ do
inRepo $ Git.Branch.commitAlways Git.Branch.AutomaticCommit "branch created" fullname [] cmode <- implicitCommitMode
inRepo $ Git.Branch.commitAlways cmode "branch created" fullname []
use sha = do use sha = do
setIndexSha sha setIndexSha sha
return sha return sha
@ -317,7 +319,8 @@ commitIndex jl branchref message parents = do
commitIndex' :: JournalLocked -> Git.Ref -> String -> String -> Integer -> [Git.Ref] -> Annex () commitIndex' :: JournalLocked -> Git.Ref -> String -> String -> Integer -> [Git.Ref] -> Annex ()
commitIndex' jl branchref message basemessage retrynum parents = do commitIndex' jl branchref message basemessage retrynum parents = do
updateIndex jl branchref 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 setIndexSha committedref
parentrefs <- commitparents <$> catObject committedref parentrefs <- commitparents <$> catObject committedref
when (racedetected branchref parentrefs) $ when (racedetected branchref parentrefs) $
@ -551,7 +554,8 @@ performTransitionsLocked jl ts neednewlocalbranch transitionedrefs = do
Annex.Queue.flush Annex.Queue.flush
if neednewlocalbranch if neednewlocalbranch
then do 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 setIndexSha committedref
else do else do
ref <- getBranch ref <- getBranch
@ -657,9 +661,10 @@ rememberTreeish treeish graftpoint = lockJournal $ \jl -> do
origtree <- fromMaybe (giveup "unable to determine git-annex branch tree") <$> origtree <- fromMaybe (giveup "unable to determine git-annex branch tree") <$>
inRepo (Git.Ref.tree branchref) inRepo (Git.Ref.tree branchref)
addedt <- inRepo $ Git.Tree.graftTree treeish graftpoint origtree 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 "graft" [branchref] addedt
c' <- inRepo $ Git.Branch.commitTree Git.Branch.AutomaticCommit c' <- inRepo $ Git.Branch.commitTree cmode
"graft cleanup" [c] origtree "graft cleanup" [c] origtree
inRepo $ Git.Branch.update' fullname c' inRepo $ Git.Branch.update' fullname c'
-- The tree in c' is the same as the tree in branchref, -- The tree in c' is the same as the tree in branchref,

View file

@ -22,6 +22,7 @@ import qualified Git.Ref
import qualified Git.Branch import qualified Git.Branch
import Git.History import Git.History
import qualified Types.Remote as Remote import qualified Types.Remote as Remote
import Config.CommitMode
import qualified Data.Set as S import qualified Data.Set as S
@ -72,9 +73,10 @@ makeRemoteTrackingBranchMergeCommit tb commitsha =
_ -> return commitsha _ -> return commitsha
makeRemoteTrackingBranchMergeCommit' :: Sha -> Sha -> Sha -> Annex Sha makeRemoteTrackingBranchMergeCommit' :: Sha -> Sha -> Sha -> Annex Sha
makeRemoteTrackingBranchMergeCommit' commitsha importedhistory treesha = makeRemoteTrackingBranchMergeCommit' commitsha importedhistory treesha = do
cmode <- implicitCommitMode
inRepo $ Git.Branch.commitTree inRepo $ Git.Branch.commitTree
Git.Branch.AutomaticCommit cmode
"remote tracking branch" "remote tracking branch"
[commitsha, importedhistory] [commitsha, importedhistory]
treesha treesha

View file

@ -30,6 +30,7 @@ import Logs.View
import Utility.Glob import Utility.Glob
import Types.Command import Types.Command
import CmdLine.Action import CmdLine.Action
import Config.CommitMode
import qualified Data.Text as T import qualified Data.Text as T
import qualified Data.ByteString as B import qualified Data.ByteString as B
@ -418,7 +419,8 @@ withViewIndex a = do
genViewBranch :: View -> Annex Git.Branch genViewBranch :: View -> Annex Git.Branch
genViewBranch view = withViewIndex $ do genViewBranch view = withViewIndex $ do
let branch = branchView view 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 return branch
withCurrentView :: (View -> Annex a) -> Annex a withCurrentView :: (View -> Annex a) -> Annex a

View file

@ -22,6 +22,7 @@ import Logs.PreferredContent
import qualified Annex.Branch import qualified Annex.Branch
import Utility.Process.Transcript import Utility.Process.Transcript
import Config import Config
import Config.CommitMode
{- Makes a new git repository. Or, if a git repository already {- Makes a new git repository. Or, if a git repository already
- exists, returns False. -} - exists, returns False. -}
@ -53,8 +54,9 @@ initRepo True primary_assistant_repo dir desc mgroup = inDir dir $ do
initRepo' desc mgroup initRepo' desc mgroup
{- Initialize the master branch, so things that expect {- Initialize the master branch, so things that expect
- to have it will work, before any files are added. -} - to have it will work, before any files are added. -}
unlessM (Git.Config.isBare <$> gitRepo) $ unlessM (Git.Config.isBare <$> gitRepo) $ do
void $ inRepo $ Git.Branch.commitCommand Git.Branch.AutomaticCommit cmode <- implicitCommitMode
void $ inRepo $ Git.Branch.commitCommand cmode
[ Param "--quiet" [ Param "--quiet"
, Param "--allow-empty" , Param "--allow-empty"
, Param "-m" , Param "-m"

View file

@ -36,9 +36,9 @@ import qualified Annex
import Utility.InodeCache import Utility.InodeCache
import qualified Database.Keys import qualified Database.Keys
import qualified Command.Sync import qualified Command.Sync
import qualified Git.Branch
import Utility.Tuple import Utility.Tuple
import Utility.Metered import Utility.Metered
import Config.CommitMode
import Data.Time.Clock import Data.Time.Clock
import qualified Data.Set as S import qualified Data.Set as S
@ -231,7 +231,8 @@ commitStaged msg = do
case v of case v of
Left _ -> return False Left _ -> return False
Right _ -> do Right _ -> do
ok <- Command.Sync.commitStaged Git.Branch.AutomaticCommit msg cmode <- implicitCommitMode
ok <- Command.Sync.commitStaged cmode msg
when ok $ when ok $
Command.Sync.updateBranches =<< getCurrentBranch Command.Sync.updateBranches =<< getCurrentBranch
return ok return ok

View file

@ -19,6 +19,7 @@ import qualified Git
import qualified Git.Branch import qualified Git.Branch
import qualified Git.Ref import qualified Git.Ref
import qualified Command.Sync import qualified Command.Sync
import Config.CommitMode
{- This thread watches for changes to .git/refs/, and handles incoming {- This thread watches for changes to .git/refs/, and handles incoming
- pushes. -} - pushes. -}
@ -80,11 +81,13 @@ onChange file
[ "merging", Git.fromRef changedbranch [ "merging", Git.fromRef changedbranch
, "into", Git.fromRef b , "into", Git.fromRef b
] ]
void $ liftAnnex $ Command.Sync.merge void $ liftAnnex $ do
currbranch Command.Sync.mergeConfig cmode <- implicitCommitMode
def Command.Sync.merge
Git.Branch.AutomaticCommit currbranch Command.Sync.mergeConfig
changedbranch def
cmode
changedbranch
mergecurrent' _ = noop mergecurrent' _ = noop
{- Is the first branch a synced branch or remote tracking branch related {- Is the first branch a synced branch or remote tracking branch related

View file

@ -1,3 +1,9 @@
git-annex (7.20191107) UNRELEASED; urgency=medium
* Added annex.allowsign option.
-- Joey Hess <id@joeyh.name> Mon, 11 Nov 2019 15:59:47 -0400
git-annex (7.20191106) upstream; urgency=medium git-annex (7.20191106) upstream; urgency=medium
* init: Fix bug that lost modifications to unlocked files when init is * init: Fix bug that lost modifications to unlocked files when init is

View file

@ -30,9 +30,9 @@ import Utility.InodeCache
import Logs.Location import Logs.Location
import Git.FilePath import Git.FilePath
import Git.Types import Git.Types
import Git.Branch
import Types.Import import Types.Import
import Utility.Metered import Utility.Metered
import Config.CommitMode
import Control.Concurrent.STM import Control.Concurrent.STM
@ -266,7 +266,8 @@ seekRemote remote branch msubdir = do
Nothing -> giveup $ "Unable to find base tree for branch " ++ fromRef branch Nothing -> giveup $ "Unable to find base tree for branch " ++ fromRef branch
trackingcommit <- fromtrackingbranch Git.Ref.sha 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 let commitimport = commitRemote remote branch tb trackingcommit importtreeconfig importcommitconfig
importabletvar <- liftIO $ newTVarIO Nothing importabletvar <- liftIO $ newTVarIO Nothing

18
Config/CommitMode.hs Normal file
View file

@ -0,0 +1,18 @@
{- git-annex configuration
-
- Copyright 2019 Joey Hess <id@joeyh.name>
-
- 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

View file

@ -1,6 +1,6 @@
{- git-annex configuration {- git-annex configuration
- -
- Copyright 2012-2015 Joey Hess <id@joeyh.name> - Copyright 2012-2019 Joey Hess <id@joeyh.name>
- -
- Licensed under the GNU AGPL version 3 or higher. - Licensed under the GNU AGPL version 3 or higher.
-} -}
@ -105,6 +105,7 @@ data GitConfig = GitConfig
, annexJobs :: Concurrency , annexJobs :: Concurrency
, annexCacheCreds :: Bool , annexCacheCreds :: Bool
, annexAutoUpgradeRepository :: Bool , annexAutoUpgradeRepository :: Bool
, annexAllowSign :: Bool
, coreSymlinks :: Bool , coreSymlinks :: Bool
, coreSharedRepository :: SharedRepository , coreSharedRepository :: SharedRepository
, receiveDenyCurrentBranch :: DenyCurrentBranch , receiveDenyCurrentBranch :: DenyCurrentBranch
@ -186,6 +187,7 @@ extractGitConfig r = GitConfig
parseConcurrency =<< getmaybe (annex "jobs") parseConcurrency =<< getmaybe (annex "jobs")
, annexCacheCreds = getbool (annex "cachecreds") True , annexCacheCreds = getbool (annex "cachecreds") True
, annexAutoUpgradeRepository = getbool (annex "autoupgraderepository") True , annexAutoUpgradeRepository = getbool (annex "autoupgraderepository") True
, annexAllowSign = getbool (annex "allowsign") False
, coreSymlinks = getbool "core.symlinks" True , coreSymlinks = getbool "core.symlinks" True
, coreSharedRepository = getSharedRepository r , coreSharedRepository = getSharedRepository r
, receiveDenyCurrentBranch = getDenyCurrentBranch r , receiveDenyCurrentBranch = getDenyCurrentBranch r

View file

@ -1028,6 +1028,19 @@ Like other git commands, git-annex is configured via `.git/config`.
This works well in combination with annex.alwayscommit=false, This works well in combination with annex.alwayscommit=false,
to gather up a set of changes and commit them with a message you specify. 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` * `annex.merge-annex-branches`
By default, git-annex branches that have been pulled from remotes By default, git-annex branches that have been pulled from remotes

View file

@ -806,6 +806,7 @@ Executable git-annex
Command.Whereis Command.Whereis
Common Common
Config Config
Config.CommitMode
Config.Cost Config.Cost
Config.Files Config.Files
Config.DynamicConfig Config.DynamicConfig