git-annex merge branch

* merge: When run with a branch parameter, merges from that branch.
  This is especially useful when using an adjusted branch, because
  it applies the same adjustment to the branch before merging it.
This commit is contained in:
Joey Hess 2019-08-09 13:21:15 -04:00
parent b90ee6dc52
commit b87ea12b6b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 58 additions and 28 deletions

View file

@ -18,8 +18,11 @@ git-annex (7.20190731) UNRELEASED; urgency=medium
* init: When the repo is already initialized, and --version requests a * init: When the repo is already initialized, and --version requests a
different version, error out rather than silently not changing the different version, error out rather than silently not changing the
version. version.
* Fix some test suite failures on Windows. * merge: When run with a branch parameter, merges from that branch.
This is especially useful when using an adjusted branch, because
it applies the same adjustment to the branch before merging it.
* test: Add pass using adjusted unlocked branch. * test: Add pass using adjusted unlocked branch.
* Fix some test suite failures on Windows.
-- Joey Hess <id@joeyh.name> Thu, 01 Aug 2019 00:11:56 -0400 -- Joey Hess <id@joeyh.name> Thu, 01 Aug 2019 00:11:56 -0400

View file

@ -1,6 +1,6 @@
{- git-annex command {- git-annex command
- -
- Copyright 2011, 2013 Joey Hess <id@joeyh.name> - Copyright 2011-2019 Joey Hess <id@joeyh.name>
- -
- Licensed under the GNU AGPL version 3 or higher. - Licensed under the GNU AGPL version 3 or higher.
-} -}
@ -9,27 +9,38 @@ module Command.Merge where
import Command import Command
import qualified Annex.Branch import qualified Annex.Branch
import qualified Git
import qualified Git.Branch
import Annex.CurrentBranch import Annex.CurrentBranch
import Command.Sync (prepMerge, mergeLocal, mergeConfig) import Command.Sync (prepMerge, mergeLocal, mergeConfig, merge)
cmd :: Command cmd :: Command
cmd = command "merge" SectionMaintenance cmd = command "merge" SectionMaintenance
"automatically merge changes from remotes" "merge changes from remotes"
paramNothing (withParams seek) (paramOptional paramRef) (withParams seek)
seek :: CmdParams -> CommandSeek seek :: CmdParams -> CommandSeek
seek _ = do seek [] = do
commandAction mergeBranch prepMerge
commandAction mergeSynced commandAction mergeAnnexBranch
commandAction mergeSyncedBranch
seek bs = do
prepMerge
forM_ bs (commandAction . mergeBranch . Git.Ref)
seek _ = giveup ""
mergeBranch :: CommandStart mergeAnnexBranch :: CommandStart
mergeBranch = starting "merge" (ActionItemOther (Just "git-annex")) $ do mergeAnnexBranch = starting "merge" (ActionItemOther (Just "git-annex")) $ do
Annex.Branch.update Annex.Branch.update
-- commit explicitly, in case no remote branches were merged -- commit explicitly, in case no remote branches were merged
Annex.Branch.commit =<< Annex.Branch.commitMessage Annex.Branch.commit =<< Annex.Branch.commitMessage
next $ return True next $ return True
mergeSynced :: CommandStart mergeSyncedBranch :: CommandStart
mergeSynced = do mergeSyncedBranch = mergeLocal mergeConfig def =<< getCurrentBranch
prepMerge
mergeLocal mergeConfig def =<< getCurrentBranch mergeBranch :: Git.Ref -> CommandStart
mergeBranch r = starting "merge" (ActionItemOther (Just (Git.fromRef r))) $ do
currbranch <- getCurrentBranch
merge currbranch mergeConfig def Git.Branch.ManualCommit r
next $ return True

View file

@ -1848,9 +1848,7 @@ test_export_import_subdir = intmpclonerepoInDirect $ do
testimport = do testimport = do
git_annex "import" ["master:"++subdir, "--from", "foo"] @? "import of subdir failed" git_annex "import" ["master:"++subdir, "--from", "foo"] @? "import of subdir failed"
up <- Git.Merge.mergeUnrelatedHistoriesParam git_annex "merge" ["foo/master"] @? "git annex merge foo/master failed"
let mergeps = [Param "merge", Param "foo/master", Param "-mmerge"] ++ maybeToList up
boolSystem "git" mergeps @? "git merge foo/master failed"
-- Make sure that import did not import the file to the top -- Make sure that import did not import the file to the top
-- of the repo. -- of the repo.

View file

@ -24,6 +24,11 @@ To propagate commits from the adjusted branch back to the original branch,
and to other repositories, as well as to merge in changes from other and to other repositories, as well as to merge in changes from other
repositories, run `git annex sync`. repositories, run `git annex sync`.
When in an adjusted branch, using `git merge otherbranch` is often not
ideal, because merging a non-adjusted branch may lead to unncessary
merge conflicts, or add files in non-adjusted form. To avoid those
problems, use `git annex merge otherbranch`.
Re-running this command with the same options Re-running this command with the same options
while inside the adjusted branch will update the adjusted branch while inside the adjusted branch will update the adjusted branch
as necessary (eg for `--hide-missing`), and will also propagate commits as necessary (eg for `--hide-missing`), and will also propagate commits

View file

@ -35,17 +35,23 @@ kinds of special remotes will let you configure them this way.
To import from a special remote, you must specify the name of a branch. To import from a special remote, you must specify the name of a branch.
A corresponding remote tracking branch will be updated by `git annex A corresponding remote tracking branch will be updated by `git annex
import`. After that point, it's the same as if you had run a `git fetch` import`. After that point, it's the same as if you had run a `git fetch`
from a regular git remote; you can `git merge` the changes into your from a regular git remote; you can merge the changes into your
currently checked out branch. currently checked out branch.
For example: For example:
git annex import master --from myremote git annex import master --from myremote
git merge myremote/master git annex merge myremote/master
Note that you may need to pass `--allow-unrelated-histories` the first time You could just as well use `git merge myremote/master` as the second step,
you `git merge` from an import. Think of this as the remote being a but using `git-annex merge` avoids a couple of gotchas. When using adjusted
separate git repository with its own files. If you first branches, it adjusts the branch before merging from it. And it avoids
the merge failing on the first merge from an import due to unrelated
histories.
If you do use `git merge`, you can pass `--allow-unrelated-histories` the
first time you `git merge` from an import. Think of this as the remote
being a separate git repository with its own files. If you first
`git annex export` files to a remote, and then `git annex import` from it, `git annex export` files to a remote, and then `git annex import` from it,
you won't need that option. you won't need that option.

View file

@ -1,16 +1,21 @@
# NAME # NAME
git-annex merge - automatically merge changes from remotes git-annex merge - merge changes from remotes
# SYNOPSIS # SYNOPSIS
git annex merge git annex merge [branch]
# DESCRIPTION # DESCRIPTION
This performs the same merging (and merge conflict resolution) When run without any parameters, this performs the same merging (and merge
that is done by the sync command, but without pushing or pulling any conflict resolution) that is done by the sync command, but without pushing
data. or pulling any data.
When a branch to merge is specified, this merges it, using the same merge
conflict resolution as the sync command. This is especially useful on
an adjusted branch, because it applies the same adjustment to the
branch before merging it.
When annex.resolvemerge is set to false, merge conflict resolution When annex.resolvemerge is set to false, merge conflict resolution
will not be done. will not be done.
@ -21,6 +26,8 @@ will not be done.
[[git-annex-sync]](1) [[git-annex-sync]](1)
[[git-annex-adjust]](1)
# AUTHOR # AUTHOR
Joey Hess <id@joeyh.name> Joey Hess <id@joeyh.name>

View file

@ -57,7 +57,7 @@ for more details, and bear in mind that you can also use commands like
these to only import from or export to the android device: these to only import from or export to the android device:
git annex import master:android --from android git annex import master:android --from android
git merge android/master git annex merge android/master
git annex export master:android --to android git annex export master:android --to android
## sample workflows ## sample workflows