Skip to content

Commit

Permalink
commit: drop duplicated parents
Browse files Browse the repository at this point in the history
The scripted version of git-commit internally used git-commit-tree which
omitted duplicated parents given from the command line.  This prevented a
nonsensical octopus merge from getting created even when you said "git
merge A B" while you are already on branch A.

However, when git-commit was rewritten in C, this sanity check was lost.
This resurrects it.

Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Junio C Hamano committed Jun 3, 2008
1 parent 69e66f5 commit 67bfc03
Showing 2 changed files with 23 additions and 0 deletions.
9 changes: 9 additions & 0 deletions builtin-commit.c
Original file line number Diff line number Diff line change
@@ -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);
}

14 changes: 14 additions & 0 deletions t/t7502-commit.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 67bfc03

Please sign in to comment.