merge: do not create a signed tag merge under --ff-only option

Starting at release v1.7.9, if you ask to merge a signed tag, "git merge" always creates a merge commit, even when the tag points at a commit that happens to be a descendant of your current commit. Unfortunately, this interacts rather badly for people who use --ff-only to make sure that their branch is free of local developments. It used to be possible to say: $ git checkout -b frotz v1.7.9~30 $ git merge --ff-only v1.7.9 and expect that the resulting tip of frotz branch matches v1.7.9^0 (aka the commit tagged as v1.7.9), but this fails with the updated Git with: fatal: Not possible to fast-forward, aborting. because a merge that merges v1.7.9 tag to v1.7.9~30 cannot be created by fast forwarding. We could teach users that now they have to do $ git merge --ff-only v1.7.9^0 but it is far more pleasant for users if we DWIMmed this ourselves. When an integrator pulls in a topic from a lieutenant via a signed tag, even when the work done by the lieutenant happens to fast-forward, the integrator wants to have a merge record, so the integrator will not be asking for --ff-only when running "git pull" in such a case. Therefore, this change should not regress the support for the use case v1.7.9 wanted to add. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Feb 5, 2012 at 16:22 UTC b5c9f1c1b0ed9c91463b9f46a7c9dff3efc53773
2 files changed +15 -1
builtin/merge.c
+2 -1
@@ -1283,7 +1283,8 @@ int cmd_merge(int argc, const char **argv, const char *prefix)
1283 sha1_to_hex(commit->object.sha1));
1284 setenv(buf.buf, argv[i], 1);
1285 strbuf_reset(&buf);
1286 - if (merge_remote_util(commit) &&
1286 + if (!fast_forward_only &&
1287 + merge_remote_util(commit) &&
1288 merge_remote_util(commit)->obj &&
1289 merge_remote_util(commit)->obj->type == OBJ_TAG) {
1290 option_edit = 1;
t/t7600-merge.sh
+13
@@ -27,6 +27,7 @@ Testing basic merge operations/option parsing.
27 '
28
29 . ./test-lib.sh
30 +. "$TEST_DIRECTORY"/lib-gpg.sh
31
32 printf '%s\n' 1 2 3 4 5 6 7 8 9 >file
33 printf '%s\n' '1 X' 2 3 4 5 6 7 8 9 >file.1
@@ -670,4 +671,16 @@ test_expect_success 'merge --no-ff --edit' '
671 test_cmp actual expected
672 '
673
674 +test_expect_success GPG 'merge --ff-only tag' '
675 + git reset --hard c0 &&
676 + git commit --allow-empty -m "A newer commit" &&
677 + git tag -s -m "A newer commit" signed &&
678 + git reset --hard c0 &&
679 +
680 + git merge --ff-only signed &&
681 + git rev-parse signed^0 >expect &&
682 + git rev-parse HEAD >actual &&
683 + test_cmp actual expect
684 +'
685 +
686 test_done