diff options
-rw-r--r-- | builtin-commit.c | 9 | ||||
-rwxr-xr-x | t/t7502-commit.sh | 14 |
2 files changed, 23 insertions, 0 deletions
diff --git a/builtin-commit.c b/builtin-commit.c index b294c1f88c..90200ed643 100644 --- a/builtin-commit.c +++ b/builtin-commit.c @@ -883,10 +883,19 @@ static void add_parent(struct strbuf *sb, const unsigned char *sha1) { struct object *obj = parse_object(sha1); const char *parent = sha1_to_hex(sha1); + const char *cp; + if (!obj) die("Unable to find commit parent %s", parent); if (obj->type != OBJ_COMMIT) die("Parent %s isn't a proper commit", parent); + + for (cp = sb->buf; cp && (cp = strstr(cp, "\nparent ")); cp += 8) { + if (!memcmp(cp + 8, parent, 40) && cp[48] == '\n') { + error("duplicate parent %s ignored", parent); + return; + } + } strbuf_addf(sb, "parent %s\n", parent); } diff --git a/t/t7502-commit.sh b/t/t7502-commit.sh index 46ec1ce8aa..22a13f7aab 100755 --- a/t/t7502-commit.sh +++ b/t/t7502-commit.sh @@ -226,4 +226,18 @@ test_expect_success 'a SIGTERM should break locks' ' ! test -f .git/index.lock ' +rm -f .git/MERGE_MSG .git/COMMIT_EDITMSG +git reset -q --hard + +test_expect_success 'Hand committing of a redundant merge removes dups' ' + + git rev-parse second master >expect && + test_must_fail git merge second master && + git checkout master g && + EDITOR=: git commit -a && + git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q" >actual && + test_cmp expect actual + +' + test_done |