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:
parent
9d690a18bd
commit
69baa45f14
2 changed files with 35 additions and 12 deletions
|
@ -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
|
||||
|
||||
* Increase default cost for p2p remotes from 200 to 1000.
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue