From 2286280b4462d56117f221ff1555f299c74ffc3b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 14 Feb 2017 15:58:05 -0400 Subject: sync, merge: Fail when the current branch has no commits yet, instead of not merging in anything from remotes and appearing to succeed. At first I wanted to make it go ahead and merge into the newborn branch, so made it use Git.Branch.currentUnsafe to get the current branch. But that failed: fatal: ambiguous argument 'refs/heads/master..refs/heads/synced/master': unknown revision or path not in the working tree. A whole nother code path to handle merging into newborn branches seemed excessive, so went with displaying a warning and propigating failure status. This commit was sponsored by Brock Spratlen on Patreon. --- CHANGELOG | 7 +++++++ Command/Sync.hs | 40 ++++++++++++++++++++++++++++------------ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b8a72536d..94d3e2595 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,10 @@ +git-annex (6.20170215) UNRELEASED; urgency=medium + + * sync, merge: Fail when the current branch has no commits yet, instead + of not merging in anything from remotes and appearing to succeed. + + -- Joey Hess Tue, 14 Feb 2017 15:54:25 -0400 + git-annex (6.20170214) unstable; urgency=medium * Increase default cost for p2p remotes from 200 to 1000. diff --git a/Command/Sync.hs b/Command/Sync.hs index 37fc343e7..e885990a4 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -272,22 +272,38 @@ commitStaged commitmode commitmessage = do return True mergeLocal :: [Git.Merge.MergeConfig] -> CurrBranch -> CommandStart -mergeLocal mergeconfig currbranch@(Just branch, madj) = go =<< needmerge +mergeLocal mergeconfig currbranch@(Just branch, madj) = + go =<< needMerge currbranch where - syncbranch = syncBranch branch - needmerge = ifM isBareRepo - ( return False - , ifM (inRepo $ Git.Ref.exists syncbranch) - ( inRepo $ Git.Branch.changed branch' syncbranch - , return False - ) - ) - go False = stop - go True = do + go Nothing = stop + go (Just syncbranch) = do showStart "merge" $ Git.Ref.describe syncbranch next $ next $ merge currbranch mergeconfig Git.Branch.ManualCommit syncbranch + syncbranch = syncBranch branch +mergeLocal _ (Nothing, madj) = do + b <- inRepo Git.Branch.currentUnsafe + ifM (needMerge (b, madj)) + ( do + warning $ "There are no commits yet in the currently checked out branch, so cannot merge any remote changes into it." + next $ next $ return False + , stop + ) + +-- Returns the branch that should be merged, if any. +needMerge :: CurrBranch -> Annex (Maybe Git.Branch) +needMerge (Nothing, _) = return Nothing +needMerge (Just branch, madj) = ifM (allM checks) + ( return (Just syncbranch) + , return Nothing + ) + where + checks = + [ not <$> isBareRepo + , inRepo (Git.Ref.exists syncbranch) + , inRepo (Git.Branch.changed branch' syncbranch) + ] + syncbranch = syncBranch branch branch' = maybe branch (adjBranch . originalToAdjusted branch) madj -mergeLocal _ (Nothing, _) = stop pushLocal :: CurrBranch -> CommandStart pushLocal b = do -- cgit v1.2.3