From b6bea0d3f2c9095e91879d2c0c1d5f8393e59735 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 19 Jul 2021 11:40:48 -0400 Subject: [PATCH] remove direct mode remnant of merging unrelated histories sync, merge, post-receive: Avoid merging unrelated histories, which used to be allowed only to support direct mode repositories. (However, sync does still merge unrelated histories when importing trees from special remotes, and the assistant still merges unrelated histories always.) See 556b2ded2ba8270846fa207255b4c2def6ef5d8a for why this was added back in 2016, for direct mode. This is a behavior change, which might break something that was relying on sync merging unrelated histories, but git had a good reason to prevent it, since it's easy to foot shoot with it, and git-annex should follow suit. Sponsored-by: Noam Kremen on Patreon --- Assistant/Sync.hs | 3 ++- Assistant/Threads/Merger.hs | 3 ++- CHANGELOG | 5 +++++ Command/Merge.hs | 4 ++-- Command/PostReceive.hs | 2 +- Command/Sync.hs | 35 +++++++++++++++++++---------------- 6 files changed, 31 insertions(+), 21 deletions(-) diff --git a/Assistant/Sync.hs b/Assistant/Sync.hs index 487cf5be55..df51a1c5ed 100644 --- a/Assistant/Sync.hs +++ b/Assistant/Sync.hs @@ -213,7 +213,8 @@ syncAction rs a manualPull :: Command.Sync.CurrBranch -> [Remote] -> Assistant ([Remote], Bool) manualPull currentbranch remotes = do g <- liftAnnex gitRepo - mc <- liftAnnex Command.Sync.mergeConfig + -- Allow merging unrelated histories. + mc <- liftAnnex $ Command.Sync.mergeConfig True failed <- forM remotes $ \r -> if wantpull $ Remote.gitconfig r then do g' <- liftAnnex $ do diff --git a/Assistant/Threads/Merger.hs b/Assistant/Threads/Merger.hs index 19b5ceca04..04d1a135b2 100644 --- a/Assistant/Threads/Merger.hs +++ b/Assistant/Threads/Merger.hs @@ -90,7 +90,8 @@ onChange file ] void $ liftAnnex $ do cmode <- annexCommitMode <$> Annex.getGitConfig - mc <- Command.Sync.mergeConfig + -- Allow merging unrelated histories. + mc <- Command.Sync.mergeConfig True Command.Sync.merge currbranch mc diff --git a/CHANGELOG b/CHANGELOG index 1a916aaf4c..a4f8eeb5a5 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -9,6 +9,11 @@ git-annex (8.20210715) UNRELEASED; urgency=medium * sync: When --quiet is used, run git commit, push, and pull without their ususual output. * merge: When --quiet is used, run git merge without its usual output. + * sync, merge, post-receive: Avoid merging unrelated histories, + which used to be allowed only to support direct mode repositories. + (However, sync does still merge unrelated histories when importing + trees from special remotes, and the assistant still merges unrelated + histories.) -- Joey Hess Wed, 14 Jul 2021 14:26:36 -0400 diff --git a/Command/Merge.hs b/Command/Merge.hs index 2a964d0769..aa8b0ddeb8 100644 --- a/Command/Merge.hs +++ b/Command/Merge.hs @@ -41,14 +41,14 @@ mergeAnnexBranch = starting "merge" ai si $ do mergeSyncedBranch :: CommandStart mergeSyncedBranch = do - mc <- mergeConfig + mc <- mergeConfig False mergeLocal mc def =<< getCurrentBranch mergeBranch :: Git.Ref -> CommandStart mergeBranch r = starting "merge" ai si $ do currbranch <- getCurrentBranch let o = def { notOnlyAnnexOption = True } - mc <- mergeConfig + mc <- mergeConfig False next $ merge currbranch mc o Git.Branch.ManualCommit r where ai = ActionItemOther (Just (Git.fromRef r)) diff --git a/Command/PostReceive.hs b/Command/PostReceive.hs index fab6181b02..ec0678383f 100644 --- a/Command/PostReceive.hs +++ b/Command/PostReceive.hs @@ -52,5 +52,5 @@ updateInsteadEmulation :: CommandStart updateInsteadEmulation = do prepMerge let o = def { notOnlyAnnexOption = True } - mc <- mergeConfig + mc <- mergeConfig False mergeLocal mc o =<< getCurrentBranch diff --git a/Command/Sync.hs b/Command/Sync.hs index c0e469c9eb..f6c53c9514 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -218,7 +218,7 @@ seek' o = do commandAction (withbranch cleanupLocal) mapM_ (commandAction . withbranch . cleanupRemote) gitremotes else do - mc <- mergeConfig + mc <- mergeConfig False -- Syncing involves many actions, any of which -- can independently fail, without preventing @@ -234,7 +234,7 @@ seek' o = do content <- shouldSyncContent o forM_ (filter isImport contentremotes) $ - withbranch . importRemote content o mc + withbranch . importRemote content o forM_ (filter isThirdPartyPopulated contentremotes) $ pullThirdPartyPopulated o @@ -275,20 +275,17 @@ seek' o = do prepMerge :: Annex () prepMerge = Annex.changeDirectory . fromRawFilePath =<< fromRepo Git.repoPath -mergeConfig :: Annex [Git.Merge.MergeConfig] -mergeConfig = do +mergeConfig :: Bool -> Annex [Git.Merge.MergeConfig] +mergeConfig mergeunrelated = do quiet <- commandProgressDisabled return $ catMaybes [ Just Git.Merge.MergeNonInteractive - -- In several situations, unrelated histories should be - -- merged together. This includes pairing in the assistant, - -- merging from a remote into a newly created direct mode - -- repo, and an initial merge from an import from a special - -- remote. (Once direct mode is removed, this could be - -- changed, so only the assistant and import from special - -- remotes use it.) - , Just Git.Merge.MergeUnrelatedHistories - , if quiet then Just Git.Merge.MergeQuiet else Nothing + , if mergeunrelated + then Just Git.Merge.MergeUnrelatedHistories + else Nothing + , if quiet + then Just Git.Merge.MergeQuiet + else Nothing ] merge :: CurrBranch -> [Git.Merge.MergeConfig] -> SyncOptions -> Git.Branch.CommitMode -> Git.Branch -> Annex Bool @@ -483,8 +480,8 @@ pullRemote o mergeconfig remote branch = stopUnless (pure $ pullOption o && want ai = ActionItemOther (Just (Remote.name remote)) si = SeekInput [] -importRemote :: Bool -> SyncOptions -> [Git.Merge.MergeConfig] -> Remote -> CurrBranch -> CommandSeek -importRemote importcontent o mergeconfig remote currbranch +importRemote :: Bool -> SyncOptions -> Remote -> CurrBranch -> CommandSeek +importRemote importcontent o remote currbranch | not (pullOption o) || not wantpull = noop | otherwise = case remoteAnnexTrackingBranch (Remote.gitconfig remote) of Nothing -> noop @@ -497,7 +494,13 @@ importRemote importcontent o mergeconfig remote currbranch if canImportKeys remote importcontent then do Command.Import.seekRemote remote branch subdir importcontent (CheckGitIgnore True) - void $ mergeRemote remote currbranch mergeconfig o + -- Importing generates a branch + -- that is not initially connected + -- to the current branch, so allow + -- merging unrelated histories when + -- mergeing it. + mc <- mergeConfig True + void $ mergeRemote remote currbranch mc o else warning $ "Cannot import from " ++ Remote.name remote ++ " when not syncing content." where wantpull = remoteAnnexPull (Remote.gitconfig remote)