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

git-merge: add --ff and --no-ff options

These new options can be used to control the policy for fast-forward merges: --ff allows it (this is the default) while --no-ff will create a merge commit. Signed-off-by: Lars Hjemli <hjemli@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Lars Hjemli committed Sep 24, 2007 at 00:51 UTC d66424c4ac661c69640765260235452499d80378
3 files changed +45 -6
Documentation/merge-options.txt
+9
@@ -27,6 +27,15 @@
27 Perform the merge and commit the result. This option can
28 be used to override --squash.
29
30 +--no-ff::
31 + Generate a merge commit even if the merge resolved as a
32 + fast-forward.
33 +
34 +--ff::
35 + Do not generate a merge commit if the merge resolved as
36 + a fast-forward, only update the branch pointer. This is
37 + the default behavior of git-merge.
38 +
39 -s <strategy>, \--strategy=<strategy>::
40 Use the given merge strategy; can be supplied more than
41 once to specify them in the order they should be tried.
git-merge.sh
+16 -6
@@ -3,7 +3,7 @@
3 # Copyright (c) 2005 Junio C Hamano
4 #
5
6 -USAGE='[-n] [--summary] [--[no-]commit] [--[no-]squash] [-s <strategy>] [-m=<merge-message>] <commit>+'
6 +USAGE='[-n] [--summary] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-s <strategy>] [-m=<merge-message>] <commit>+'
7
8 SUBDIRECTORY_OK=Yes
9 . git-sh-setup
@@ -127,13 +127,17 @@ parse_option () {
127 --summary)
128 show_diffstat=t ;;
129 --sq|--squ|--squa|--squas|--squash)
130 - squash=t no_commit=t ;;
130 + allow_fast_forward=t squash=t no_commit=t ;;
131 --no-sq|--no-squ|--no-squa|--no-squas|--no-squash)
132 - squash= no_commit= ;;
132 + allow_fast_forward=t squash= no_commit= ;;
133 --c|--co|--com|--comm|--commi|--commit)
134 - squash= no_commit= ;;
134 + allow_fast_forward=t squash= no_commit= ;;
135 --no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
136 - squash= no_commit=t ;;
136 + allow_fast_forward=t squash= no_commit=t ;;
137 + --ff)
138 + allow_fast_forward=t squash= no_commit= ;;
139 + --no-ff)
140 + allow_fast_forward=false squash= no_commit= ;;
141 -s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
142 --strateg=*|--strategy=*|\
143 -s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
@@ -477,7 +481,13 @@ done
481 # auto resolved the merge cleanly.
482 if test '' != "$result_tree"
483 then
480 - parents=$(git show-branch --independent "$head" "$@" | sed -e 's/^/-p /')
484 + if test "$allow_fast_forward" = "t"
485 + then
486 + parents=$(git show-branch --independent "$head" "$@")
487 + else
488 + parents=$(git rev-parse "$head" "$@")
489 + fi
490 + parents=$(echo "$parents" | sed -e 's/^/-p /')
491 result_commit=$(printf '%s\n' "$merge_msg" | git commit-tree $result_tree $parents) || exit
492 finish "$result_commit" "Merge made by $wt_strategy."
493 dropsave
t/t7600-merge.sh
+20
@@ -417,4 +417,24 @@ test_expect_success 'merge c1 with c2 (override --squash)' '
417
418 test_debug 'gitk --all'
419
420 +test_expect_success 'merge c0 with c1 (no-ff)' '
421 + git reset --hard c0 &&
422 + test_tick &&
423 + git merge --no-ff c1 &&
424 + verify_merge file result.1 &&
425 + verify_parents $c0 $c1
426 +'
427 +
428 +test_debug 'gitk --all'
429 +
430 +test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
431 + git reset --hard c0 &&
432 + git config branch.master.mergeoptions "--no-ff" &&
433 + git merge --ff c1 &&
434 + verify_merge file result.1 &&
435 + verify_head $c1
436 +'
437 +
438 +test_debug 'gitk --all'
439 +
440 test_done