From d120c733020b7500ef6a8624069fb2232a40c6f2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 7 Sep 2020 13:50:58 -0400 Subject: [PATCH] sync, assistant: When merge.directoryRenames is not set, default it it to "false" Works better with automatic merge conflict resolution than git's ususual default of "conflict". This is not done when automatic merge conflict resolution is disabled. This commit was sponsored by Mark Reidenbach on Patreon. --- Annex/AdjustedBranch.hs | 2 +- Annex/AutoMerge.hs | 30 +++++++++++++++---- CHANGELOG | 4 +++ Types/GitConfig.hs | 2 ++ ...breaks_sync_merge_conflict_resolution.mdwn | 2 ++ 5 files changed, 34 insertions(+), 6 deletions(-) diff --git a/Annex/AdjustedBranch.hs b/Annex/AdjustedBranch.hs index ecc3fca1ea..bc364b52d5 100644 --- a/Annex/AdjustedBranch.hs +++ b/Annex/AdjustedBranch.hs @@ -402,7 +402,7 @@ mergeToAdjustedBranch tomerge (origbranch, adj) mergeconfig canresolvemerge comm -- http://thread.gmane.org/gmane.comp.version-control.git/297237 inRepo $ Git.Command.run [Param "reset", Param "HEAD", Param "--quiet"] showAction $ "Merging into " ++ fromRef (Git.Ref.base origbranch) - merged <- autoMergeFrom' tomerge Nothing mergeconfig commitmode + merged <- autoMergeFrom' tomerge Nothing mergeconfig commitmode True (const $ resolveMerge (Just updatedorig) tomerge True) if merged then do diff --git a/Annex/AutoMerge.hs b/Annex/AutoMerge.hs index 65a4989d83..2d7c8e93d1 100644 --- a/Annex/AutoMerge.hs +++ b/Annex/AutoMerge.hs @@ -15,6 +15,7 @@ module Annex.AutoMerge ) where import Annex.Common +import qualified Annex import qualified Annex.Queue import Annex.CatFile import Annex.Link @@ -46,22 +47,41 @@ import qualified Data.ByteString.Lazy as L -} autoMergeFrom :: Git.Ref -> Maybe Git.Ref -> [Git.Merge.MergeConfig] -> Git.Branch.CommitMode -> Bool -> Annex Bool autoMergeFrom branch currbranch mergeconfig commitmode canresolvemerge = - autoMergeFrom' branch currbranch mergeconfig commitmode resolvemerge + autoMergeFrom' branch currbranch mergeconfig commitmode canresolvemerge resolvemerge where resolvemerge old | canresolvemerge = resolveMerge old branch False | otherwise = return False -autoMergeFrom' :: Git.Ref -> Maybe Git.Ref -> [Git.Merge.MergeConfig] -> Git.Branch.CommitMode -> (Maybe Git.Ref -> Annex Bool) -> Annex Bool -autoMergeFrom' branch currbranch mergeconfig commitmode resolvemerge = do +autoMergeFrom' :: Git.Ref -> Maybe Git.Ref -> [Git.Merge.MergeConfig] -> Git.Branch.CommitMode -> Bool -> (Maybe Git.Ref -> Annex Bool) -> Annex Bool +autoMergeFrom' branch currbranch mergeconfig commitmode willresolvemerge toresolvemerge = do showOutput case currbranch of Nothing -> go Nothing Just b -> go =<< inRepo (Git.Ref.sha b) where go old = do - r <- inRepo (Git.Merge.merge branch mergeconfig commitmode) - <||> (resolvemerge old <&&> commitResolvedMerge commitmode) + -- merge.directoryRenames=conflict plus automatic + -- merge conflict resolution results in files in a + -- "renamed" directory getting variant names, + -- so is not a great combination. If the user has + -- explicitly set it, use it, but otherwise when + -- merge conflicts will be resolved, override + -- to merge.directoryRenames=false. + overridedirectoryrenames <- if willresolvemerge + then isNothing . mergeDirectoryRenames + <$> Annex.getGitConfig + else pure False + let f r + | overridedirectoryrenames = r + { Git.gitGlobalOpts = + Param "-c" + : Param "merge.directoryRenames=false" + : Git.gitGlobalOpts r + } + | otherwise = r + r <- inRepo (Git.Merge.merge branch mergeconfig commitmode . f) + <||> (toresolvemerge old <&&> commitResolvedMerge commitmode) -- Merging can cause new associated files to appear -- and the smudge filter will add them to the database. -- To ensure that this process sees those changes, diff --git a/CHANGELOG b/CHANGELOG index ed7d4f8a84..1c493bad4e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -33,6 +33,10 @@ git-annex (8.20200815) UNRELEASED; urgency=medium * import: Retry downloads that fail, same as is done for downloads generally. * resolvemerge: Improve cleanup of files that were deleted by one side of a conflicted merge, and modified by the other side. + * sync, assistant, merge: When merge.directoryRenames is not set, + default it it to "false", which works better with automatic merge + conflict resolution than git's ususual default of "conflict". + (This is not done when automatic merge conflict resolution is disabled.) -- Joey Hess Fri, 14 Aug 2020 14:57:45 -0400 diff --git a/Types/GitConfig.hs b/Types/GitConfig.hs index 1b441297fd..ab586b063a 100644 --- a/Types/GitConfig.hs +++ b/Types/GitConfig.hs @@ -130,6 +130,7 @@ data GitConfig = GitConfig , receiveDenyCurrentBranch :: DenyCurrentBranch , gcryptId :: Maybe String , gpgCmd :: GpgCmd + , mergeDirectoryRenames :: Maybe String } extractGitConfig :: ConfigSource -> Git.Repo -> GitConfig @@ -223,6 +224,7 @@ extractGitConfig configsource r = GitConfig , receiveDenyCurrentBranch = getDenyCurrentBranch r , gcryptId = getmaybe "core.gcrypt-id" , gpgCmd = mkGpgCmd (getmaybe "gpg.program") + , mergeDirectoryRenames = getmaybe "directoryrenames" } where getbool k d = fromMaybe d $ getmaybebool k diff --git a/doc/bugs/new_merge.directoryRenames_behavior_breaks_sync_merge_conflict_resolution.mdwn b/doc/bugs/new_merge.directoryRenames_behavior_breaks_sync_merge_conflict_resolution.mdwn index 0adbf07481..afc2eae8f3 100644 --- a/doc/bugs/new_merge.directoryRenames_behavior_breaks_sync_merge_conflict_resolution.mdwn +++ b/doc/bugs/new_merge.directoryRenames_behavior_breaks_sync_merge_conflict_resolution.mdwn @@ -46,3 +46,5 @@ to detect it and handle it specially. > git-annex sync should set merge.directoryRenames=false when > merge.directoryRenames is not configured, unless automatic merge conflict > resolution is disabled. --[[Joey]] +> +> > [[done]] --[[Joey]]