* [PATCH 0/6] per branch options for git-merge
@ 2007-09-23 22:51 Lars Hjemli
2007-09-23 22:51 ` [PATCH 1/6] Add test-script for git-merge porcelain Lars Hjemli
0 siblings, 1 reply; 7+ messages in thread
From: Lars Hjemli @ 2007-09-23 22:51 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
This patch-series implements support for per branch configuration of
git-merge, using entries (branch.<name>.mergeoptions) in .git/config.
Since this makes it possible to specify --no-commit and --squash as
default options for git-merge, the new options --commit and --no-squash
are added to enable users to override such defaults.
There is also a new option, --no-ff, which can be used to force git-merge
to create a merge commit even when the merge was a fast-forward (and a
matching --ff option to allow overrides).
Shortlog:
Add test-script for git-merge porcelain
git-merge: fix faulty SQUASH_MSG
git-merge: refactor option parsing
git-merge: add support for branch.<name>.mergeoptions
git-merge: add support for --commit and --no-squash
git-merge: add --ff and --no-ff options
Diffstat:
Documentation/config.txt | 6 +
Documentation/git-merge.txt | 4 +
Documentation/merge-options.txt | 17 ++
git-merge.sh | 65 +++++-
t/t7600-merge.sh | 440 +++++++++++++++++++++++++++++++++++++++
5 files changed, 521 insertions(+), 11 deletions(-)
^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 1/6] Add test-script for git-merge porcelain
2007-09-23 22:51 [PATCH 0/6] per branch options for git-merge Lars Hjemli
@ 2007-09-23 22:51 ` Lars Hjemli
2007-09-23 22:51 ` [PATCH 2/6] git-merge: fix faulty SQUASH_MSG Lars Hjemli
0 siblings, 1 reply; 7+ messages in thread
From: Lars Hjemli @ 2007-09-23 22:51 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
This test-script excercises the porcelainish aspects of git-merge, and
does it thoroughly enough to detect a small bug already noticed by Junio:
squashing an octopus generates a faulty .git/SQUASH_MSG.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
t/t7600-merge.sh | 344 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 344 insertions(+), 0 deletions(-)
create mode 100755 t/t7600-merge.sh
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
new file mode 100755
index 0000000..dec6ea2
--- /dev/null
+++ b/t/t7600-merge.sh
@@ -0,0 +1,344 @@
+#!/bin/sh
+#
+# Copyright (c) 2007 Lars Hjemli
+#
+
+test_description='git-merge
+
+Testing basic merge operations/option parsing.'
+
+. ./test-lib.sh
+
+cat >file <<EOF
+1
+2
+3
+4
+5
+6
+7
+8
+9
+EOF
+
+cat >file.1 <<EOF
+1 X
+2
+3
+4
+5
+6
+7
+8
+9
+EOF
+
+cat >file.5 <<EOF
+1
+2
+3
+4
+5 X
+6
+7
+8
+9
+EOF
+
+cat >file.9 <<EOF
+1
+2
+3
+4
+5
+6
+7
+8
+9 X
+EOF
+
+cat >result.1 <<EOF
+1 X
+2
+3
+4
+5
+6
+7
+8
+9
+EOF
+
+cat >result.1-5 <<EOF
+1 X
+2
+3
+4
+5 X
+6
+7
+8
+9
+EOF
+
+cat >result.1-5-9 <<EOF
+1 X
+2
+3
+4
+5 X
+6
+7
+8
+9 X
+EOF
+
+create_merge_msgs() {
+ echo "Merge commit 'c2'" >msg.1-5 &&
+ echo "Merge commit 'c2'; commit 'c3'" >msg.1-5-9 &&
+ echo "Squashed commit of the following:" >squash.1 &&
+ echo >>squash.1 &&
+ git log --no-merges ^HEAD c1 >>squash.1 &&
+ echo "Squashed commit of the following:" >squash.1-5 &&
+ echo >>squash.1-5 &&
+ git log --no-merges ^HEAD c2 >>squash.1-5 &&
+ echo "Squashed commit of the following:" >squash.1-5-9 &&
+ echo >>squash.1-5-9 &&
+ git log --no-merges ^HEAD c2 c3 >>squash.1-5-9
+}
+
+verify_diff() {
+ if ! diff -u "$1" "$2"
+ then
+ echo "$3"
+ false
+ fi
+}
+
+verify_merge() {
+ verify_diff "$2" "$1" "[OOPS] bad merge result" &&
+ if test $(git ls-files -u | wc -l) -gt 0
+ then
+ echo "[OOPS] unmerged files"
+ false
+ fi &&
+ if ! git diff --exit-code
+ then
+ echo "[OOPS] working tree != index"
+ false
+ fi &&
+ if test -n "$3"
+ then
+ git show -s --pretty=format:%s HEAD >msg.act &&
+ verify_diff "$3" msg.act "[OOPS] bad merge message"
+ fi
+}
+
+verify_head() {
+ if test "$1" != "$(git rev-parse HEAD)"
+ then
+ echo "[OOPS] HEAD != $1"
+ false
+ fi
+}
+
+verify_parents() {
+ i=1
+ while test $# -gt 0
+ do
+ if test "$1" != "$(git rev-parse HEAD^$i)"
+ then
+ echo "[OOPS] HEAD^$i != $1"
+ return 1
+ fi
+ i=$(expr $i + 1)
+ shift
+ done
+}
+
+verify_mergeheads() {
+ i=1
+ if ! test -f .git/MERGE_HEAD
+ then
+ echo "[OOPS] MERGE_HEAD is missing"
+ false
+ fi &&
+ while test $# -gt 0
+ do
+ head=$(head -n $i .git/MERGE_HEAD | tail -n 1)
+ if test "$1" != "$head"
+ then
+ echo "[OOPS] MERGE_HEAD $i != $1"
+ return 1
+ fi
+ i=$(expr $i + 1)
+ shift
+ done
+}
+
+verify_no_mergehead() {
+ if test -f .git/MERGE_HEAD
+ then
+ echo "[OOPS] MERGE_HEAD exists"
+ false
+ fi
+}
+
+
+test_expect_success 'setup' '
+ git add file &&
+ test_tick &&
+ git commit -m "commit 0" &&
+ git tag c0 &&
+ c0=$(git rev-parse HEAD) &&
+ cp file.1 file &&
+ git add file &&
+ test_tick &&
+ git commit -m "commit 1" &&
+ git tag c1 &&
+ c1=$(git rev-parse HEAD) &&
+ git reset --hard "$c0" &&
+ cp file.5 file &&
+ git add file &&
+ test_tick &&
+ git commit -m "commit 2" &&
+ git tag c2 &&
+ c2=$(git rev-parse HEAD) &&
+ git reset --hard "$c0" &&
+ cp file.9 file &&
+ git add file &&
+ test_tick &&
+ git commit -m "commit 3" &&
+ git tag c3 &&
+ c3=$(git rev-parse HEAD)
+ git reset --hard "$c0" &&
+ create_merge_msgs
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'test option parsing' '
+ if git merge -$ c1
+ then
+ echo "[OOPS] -$ accepted"
+ false
+ fi &&
+ if git merge --no-such c1
+ then
+ echo "[OOPS] --no-such accepted"
+ false
+ fi &&
+ if git merge -s foobar c1
+ then
+ echo "[OOPS] -s foobar accepted"
+ false
+ fi &&
+ if git merge -s=foobar c1
+ then
+ echo "[OOPS] -s=foobar accepted"
+ false
+ fi &&
+ if git merge -m
+ then
+ echo "[OOPS] missing commit msg accepted"
+ false
+ fi &&
+ if git merge
+ then
+ echo "[OOPS] missing commit references accepted"
+ false
+ fi
+'
+
+test_expect_success 'merge c0 with c1' '
+ git reset --hard c0 &&
+ git merge c1 &&
+ verify_merge file result.1 &&
+ verify_head "$c1"
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'merge c1 with c2' '
+ git reset --hard c1 &&
+ test_tick &&
+ git merge c2 &&
+ verify_merge file result.1-5 msg.1-5 &&
+ verify_parents $c1 $c2
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'merge c1 with c2 and c3' '
+ git reset --hard c1 &&
+ test_tick &&
+ git merge c2 c3 &&
+ verify_merge file result.1-5-9 msg.1-5-9 &&
+ verify_parents $c1 $c2 $c3
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'merge c0 with c1 (no-commit)' '
+ git reset --hard c0 &&
+ git merge --no-commit c1 &&
+ verify_merge file result.1 &&
+ verify_head $c1
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'merge c1 with c2 (no-commit)' '
+ git reset --hard c1 &&
+ git merge --no-commit c2 &&
+ verify_merge file result.1-5 &&
+ verify_head $c1 &&
+ verify_mergeheads $c2
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'merge c1 with c2 and c3 (no-commit)' '
+ git reset --hard c1 &&
+ git merge --no-commit c2 c3 &&
+ verify_merge file result.1-5-9 &&
+ verify_head $c1 &&
+ verify_mergeheads $c2 $c3
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'merge c0 with c1 (squash)' '
+ git reset --hard c0 &&
+ git merge --squash c1 &&
+ verify_merge file result.1 &&
+ verify_head $c0 &&
+ verify_no_mergehead &&
+ verify_diff squash.1 .git/SQUASH_MSG "[OOPS] bad squash message"
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'merge c1 with c2 (squash)' '
+ git reset --hard c1 &&
+ git merge --squash c2 &&
+ verify_merge file result.1-5 &&
+ verify_head $c1 &&
+ verify_no_mergehead &&
+ verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'merge c1 with c2 and c3 (squash)' '
+ git reset --hard c1 &&
+ git merge --squash c2 c3 &&
+ verify_merge file result.1-5-9 &&
+ verify_head $c1 &&
+ verify_no_mergehead &&
+ verify_diff squash.1-5-9 .git/SQUASH_MSG "[OOPS] bad squash message"
+'
+
+test_debug 'gitk --all'
+
+test_done
--
1.5.3.2.82.g75c8d
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 2/6] git-merge: fix faulty SQUASH_MSG
2007-09-23 22:51 ` [PATCH 1/6] Add test-script for git-merge porcelain Lars Hjemli
@ 2007-09-23 22:51 ` Lars Hjemli
2007-09-23 22:51 ` [PATCH 3/6] git-merge: refactor option parsing Lars Hjemli
0 siblings, 1 reply; 7+ messages in thread
From: Lars Hjemli @ 2007-09-23 22:51 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Only the first 'remote' head is currently specified as an argument to 'git
log' when generating a SQUSH_MSG, which makes the generated message fail
to mention every commit involved in the merge. This fixes the problem.
Noticed-by: Junio C Hamano <gitster@pobox.com>
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
git-merge.sh | 2 +-
1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/git-merge.sh b/git-merge.sh
index 3a01db0..3857634 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -59,7 +59,7 @@ finish_up_to_date () {
squash_message () {
echo Squashed commit of the following:
echo
- git log --no-merges ^"$head" $remote
+ git log --no-merges ^"$head" $remoteheads
}
finish () {
--
1.5.3.2.82.g75c8d
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/6] git-merge: refactor option parsing
2007-09-23 22:51 ` [PATCH 2/6] git-merge: fix faulty SQUASH_MSG Lars Hjemli
@ 2007-09-23 22:51 ` Lars Hjemli
2007-09-23 22:51 ` [PATCH 4/6] git-merge: add support for branch.<name>.mergeoptions Lars Hjemli
0 siblings, 1 reply; 7+ messages in thread
From: Lars Hjemli @ 2007-09-23 22:51 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
Move the option parsing into a separate function as preparation for reuse
by the next commit.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
git-merge.sh | 20 ++++++++++++++------
1 files changed, 14 insertions(+), 6 deletions(-)
diff --git a/git-merge.sh b/git-merge.sh
index 3857634..68b3503 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -119,11 +119,7 @@ merge_name () {
fi
}
-case "$#" in 0) usage ;; esac
-
-have_message=
-while case "$#" in 0) break ;; esac
-do
+parse_option () {
case "$1" in
-n|--n|--no|--no-|--no-s|--no-su|--no-sum|--no-summ|\
--no-summa|--no-summar|--no-summary)
@@ -166,9 +162,21 @@ do
have_message=t
;;
-*) usage ;;
- *) break ;;
+ *) return 1 ;;
esac
shift
+ args_left="$#"
+}
+
+case "$#" in 0) usage ;; esac
+
+have_message=
+while parse_option "$@"
+do
+ while test $args_left -lt $#
+ do
+ shift
+ done
done
if test -z "$show_diffstat"; then
--
1.5.3.2.82.g75c8d
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/6] git-merge: add support for branch.<name>.mergeoptions
2007-09-23 22:51 ` [PATCH 3/6] git-merge: refactor option parsing Lars Hjemli
@ 2007-09-23 22:51 ` Lars Hjemli
2007-09-23 22:51 ` [PATCH 5/6] git-merge: add support for --commit and --no-squash Lars Hjemli
0 siblings, 1 reply; 7+ messages in thread
From: Lars Hjemli @ 2007-09-23 22:51 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
This enables per branch configuration of merge options. Currently, the most
useful options to specify per branch are --squash, --summary/--no-summary
and possibly --strategy, but all options are supported.
Note: Options containing whitespace will _not_ be handled correctly. Luckily,
the only option which can include whitespace is --message and it doesn't
make much sense to give that option a default value.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
Documentation/config.txt | 6 ++++
Documentation/git-merge.txt | 4 +++
git-merge.sh | 21 ++++++++++++++++
t/t7600-merge.sh | 54 +++++++++++++++++++++++++++++++++++++++++++
4 files changed, 85 insertions(+), 0 deletions(-)
diff --git a/Documentation/config.txt b/Documentation/config.txt
index 015910f..d3c25f3 100644
--- a/Documentation/config.txt
+++ b/Documentation/config.txt
@@ -337,6 +337,12 @@ branch.<name>.merge::
branch.<name>.merge to the desired branch, and use the special setting
`.` (a period) for branch.<name>.remote.
+branch.<name>.mergeoptions::
+ Sets default options for merging into branch <name>. The syntax and
+ supported options are equal to that of gitlink:git-merge[1], but
+ option values containing whitespace characters are currently not
+ supported.
+
clean.requireForce::
A boolean to make git-clean do nothing unless given -f or -n. Defaults
to false.
diff --git a/Documentation/git-merge.txt b/Documentation/git-merge.txt
index 144bc16..b1771a1 100644
--- a/Documentation/git-merge.txt
+++ b/Documentation/git-merge.txt
@@ -58,6 +58,10 @@ merge.verbosity::
above outputs debugging information. The default is level 2.
Can be overriden by 'GIT_MERGE_VERBOSITY' environment variable.
+branch.<name>.mergeoptions::
+ Sets default options for merging into branch <name>. The syntax and
+ supported options are equal to that of git-merge, but option values
+ containing whitespace characters are currently not supported.
HOW MERGE WORKS
---------------
diff --git a/git-merge.sh b/git-merge.sh
index 68b3503..e95d4a7 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -168,9 +168,30 @@ parse_option () {
args_left="$#"
}
+parse_config () {
+ while test $# -gt 0
+ do
+ parse_option "$@" || usage
+ while test $args_left -lt $#
+ do
+ shift
+ done
+ done
+}
+
case "$#" in 0) usage ;; esac
have_message=
+
+if branch=$(git-symbolic-ref -q HEAD)
+then
+ mergeopts=$(git config "branch.${branch#refs/heads/}.mergeoptions")
+ if test -n "$mergeopts"
+ then
+ parse_config $mergeopts
+ fi
+fi
+
while parse_option "$@"
do
while test $args_left -lt $#
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index dec6ea2..110974c 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -341,4 +341,58 @@ test_expect_success 'merge c1 with c2 and c3 (squash)' '
test_debug 'gitk --all'
+test_expect_success 'merge c1 with c2 (no-commit in config)' '
+ git reset --hard c1 &&
+ git config branch.master.mergeoptions "--no-commit" &&
+ git merge c2 &&
+ verify_merge file result.1-5 &&
+ verify_head $c1 &&
+ verify_mergeheads $c2
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'merge c1 with c2 (squash in config)' '
+ git reset --hard c1 &&
+ git config branch.master.mergeoptions "--squash" &&
+ git merge c2 &&
+ verify_merge file result.1-5 &&
+ verify_head $c1 &&
+ verify_no_mergehead &&
+ verify_diff squash.1-5 .git/SQUASH_MSG "[OOPS] bad squash message"
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'override config option -n' '
+ git reset --hard c1 &&
+ git config branch.master.mergeoptions "-n" &&
+ test_tick &&
+ git merge --summary c2 >diffstat.txt &&
+ verify_merge file result.1-5 msg.1-5 &&
+ verify_parents $c1 $c2 &&
+ if ! grep -e "^ file | \+2 +-$" diffstat.txt
+ then
+ echo "[OOPS] diffstat was not generated"
+ fi
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'override config option --summary' '
+ git reset --hard c1 &&
+ git config branch.master.mergeoptions "--summary" &&
+ test_tick &&
+ git merge -n c2 >diffstat.txt &&
+ verify_merge file result.1-5 msg.1-5 &&
+ verify_parents $c1 $c2 &&
+ if grep -e "^ file | \+2 +-$" diffstat.txt
+ then
+ echo "[OOPS] diffstat was generated"
+ false
+ fi
+'
+
+test_debug 'gitk --all'
+
test_done
--
1.5.3.2.82.g75c8d
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 5/6] git-merge: add support for --commit and --no-squash
2007-09-23 22:51 ` [PATCH 4/6] git-merge: add support for branch.<name>.mergeoptions Lars Hjemli
@ 2007-09-23 22:51 ` Lars Hjemli
2007-09-23 22:51 ` [PATCH 6/6] git-merge: add --ff and --no-ff options Lars Hjemli
0 siblings, 1 reply; 7+ messages in thread
From: Lars Hjemli @ 2007-09-23 22:51 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
These options can be used to override --no-commit and --squash, which is
needed since --no-commit and --squash now can be specified as default merge
options in $GIT_DIR/config.
The change also introduces slightly different behavior for --no-commit:
when specified, it explicitly overrides --squash. Earlier,
'git merge --squash --no-commit' would result in a squashed merge (i.e. no
$GIT_DIR/MERGE_HEAD was created) but with this patch the command will
behave as if --squash hadn't been specified.
Signed-off-by: Lars Hjemli <hjemli@gmail.com>
---
Documentation/merge-options.txt | 8 ++++++++
git-merge.sh | 8 ++++++--
t/t7600-merge.sh | 22 ++++++++++++++++++++++
3 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt
index d64c259..0464a34 100644
--- a/Documentation/merge-options.txt
+++ b/Documentation/merge-options.txt
@@ -10,6 +10,10 @@
not autocommit, to give the user a chance to inspect and
further tweak the merge result before committing.
+--commit::
+ Perform the merge and commit the result. This option can
+ be used to override --no-commit.
+
--squash::
Produce the working tree and index state as if a real
merge happened, but do not actually make a commit or
@@ -19,6 +23,10 @@
top of the current branch whose effect is the same as
merging another branch (or more in case of an octopus).
+--no-squash::
+ Perform the merge and commit the result. This option can
+ be used to override --squash.
+
-s <strategy>, \--strategy=<strategy>::
Use the given merge strategy; can be supplied more than
once to specify them in the order they should be tried.
diff --git a/git-merge.sh b/git-merge.sh
index e95d4a7..ee8342d 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -3,7 +3,7 @@
# Copyright (c) 2005 Junio C Hamano
#
-USAGE='[-n] [--summary] [--no-commit] [--squash] [-s <strategy>] [-m=<merge-message>] <commit>+'
+USAGE='[-n] [--summary] [--[no-]commit] [--[no-]squash] [-s <strategy>] [-m=<merge-message>] <commit>+'
SUBDIRECTORY_OK=Yes
. git-sh-setup
@@ -128,8 +128,12 @@ parse_option () {
show_diffstat=t ;;
--sq|--squ|--squa|--squas|--squash)
squash=t no_commit=t ;;
+ --no-sq|--no-squ|--no-squa|--no-squas|--no-squash)
+ squash= no_commit= ;;
+ --c|--co|--com|--comm|--commi|--commit)
+ squash= no_commit= ;;
--no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
- no_commit=t ;;
+ squash= no_commit=t ;;
-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
--strateg=*|--strategy=*|\
-s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index 110974c..b0ef488 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -395,4 +395,26 @@ test_expect_success 'override config option --summary' '
test_debug 'gitk --all'
+test_expect_success 'merge c1 with c2 (override --no-commit)' '
+ git reset --hard c1 &&
+ git config branch.master.mergeoptions "--no-commit" &&
+ test_tick &&
+ git merge --commit c2 &&
+ verify_merge file result.1-5 msg.1-5 &&
+ verify_parents $c1 $c2
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'merge c1 with c2 (override --squash)' '
+ git reset --hard c1 &&
+ git config branch.master.mergeoptions "--squash" &&
+ test_tick &&
+ git merge --no-squash c2 &&
+ verify_merge file result.1-5 msg.1-5 &&
+ verify_parents $c1 $c2
+'
+
+test_debug 'gitk --all'
+
test_done
--
1.5.3.2.82.g75c8d
^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 6/6] git-merge: add --ff and --no-ff options
2007-09-23 22:51 ` [PATCH 5/6] git-merge: add support for --commit and --no-squash Lars Hjemli
@ 2007-09-23 22:51 ` Lars Hjemli
0 siblings, 0 replies; 7+ messages in thread
From: Lars Hjemli @ 2007-09-23 22:51 UTC (permalink / raw)
To: Junio C Hamano; +Cc: git
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>
---
Documentation/merge-options.txt | 9 +++++++++
git-merge.sh | 22 ++++++++++++++++------
t/t7600-merge.sh | 20 ++++++++++++++++++++
3 files changed, 45 insertions(+), 6 deletions(-)
diff --git a/Documentation/merge-options.txt b/Documentation/merge-options.txt
index 0464a34..9f1fc82 100644
--- a/Documentation/merge-options.txt
+++ b/Documentation/merge-options.txt
@@ -27,6 +27,15 @@
Perform the merge and commit the result. This option can
be used to override --squash.
+--no-ff::
+ Generate a merge commit even if the merge resolved as a
+ fast-forward.
+
+--ff::
+ Do not generate a merge commit if the merge resolved as
+ a fast-forward, only update the branch pointer. This is
+ the default behavior of git-merge.
+
-s <strategy>, \--strategy=<strategy>::
Use the given merge strategy; can be supplied more than
once to specify them in the order they should be tried.
diff --git a/git-merge.sh b/git-merge.sh
index ee8342d..212e0ee 100755
--- a/git-merge.sh
+++ b/git-merge.sh
@@ -3,7 +3,7 @@
# Copyright (c) 2005 Junio C Hamano
#
-USAGE='[-n] [--summary] [--[no-]commit] [--[no-]squash] [-s <strategy>] [-m=<merge-message>] <commit>+'
+USAGE='[-n] [--summary] [--[no-]commit] [--[no-]squash] [--[no-]ff] [-s <strategy>] [-m=<merge-message>] <commit>+'
SUBDIRECTORY_OK=Yes
. git-sh-setup
@@ -127,13 +127,17 @@ parse_option () {
--summary)
show_diffstat=t ;;
--sq|--squ|--squa|--squas|--squash)
- squash=t no_commit=t ;;
+ allow_fast_forward=t squash=t no_commit=t ;;
--no-sq|--no-squ|--no-squa|--no-squas|--no-squash)
- squash= no_commit= ;;
+ allow_fast_forward=t squash= no_commit= ;;
--c|--co|--com|--comm|--commi|--commit)
- squash= no_commit= ;;
+ allow_fast_forward=t squash= no_commit= ;;
--no-c|--no-co|--no-com|--no-comm|--no-commi|--no-commit)
- squash= no_commit=t ;;
+ allow_fast_forward=t squash= no_commit=t ;;
+ --ff)
+ allow_fast_forward=t squash= no_commit= ;;
+ --no-ff)
+ allow_fast_forward=false squash= no_commit= ;;
-s=*|--s=*|--st=*|--str=*|--stra=*|--strat=*|--strate=*|\
--strateg=*|--strategy=*|\
-s|--s|--st|--str|--stra|--strat|--strate|--strateg|--strategy)
@@ -477,7 +481,13 @@ done
# auto resolved the merge cleanly.
if test '' != "$result_tree"
then
- parents=$(git show-branch --independent "$head" "$@" | sed -e 's/^/-p /')
+ if test "$allow_fast_forward" = "t"
+ then
+ parents=$(git show-branch --independent "$head" "$@")
+ else
+ parents=$(git rev-parse "$head" "$@")
+ fi
+ parents=$(echo "$parents" | sed -e 's/^/-p /')
result_commit=$(printf '%s\n' "$merge_msg" | git commit-tree $result_tree $parents) || exit
finish "$result_commit" "Merge made by $wt_strategy."
dropsave
diff --git a/t/t7600-merge.sh b/t/t7600-merge.sh
index b0ef488..6424c6e 100755
--- a/t/t7600-merge.sh
+++ b/t/t7600-merge.sh
@@ -417,4 +417,24 @@ test_expect_success 'merge c1 with c2 (override --squash)' '
test_debug 'gitk --all'
+test_expect_success 'merge c0 with c1 (no-ff)' '
+ git reset --hard c0 &&
+ test_tick &&
+ git merge --no-ff c1 &&
+ verify_merge file result.1 &&
+ verify_parents $c0 $c1
+'
+
+test_debug 'gitk --all'
+
+test_expect_success 'merge c0 with c1 (ff overrides no-ff)' '
+ git reset --hard c0 &&
+ git config branch.master.mergeoptions "--no-ff" &&
+ git merge --ff c1 &&
+ verify_merge file result.1 &&
+ verify_head $c1
+'
+
+test_debug 'gitk --all'
+
test_done
--
1.5.3.2.82.g75c8d
^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2007-09-23 22:52 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-23 22:51 [PATCH 0/6] per branch options for git-merge Lars Hjemli
2007-09-23 22:51 ` [PATCH 1/6] Add test-script for git-merge porcelain Lars Hjemli
2007-09-23 22:51 ` [PATCH 2/6] git-merge: fix faulty SQUASH_MSG Lars Hjemli
2007-09-23 22:51 ` [PATCH 3/6] git-merge: refactor option parsing Lars Hjemli
2007-09-23 22:51 ` [PATCH 4/6] git-merge: add support for branch.<name>.mergeoptions Lars Hjemli
2007-09-23 22:51 ` [PATCH 5/6] git-merge: add support for --commit and --no-squash Lars Hjemli
2007-09-23 22:51 ` [PATCH 6/6] git-merge: add --ff and --no-ff options Lars Hjemli
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).