sync: Avoid an ugly error message when nothing has been committed to master yet and there is a synced master branch to merge from

Now the warning gets displayed, which is better than an arcane git error.

The warning is still kind of ugly, especially when the pull later in the
sync will clear up what it warns about. But, this is an unusual situation
not likely to happen, and if there is no remote to pull from, the warning
message is needed or the sync will seem to succeed despite not merging the
synced master branch.

Would still be better if it could merge the synced master branch in this
situation, making an empty commit to master to do it seems wrong, and
otherwise it would need a whole separate code path, and would bypass using
git merge in favor of say, setting master to the syned branch. Which would
bypass git configs like arguably merge.ff and certianly
merge.verifySignatures. So don't want to do that.
This commit is contained in:
Joey Hess 2020-05-05 13:57:20 -04:00
parent e3585dc674
commit 0040d2c129
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 76 additions and 16 deletions

View file

@ -346,36 +346,41 @@ mergeLocal mergeconfig o currbranch = stopUnless (notOnlyAnnex o) $
mergeLocal' mergeconfig o currbranch
mergeLocal' :: [Git.Merge.MergeConfig] -> SyncOptions -> CurrBranch -> CommandStart
mergeLocal' mergeconfig o currbranch@(Just _, _) =
needMerge currbranch >>= \case
mergeLocal' mergeconfig o currbranch@(Just branch, _) =
needMerge currbranch branch >>= \case
Nothing -> stop
Just syncbranch ->
starting "merge" (ActionItemOther (Just $ Git.Ref.describe syncbranch)) $
next $ merge currbranch mergeconfig o Git.Branch.ManualCommit syncbranch
mergeLocal' _ _ (Nothing, madj) = do
b <- inRepo Git.Branch.currentUnsafe
needMerge (b, madj) >>= \case
mergeLocal' _ _ currbranch@(Nothing, _) = inRepo Git.Branch.currentUnsafe >>= \case
Just branch -> needMerge currbranch branch >>= \case
Nothing -> stop
Just syncbranch ->
starting "merge" (ActionItemOther (Just $ Git.Ref.describe syncbranch)) $ do
warning $ "There are no commits yet in the currently checked out branch, so cannot merge any remote changes into it."
warning $ "There are no commits yet to branch " ++ Git.fromRef branch ++ ", so cannot merge " ++ Git.fromRef syncbranch ++ " into it."
next $ return False
Nothing -> 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 id checks)
needMerge :: CurrBranch -> Git.Branch -> Annex (Maybe Git.Branch)
needMerge currbranch headbranch = ifM (allM id 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
syncbranch = syncBranch headbranch
checks = case currbranch of
(Just _, madj) ->
let branch' = maybe headbranch (adjBranch . originalToAdjusted headbranch) madj
in
[ not <$> isBareRepo
, inRepo (Git.Ref.exists syncbranch)
, inRepo (Git.Branch.changed branch' syncbranch)
]
(Nothing, _) ->
[ not <$> isBareRepo
, inRepo (Git.Ref.exists syncbranch)
]
pushLocal :: SyncOptions -> CurrBranch -> CommandStart
pushLocal o b = stopUnless (notOnlyAnnex o) $ do