@matheusbsbs / matheus-bagliano / commits / 67bfc030d7
Fork 0

commit: drop duplicated parents

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>

Junio C Hamano committed Jun 2, 2008 at 22:17 UTC 67bfc030d7b27c007853776e8028598bdfa2cae0
2 files changed +23
builtin-commit.c
+9
@@ -883,10 +883,19 @@ static void add_parent(struct strbuf *sb, const unsigned char *sha1)
883 {
884 struct object *obj = parse_object(sha1);
885 const char *parent = sha1_to_hex(sha1);
886 + const char *cp;
887 +
888 if (!obj)
889 die("Unable to find commit parent %s", parent);
890 if (obj->type != OBJ_COMMIT)
891 die("Parent %s isn't a proper commit", parent);
892 +
893 + for (cp = sb->buf; cp && (cp = strstr(cp, "\nparent ")); cp += 8) {
894 + if (!memcmp(cp + 8, parent, 40) && cp[48] == '\n') {
895 + error("duplicate parent %s ignored", parent);
896 + return;
897 + }
898 + }
899 strbuf_addf(sb, "parent %s\n", parent);
900 }
901
t/t7502-commit.sh
+14
@@ -226,4 +226,18 @@ test_expect_success 'a SIGTERM should break locks' '
226 ! test -f .git/index.lock
227 '
228
229 +rm -f .git/MERGE_MSG .git/COMMIT_EDITMSG
230 +git reset -q --hard
231 +
232 +test_expect_success 'Hand committing of a redundant merge removes dups' '
233 +
234 + git rev-parse second master >expect &&
235 + test_must_fail git merge second master &&
236 + git checkout master g &&
237 + EDITOR=: git commit -a &&
238 + git cat-file commit HEAD | sed -n -e "s/^parent //p" -e "/^$/q" >actual &&
239 + test_cmp expect actual
240 +
241 +'
242 +
243 test_done