@matheusbsbs / matheus-bagliano / commits / e6d1f76ccf
Fork 0

git-merge.sh: better handling of combined --squash,--no-ff,--no-commit options

git-merge used to use either the --squash,--no-squash, --no-ff,--ff, --no-commit,--commit option, whichever came last in the command line. This lead to some un-intuitive behavior, having git merge --no-commit --no-ff <branch> actually commit the merge. Now git-merge respects --no-commit together with --no-ff, as well as other combinations of the options. However, this broke a selftest in t/t7600-merge.sh which expected to have --no-ff completely override the --squash option, so that git merge --squash --no-ff <branch> fast-forwards, and makes a merge commit; combining --squash with --no-ff doesn't really make sense though, and is now refused by git-merge. The test is adapted to test --no-ff without the preceding --squash, and another test is added to make sure the --squash --no-ff combination is refused. The unexpected behavior was reported by John Goerzen through http://bing.sdebian.org/468568 Signed-off-by: Gerrit Pape <pape@smarden.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Gerrit Pape committed Mar 3, 2008 at 09:22 UTC e6d1f76ccf9de037c5479acdd9b6211e80145142
2 files changed +17 -6
git-merge.sh
+11 -6
@@ -37,6 +37,7 @@ use_strategies=
37
38 allow_fast_forward=t
39 allow_trivial_merge=t
40 +squash= no_commit=
41
42 dropsave() {
43 rm -f -- "$GIT_DIR/MERGE_HEAD" "$GIT_DIR/MERGE_MSG" \
@@ -152,17 +153,21 @@ parse_config () {
153 --summary)
154 show_diffstat=t ;;
155 --squash)
155 - allow_fast_forward=t squash=t no_commit=t ;;
156 + test "$allow_fast_forward" = t ||
157 + die "You cannot combine --squash with --no-ff."
158 + squash=t no_commit=t ;;
159 --no-squash)
157 - allow_fast_forward=t squash= no_commit= ;;
160 + squash= no_commit= ;;
161 --commit)
159 - allow_fast_forward=t squash= no_commit= ;;
162 + no_commit= ;;
163 --no-commit)
161 - allow_fast_forward=t squash= no_commit=t ;;
164 + no_commit=t ;;
165 --ff)
163 - allow_fast_forward=t squash= no_commit= ;;
166 + allow_fast_forward=t ;;
167 --no-ff)
165 - allow_fast_forward=false squash= no_commit= ;;
168 + test "$squash" != t ||
169 + die "You cannot combine --squash with --no-ff."
170 + allow_fast_forward=f ;;
171 -s|--strategy)
172 shift
173 case " $all_strategies " in
t/t7600-merge.sh
+6
@@ -419,6 +419,7 @@ test_debug 'gitk --all'
419
420 test_expect_success 'merge c0 with c1 (no-ff)' '
421 git reset --hard c0 &&
422 + git config branch.master.mergeoptions "" &&
423 test_tick &&
424 git merge --no-ff c1 &&
425 verify_merge file result.1 &&
@@ -427,6 +428,11 @@ test_expect_success 'merge c0 with c1 (no-ff)' '
428
429 test_debug 'gitk --all'
430
431 +test_expect_success 'combining --squash and --no-ff is refused' '
432 + test_must_fail git merge --squash --no-ff c1 &&
433 + test_must_fail git merge --no-ff --squash c1
434 +'
435 +
436 test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
437 git reset --hard c0 &&
438 git config branch.master.mergeoptions "--no-ff" &&