diff --git a/merge-recursive.c b/merge-recursive.c index 9fb0b9f8fd..be01f528cb 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -1952,6 +1952,13 @@ int merge_trees(struct merge_options *o, } if (oid_eq(&common->object.oid, &merge->object.oid)) { + struct strbuf sb = STRBUF_INIT; + + if (index_has_changes(&sb)) { + err(o, _("Dirty index: cannot merge (dirty: %s)"), + sb.buf); + return 0; + } output(o, 0, _("Already up to date!")); *result = head; return 1; diff --git a/t/t6044-merge-unrelated-index-changes.sh b/t/t6044-merge-unrelated-index-changes.sh index 5e472be92b..23b86fb977 100755 --- a/t/t6044-merge-unrelated-index-changes.sh +++ b/t/t6044-merge-unrelated-index-changes.sh @@ -112,7 +112,7 @@ test_expect_success 'recursive' ' test_must_fail git merge -s recursive C^0 ' -test_expect_failure 'recursive, when merge branch matches merge base' ' +test_expect_success 'recursive, when merge branch matches merge base' ' git reset --hard && git checkout B^0 &&