From b87ea12b6bc7ac192ad5a7d6aeeb09f802f519b4 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 9 Aug 2019 13:21:15 -0400 Subject: [PATCH] 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. --- CHANGELOG | 5 +++- Command/Merge.hs | 37 +++++++++++++++++++---------- Test.hs | 4 +--- doc/git-annex-adjust.mdwn | 5 ++++ doc/git-annex-import.mdwn | 16 +++++++++---- doc/git-annex-merge.mdwn | 17 +++++++++---- doc/tips/android_sync_with_adb.mdwn | 2 +- 7 files changed, 58 insertions(+), 28 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 4c65c5fba3..24e9bde411 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -18,8 +18,11 @@ git-annex (7.20190731) UNRELEASED; urgency=medium * init: When the repo is already initialized, and --version requests a different version, error out rather than silently not changing the 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. + * Fix some test suite failures on Windows. -- Joey Hess Thu, 01 Aug 2019 00:11:56 -0400 diff --git a/Command/Merge.hs b/Command/Merge.hs index 8870e556b8..ddeef3c688 100644 --- a/Command/Merge.hs +++ b/Command/Merge.hs @@ -1,6 +1,6 @@ {- git-annex command - - - Copyright 2011, 2013 Joey Hess + - Copyright 2011-2019 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -9,27 +9,38 @@ module Command.Merge where import Command import qualified Annex.Branch +import qualified Git +import qualified Git.Branch import Annex.CurrentBranch -import Command.Sync (prepMerge, mergeLocal, mergeConfig) +import Command.Sync (prepMerge, mergeLocal, mergeConfig, merge) cmd :: Command cmd = command "merge" SectionMaintenance - "automatically merge changes from remotes" - paramNothing (withParams seek) + "merge changes from remotes" + (paramOptional paramRef) (withParams seek) seek :: CmdParams -> CommandSeek -seek _ = do - commandAction mergeBranch - commandAction mergeSynced +seek [] = do + prepMerge + commandAction mergeAnnexBranch + commandAction mergeSyncedBranch +seek bs = do + prepMerge + forM_ bs (commandAction . mergeBranch . Git.Ref) +seek _ = giveup "" -mergeBranch :: CommandStart -mergeBranch = starting "merge" (ActionItemOther (Just "git-annex")) $ do +mergeAnnexBranch :: CommandStart +mergeAnnexBranch = starting "merge" (ActionItemOther (Just "git-annex")) $ do Annex.Branch.update -- commit explicitly, in case no remote branches were merged Annex.Branch.commit =<< Annex.Branch.commitMessage next $ return True -mergeSynced :: CommandStart -mergeSynced = do - prepMerge - mergeLocal mergeConfig def =<< getCurrentBranch +mergeSyncedBranch :: CommandStart +mergeSyncedBranch = 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 diff --git a/Test.hs b/Test.hs index 620e81f40a..dd0972fd85 100644 --- a/Test.hs +++ b/Test.hs @@ -1848,9 +1848,7 @@ test_export_import_subdir = intmpclonerepoInDirect $ do testimport = do git_annex "import" ["master:"++subdir, "--from", "foo"] @? "import of subdir failed" - up <- Git.Merge.mergeUnrelatedHistoriesParam - let mergeps = [Param "merge", Param "foo/master", Param "-mmerge"] ++ maybeToList up - boolSystem "git" mergeps @? "git merge foo/master failed" + git_annex "merge" ["foo/master"] @? "git annex merge foo/master failed" -- Make sure that import did not import the file to the top -- of the repo. diff --git a/doc/git-annex-adjust.mdwn b/doc/git-annex-adjust.mdwn index 027d14a4fc..c03a6e43b4 100644 --- a/doc/git-annex-adjust.mdwn +++ b/doc/git-annex-adjust.mdwn @@ -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 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 while inside the adjusted branch will update the adjusted branch as necessary (eg for `--hide-missing`), and will also propagate commits diff --git a/doc/git-annex-import.mdwn b/doc/git-annex-import.mdwn index a89986f013..89a30e82c5 100644 --- a/doc/git-annex-import.mdwn +++ b/doc/git-annex-import.mdwn @@ -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. 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` -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. For example: 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 `git merge` from an import. Think of this as the remote being a -separate git repository with its own files. If you first +You could just as well use `git merge myremote/master` as the second step, +but using `git-annex merge` avoids a couple of gotchas. When using adjusted +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, you won't need that option. diff --git a/doc/git-annex-merge.mdwn b/doc/git-annex-merge.mdwn index bb204d7255..a8324ba334 100644 --- a/doc/git-annex-merge.mdwn +++ b/doc/git-annex-merge.mdwn @@ -1,16 +1,21 @@ # NAME -git-annex merge - automatically merge changes from remotes +git-annex merge - merge changes from remotes # SYNOPSIS -git annex merge +git annex merge [branch] # DESCRIPTION -This performs the same merging (and merge conflict resolution) -that is done by the sync command, but without pushing or pulling any -data. +When run without any parameters, this performs the same merging (and merge +conflict resolution) that is done by the sync command, but without pushing +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 will not be done. @@ -21,6 +26,8 @@ will not be done. [[git-annex-sync]](1) +[[git-annex-adjust]](1) + # AUTHOR Joey Hess diff --git a/doc/tips/android_sync_with_adb.mdwn b/doc/tips/android_sync_with_adb.mdwn index c6b3f0f0f2..2efab4f625 100644 --- a/doc/tips/android_sync_with_adb.mdwn +++ b/doc/tips/android_sync_with_adb.mdwn @@ -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: git annex import master:android --from android - git merge android/master + git annex merge android/master git annex export master:android --to android ## sample workflows