aboutsummaryrefslogtreecommitdiff
path: root/Command
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-02-14 15:58:05 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-02-14 16:09:55 -0400
commit2286280b4462d56117f221ff1555f299c74ffc3b (patch)
treed65b9799e6a99b0a3249f5ea74939793c5275b46 /Command
parent81a4bf492f4c34707143aeec614c246f2a2bd394 (diff)
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.
Diffstat (limited to 'Command')
-rw-r--r--Command/Sync.hs40
1 files changed, 28 insertions, 12 deletions
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