git-annex assist

assist: New command, which is the same as git-annex sync but with
new files added and content transferred by default.

(Also this fixes another reversion in git-annex sync,
--commit --no-commit, and --message were not enabled, oops.)

See added comment for why git-annex assist does commit staged
changes elsewhere in the work tree, but only adds files under
the cwd.

Note that it does not support --no-commit, --no-push, --no-pull
like sync does. My thinking is, why should it? If you want that
level of control, use git commit, git annex push, git annex pull.
Sync only got those options because pull and push were not split
out.

Sponsored-by: k0ld on Patreon
This commit is contained in:
Joey Hess 2023-05-18 14:37:29 -04:00
parent 80e9a655f8
commit e955912ad0
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
16 changed files with 224 additions and 47 deletions

View file

@ -86,7 +86,10 @@ checkGitIgnoreSwitch = CheckGitIgnore <$>
(help "Do not check .gitignore when adding files")
seek :: AddOptions -> CommandSeek
seek o = startConcurrency commandStages $ do
seek o = startConcurrency commandStages (seek' o)
seek' :: AddOptions -> CommandSeek
seek' o = do
largematcher <- largeFilesMatcher
addunlockedmatcher <- addUnlockedMatcher
annexdotfiles <- getGitConfigVal annexDotFiles

43
Command/Assist.hs Normal file
View file

@ -0,0 +1,43 @@
{- git-annex command
-
- Copyright 2023 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
module Command.Assist (cmd) where
import Command
import qualified Command.Sync
import qualified Command.Add
import Annex.CheckIgnore
cmd :: Command
cmd = withAnnexOptions [jobsOption, backendOption] $
command "assist" SectionCommon
"add files and sync changes with remotes"
(paramRepeating paramRemote)
(myseek <--< Command.Sync.optParser Command.Sync.AssistMode)
myseek :: Command.Sync.SyncOptions -> CommandSeek
myseek o = startConcurrency transferStages $ do
-- Run before prepMerge so it adds only files in the current
-- directory and below, not new files elsewhere in the working
-- tree.
Command.Add.seek Command.Add.AddOptions
{ Command.Add.addThese = []
, Command.Add.batchOption = NoBatch
, Command.Add.updateOnly = False
, Command.Add.largeFilesOverride = Nothing
, Command.Add.checkGitIgnoreOption = CheckGitIgnore (False)
, Command.Add.dryRunOption = DryRun False
}
Command.Sync.prepMerge
Command.Sync.seek' o'
where
o'
| Command.Sync.contentOption o == Nothing
&& Command.Sync.noContentOption o == Nothing =
o { Command.Sync.contentOption = Just True }
| otherwise = o

View file

@ -24,7 +24,7 @@ cmd :: Command
cmd = dontCheck repoExists $ notBareRepo $
noRepo (startNoRepo <$$> optParser) $
command "assistant" SectionCommon
"automatically sync changes"
"daemon to add files and automatically sync changes"
paramNothing (seek <$$> optParser)
data AssistantOptions = AssistantOptions

View file

@ -12,6 +12,7 @@
module Command.Sync (
cmd,
seek,
seek',
CurrBranch,
mergeConfig,
merge,
@ -94,7 +95,7 @@ cmd = withAnnexOptions [jobsOption, backendOption] $
"synchronize local repository with remotes"
(paramRepeating paramRemote) (seek <--< optParser SyncMode)
data OperationMode = SyncMode | PullMode | PushMode
data OperationMode = SyncMode | PullMode | PushMode | AssistMode
deriving (Eq, Show)
data SyncOptions = SyncOptions
@ -151,15 +152,15 @@ optParser mode desc = SyncOptions
( long "not-only-annex"
<> help "operate on git branches as well as annex"
)
<*> unlessmode SyncMode False (switch
<*> unlessmode [SyncMode] False (switch
( long "commit"
<> help "commit changes to git"
))
<*> unlessmode SyncMode True (switch
<*> unlessmode [SyncMode] True (switch
( long "no-commit"
<> help "avoid git commit"
))
<*> unlessmode SyncMode Nothing (optional (strOption
<*> unlessmode [SyncMode, AssistMode] Nothing (optional (strOption
( long "message" <> short 'm' <> metavar "MSG"
<> help "commit message"
)))
@ -169,12 +170,14 @@ optParser mode desc = SyncOptions
)
PullMode -> pure True
PushMode -> pure False
AssistMode -> pure True
<*> case mode of
SyncMode -> invertableSwitch "push" True
( help "avoid git pushes to remotes"
)
PullMode -> pure False
PushMode -> pure True
AssistMode -> pure True
<*> optional (flag' True
( long "content"
<> help "transfer annexed file contents"
@ -190,25 +193,24 @@ optParser mode desc = SyncOptions
<> help "transfer contents of annexed files in a given location"
<> metavar paramPath
))
<*> whenmode PullMode False (switch
<*> whenmode [PullMode] False (switch
( long "cleanup"
<> help "remove synced/ branches from previous sync"
))
<*> optional parseAllOption
<*> whenmode PushMode False (invertableSwitch "resolvemerge" True
<*> whenmode [PushMode] False (invertableSwitch "resolvemerge" True
( help "do not automatically resolve merge conflicts"
))
<*> case mode of
PushMode -> pure False
_ -> parseUnrelatedHistoriesOption
<*> whenmode [PushMode] False
parseUnrelatedHistoriesOption
<*> pure mode
where
unlessmode m v a
| mode /= m = pure v
| otherwise = a
whenmode m v a
| mode == m = pure v
| mode `elem` m = pure v
| otherwise = a
unlessmode m v a
| mode `elem` m = a
| otherwise = pure v
parseUnrelatedHistoriesOption :: Parser Bool
parseUnrelatedHistoriesOption =
@ -240,8 +242,9 @@ instance DeferredParseClass SyncOptions where
seek :: SyncOptions -> CommandSeek
seek o = do
warnSyncContentTransition o
prepMerge
startConcurrency transferStages (seek' o)
seek' :: SyncOptions -> CommandSeek
@ -828,6 +831,7 @@ seekSyncContent o rs currbranch = do
SyncMode -> "sync"
PullMode -> "pull"
PushMode -> "push"
AssistMode -> "assist"
gofile bloom mvar _ f k =
go (Right bloom) mvar (AssociatedFile (Just f)) k
@ -1044,7 +1048,7 @@ cleanupRemote remote (Just b, _) =
shouldSyncContent :: SyncOptions -> Annex Bool
shouldSyncContent o
| fromMaybe False (noContentOption o) = pure False
-- For git-annex pull and git-annex push,
-- For git-annex pull and git-annex push and git-annex assist,
-- annex.syncontent defaults to True unless set
| operationMode o /= SyncMode = annexsynccontent True
| fromMaybe False (contentOption o) || not (null (contentOfOption o)) = pure True

View file

@ -14,7 +14,7 @@ import Utility.HumanTime
cmd :: Command
cmd = notBareRepo $
command "watch" SectionCommon
"watch for changes and autocommit"
"daemon to watch for changes and autocommit"
paramNothing (seek <$$> const (parseDaemonOptions True))
seek :: DaemonOptions -> CommandSeek