Skip to content

merge() of an already merged branch creates an empty merge commit #6

Closed

Description

@dnnsjsk

Merging a branch that is already contained in HEAD creates a new merge commit every time. git answers "Already up to date." and leaves HEAD alone.

Repro

# main contains feature after a first merge
pitmaster merge feature   # "Merge successful.", creates "Merge branch 'feature'"
pitmaster merge feature   # "Merge successful." again, creates a second merge commit with the same tree
git log --oneline -3
# 643f58d Merge branch 'feature'
# d5382c8 Merge branch 'feature'

Cause

merge() checks isAncestor($oursId, $theirsId) for the fast-forward case (

if ($mergeBaseFinder->isAncestor($oursId, $theirsId)) {
) but has no check for the reverse case ($theirsId already an ancestor of HEAD), so it falls through to the three-way path and createCommitFromTree() (L2321-L2322).

Expected

When the merged commit is an ancestor of (or equal to) HEAD, return a clean result without creating a commit or touching the working tree.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions