push: Support --cleanup

This option is not specific to sync, so it seemed it should be in either
pull or push as well as sync. Since it does modify the remote, it seems
better to have it in push; the modification of the local repo pulls in
the direction of pull, but not hard enough.

Maybe it would be better to have it in both?

Sponsored-by: Luke Shumaker on Patreon
This commit is contained in:
Joey Hess 2023-05-17 12:46:22 -04:00
parent 31d21578c3
commit af6b73a7e6
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 29 additions and 31 deletions

View file

@ -151,15 +151,15 @@ optParser mode desc = SyncOptions
( long "not-only-annex"
<> help "operate on git branches as well as annex"
)
<*> unlesssync False (switch
<*> unlessmode SyncMode False (switch
( long "commit"
<> help "commit changes to git"
))
<*> unlesssync True (switch
<*> unlessmode SyncMode True (switch
( long "no-commit"
<> help "avoid git commit"
))
<*> unlesssync Nothing (optional (strOption
<*> unlessmode SyncMode Nothing (optional (strOption
( long "message" <> short 'm' <> metavar "MSG"
<> help "commit message"
)))
@ -190,24 +190,22 @@ optParser mode desc = SyncOptions
<> help "transfer contents of annexed files in a given location"
<> metavar paramPath
))
<*> unlesssync False (switch
<*> unlessmode PullMode False (switch
( long "cleanup"
<> help "remove synced/ branches from previous sync"
))
<*> optional parseAllOption
<*> case mode of
PushMode -> pure False
_ -> invertableSwitch "resolvemerge" True
( help "do not automatically resolve merge conflicts"
)
<*> unlessmode PushMode False (invertableSwitch "resolvemerge" True
( help "do not automatically resolve merge conflicts"
))
<*> case mode of
PushMode -> pure False
_ -> parseUnrelatedHistoriesOption
<*> pure mode
where
unlesssync v a = case mode of
SyncMode -> a
_ -> pure v
unlessmode m v a
| mode /= m = a
| otherwise = pure v
parseUnrelatedHistoriesOption :: Parser Bool
parseUnrelatedHistoriesOption =

View file

@ -22,11 +22,11 @@ not normally update the remote's current branch with changes from the local
repository. (Unless the remote is configured with
receive.denyCurrentBranch=updateInstead.)
To make working with such non-bare remotes easier, this command pushes not only
local `master` to remote `master`, but also to remote `synced/master` (and
similar with other branches). When `git-annex pull` (or `git-annex sync`)
is later run on the remote, it will merge the `synced/` branches that
were pushed to it.
To make working with such non-bare remotes easier, this command pushes not
only local `master` to remote `master`, but also to remote `synced/master`
(and similar with other branches). When `git-annex pull` (or `git-annex
sync`) is later run on the remote, it will merge the `synced/` branches
that were pushed to it.
Some special remotes allow exporting a tree of files to them,
and this command can be used to push to those remotes as well
@ -108,6 +108,20 @@ See [[git-annex-preferred-content]](1).
Setting this to "cpus" will run one job per CPU core.
* `--cleanup`
Removes the local and remote `synced/` branches, which were created
and pushed by `git-annex push` or `git-annex sync`. This option
prevents all other activities.
This can come in handy when you've pushed a change to remotes and now
want to reset your master branch back before that change. So you
run `git reset` and force-push the master branch to remotes, only
to find that the next `git annex merge` or `git annex pull` brings the
changes back. Why? Because the `synced/master` branch is hanging
around and still has the change in it. Cleaning up the `synced/` branches
prevents that problem.
* Also the [[git-annex-common-options]](1) can be used.
# SEE ALSO

View file

@ -61,20 +61,6 @@ content by default. This may change in a future version of git-annex.
When `remote.<name>.annex-sync` is set to false, pushing is disabled for
that remote, and using `--push` will not enable it.
* `--cleanup`
Removes the local and remote `synced/` branches, which were created
and pushed by `git-annex sync`. This option prevents all other syncing
activities.
This can come in handy when you've synced a change to remotes and now
want to reset your master branch back before that change. So you
run `git reset` and force-push the master branch to remotes, only
to find that the next `git annex merge` or `git annex sync` brings the
changes back. Why? Because the `synced/master` branch is hanging
around and still has the change in it. Cleaning up the `synced/` branches
prevents that problem.
* Also all options supported by [[git-annex-pull]](1) and
[[git-annex-push]](1) can be used.