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.
This commit is contained in:
Joey Hess 2017-02-14 15:58:05 -04:00
parent 9d690a18bd
commit 69baa45f14
No known key found for this signature in database
GPG key ID: C910D9222512E3C7
2 changed files with 35 additions and 12 deletions

View file

@ -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 <id@joeyh.name> Tue, 14 Feb 2017 15:54:25 -0400
git-annex (6.20170214) unstable; urgency=medium git-annex (6.20170214) unstable; urgency=medium
* Increase default cost for p2p remotes from 200 to 1000. * Increase default cost for p2p remotes from 200 to 1000.

View file

@ -272,22 +272,38 @@ commitStaged commitmode commitmessage = do
return True return True
mergeLocal :: [Git.Merge.MergeConfig] -> CurrBranch -> CommandStart mergeLocal :: [Git.Merge.MergeConfig] -> CurrBranch -> CommandStart
mergeLocal mergeconfig currbranch@(Just branch, madj) = go =<< needmerge mergeLocal mergeconfig currbranch@(Just branch, madj) =
go =<< needMerge currbranch
where where
syncbranch = syncBranch branch go Nothing = stop
needmerge = ifM isBareRepo go (Just syncbranch) = do
( return False
, ifM (inRepo $ Git.Ref.exists syncbranch)
( inRepo $ Git.Branch.changed branch' syncbranch
, return False
)
)
go False = stop
go True = do
showStart "merge" $ Git.Ref.describe syncbranch showStart "merge" $ Git.Ref.describe syncbranch
next $ next $ merge currbranch mergeconfig Git.Branch.ManualCommit 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 branch' = maybe branch (adjBranch . originalToAdjusted branch) madj
mergeLocal _ (Nothing, _) = stop
pushLocal :: CurrBranch -> CommandStart pushLocal :: CurrBranch -> CommandStart
pushLocal b = do pushLocal b = do