Skip to contentSkip to conversation

add support for per branch merge policy

PATCH In review Lars Hjemli 3 participants 8 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

cover add support for per branch merge policy

These two patches extends git-merge with the options --ff and --no-ff, and uses the configuration setting branch.<name>.integrationonly to select the default policy per branch (it obviously defaults to --ff), as mentioned in http://article.gmane.org/gmane.comp.version-control.git/41980

This can also be used as a clean solution to the problem related to fast-forward merges between git-svn tracking branches, especially if git-svn could be taught to set integrationonly=true on all relevant branches whenever this setting is undefined.

Diffstat:

 Documentation/config.txt        |    7 +++
 Documentation/git-svn.txt       |   17 ++++++
 Documentation/merge-options.txt |   13 +++++
 git-merge.sh                    |   30 ++++++++++-
 t/t6029-merge-integration.sh    |  108 +++++++++++++++++++++++++++++++++++++++
 5 files changed, 172 insertions(+), 3 deletions(-)
#1 lore raw

PATCH 1/2 git-merge: add option --no-ff

This option forces all merges to create a "true" merge commit, i.e. a commit with multiple parents.

A fast-forward merge will often be considered The Right Thing when working in a distributed environment, but it doesn't work well when the branches to be merged originated in subversion and the merge commit will be pushed back with 'git svn dcommit'. In this case, a fast-forward merge will make git-svn mistakenly think that the current branch is tracking the merged upstream branch. But if the merge is created with --no-ff, 'git svn dcommit' will work as expected (and the history in subversion and git will be equal).

There are also a use-case for --no-ff in 'native git' when integrating topic
branches: if the merge of a topic-branch results in a fast-forward operation, there will be no way to detect that the topic-branch ever existed. This might be good or bad dependent on project policy, but both options (ff/no-ff) are technically sane.

---
 Documentation/git-svn.txt       |   13 +++++++++++
 Documentation/merge-options.txt |    5 ++++
 git-merge.sh                    |   13 +++++++++-
 t/t6029-merge-integration.sh    |   46 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 75 insertions(+), 2 deletions(-)
 create mode 100755 t/t6029-merge-integration.sh
Documentation/git-svn.txt +13 -0
index e157c6a..619023d 100644
@@ -475,6 +475,19 @@ use 'git-svn rebase' to update your work branch instead of 'git pull' or
 when committing into SVN, which can lead to merge commits reversing
 previous commits in SVN.
 
+If you use 'git-svn dcommit' to commit your local work to the upstream
+subversion branch, merge commits are usually handled correctly, i.e.
+git-svn will only follow the first parent of each merge commit and create
+a single subversion revision for each of them. An exception is when two
+subversion branches has been merged locally and the merge ended up as a
+fast-forward operation. This will make git-svn believe that there are no
+local changes to dcommit. To work around this issue, one can redo the
+merge using the --no-ff option:
+
+       $ git reset --hard HEAD@{1}   ## undo the fast-forward merge
+       $ git merge --no-ff <branch>
+
+
 DESIGN PHILOSOPHY
 -----------------
 Merge tracking in Subversion is lacking and doing branched development
Documentation/merge-options.txt +5 -0
index d64c259..b34b888 100644
@@ -25,3 +25,8 @@
 	If there is no `-s` option, a built-in list of strategies
 	is used instead (`git-merge-recursive` when merging a single
 	head, `git-merge-octopus` otherwise).
+
+--no-ff::
+	Force the creation of a merge commit even when the merge would
+	have resolved as a fast-forward operation. See gitlink:git-svn[1]
+	for a use-case for this option.
git-merge.sh +11 -2
index 3a01db0..70ca5ff 100755
@@ -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-ff] [--squash] [-s <strategy>] [-m=<merge-message>] <commit>+'
 
 SUBDIRECTORY_OK=Yes
 . git-sh-setup
@@ -165,6 +165,9 @@ do
 		merge_msg="$1"
 		have_message=t
 		;;
+	--no-ff)
+		allow_fast_forward=f
+		;;
 	-*)	usage ;;
 	*)	break ;;
 	esac
@@ -444,7 +447,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" = "f"
+    then
+        parents=$(git rev-parse "$head" "$@")
+    else
+        parents=$(git show-branch --independent "$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
t/t6029-merge-integration.sh new file +46 -0

46 lines not on this page · raw message

Signature · 1 line
1.5.3.2.82.g75c8d
#2 lore raw

PATCH 2/2 add support for branch.<name>.integrationonly

This setting can be used to set --no-ff as default merge policy for selected branches. There is also a new new merge-option, --ff, which can be used to override the default.

---
 Documentation/config.txt        |    7 ++++
 Documentation/git-svn.txt       |    4 ++
 Documentation/merge-options.txt |   14 +++++++--
 git-merge.sh                    |   19 ++++++++++-
 t/t6029-merge-integration.sh    |   64 ++++++++++++++++++++++++++++++++++++++-
 5 files changed, 102 insertions(+), 6 deletions(-)
Documentation/config.txt +7 -0
index 015910f..fa7c3c1 100644
@@ -337,6 +337,13 @@ branch.<name>.merge::
 	branch.<name>.merge to the desired branch, and use the special setting
 	`.` (a period) for branch.<name>.remote.
 
+branch.<name>.integrationonly::
+	When merging into branch <name>, this setting specifies whether
+	fast-forward merges are disallowed. The setting can be overridden
+	by the --ff and --no-ff options of gitlink:git-merge[1]. See
+	gitlink:git-svn[1] for information about this setting when
+	working with subversion branches. Defaults to false.
+
 clean.requireForce::
 	A boolean to make git-clean do nothing unless given -f or -n.  Defaults
 	to false.
Documentation/git-svn.txt +4 -0
index 619023d..55828a3 100644
@@ -487,6 +487,10 @@ merge using the --no-ff option:
        $ git reset --hard HEAD@{1}   ## undo the fast-forward merge
        $ git merge --no-ff <branch>
 
+Alternatively, one can configure the appropriate local branches to use
+--no-ff as default by setting branch.<name>.integrationonly=true in
+$GIT_DIR/config.
+
 
 DESIGN PHILOSOPHY
 -----------------
Documentation/merge-options.txt +11 -3
index b34b888..f83bba9 100644
@@ -26,7 +26,15 @@
 	is used instead (`git-merge-recursive` when merging a single
 	head, `git-merge-octopus` otherwise).
 
+--ff::
+	Explicitly allow fast-forward merges. This can be used to
+	override the merge policy of the current branch, as specified
+	by the branch.<branch>.integrationonly configuration setting (see 
+	gitlink:git-config[1] for further details).
+
 --no-ff::
-	Force the creation of a merge commit even when the merge would
-	have resolved as a fast-forward operation. See gitlink:git-svn[1]
-	for a use-case for this option.
+	Explicitly disallow fast-forward merges. This can be used to
+	override the merge policy of the current branch, as specified
+	by the branch.<branch>.integrationonly configuration setting (see 
+	gitlink:git-config[1] for further details, and gitlink:git-svn[1]
+	for a use-case for this option).
git-merge.sh +17 -2
index 70ca5ff..4775767 100755
@@ -3,7 +3,7 @@
 # Copyright (c) 2005 Junio C Hamano
 #
 
-USAGE='[-n] [--summary] [--no-commit] [--no-ff] [--squash] [-s <strategy>] [-m=<merge-message>] <commit>+'
+USAGE='[-n] [--summary] [--no-commit] [--ff] [--no-ff] [--squash] [-s <strategy>] [-m=<merge-message>] <commit>+'
 
 SUBDIRECTORY_OK=Yes
 . git-sh-setup
@@ -23,7 +23,7 @@ no_fast_forward_strategies='subtree ours'
 no_trivial_strategies='recursive recur subtree ours'
 use_strategies=
 
-allow_fast_forward=t
+allow_fast_forward=
 allow_trivial_merge=t
 
 dropsave() {
@@ -165,6 +165,9 @@ do
 		merge_msg="$1"
 		have_message=t
 		;;
+	--ff)
+		allow_fast_forward=t
+		;;
 	--no-ff)
 		allow_fast_forward=f
 		;;
@@ -245,6 +248,18 @@ do
 done
 set x $remoteheads ; shift
 
+if test -z "$allow_fast_forward"
+then
+	branch=$(git-symbolic-ref HEAD | sed -e 's|^refs/heads/||')
+	integrate=$(git config --bool "branch.$branch.integrationonly")
+	if test -n "$branch" -a "$integrate" = "true"
+	then
+		allow_fast_forward=f
+	else
+		allow_fast_forward=t
+	fi
+fi
+
 case "$use_strategies" in
 '')
 	case "$#" in
t/t6029-merge-integration.sh +63 -1

75 lines not on this page · raw message

Signature · 1 line
1.5.3.2.82.g75c8d
#3 lore raw

Re: [PATCH 2/2] add support for branch.<name>.integrationonly

Hi,

Quoted 1 line · Lars Hjemli

+branch.<name>.integrationonly::

Why not have something like branch.<name>.mergeOptions instead?

Ciao,
Dscho

#4 lore raw

Re: [PATCH 2/2] add support for branch.<name>.integrationonly

Quoted 5 lines · Johannes Schindelin
Quoted 1 line · Lars Hjemli

+branch.<name>.integrationonly::

Why not have something like branch.<name>.mergeOptions instead?

Why make it plural? I agree that it's better to have a multiple values option than having just "true/false", which makes it more extensible, but I don't understand the kind of things you could put here that wouldn't be better located in a separate configuration option.

Signature · 1 line
Matthieu
#5 lore raw
In reply to Lars Hjemli
Quoted 1 line · Lars Hjemli

branch.<name>.integrationonly

Btw: we might want to call this 'branch.<name>.mergepolicy' with the possible values 'synchronize' and 'integrate'.

--
larsh

#6 lore raw

Hi,

Quoted 5 lines · Lars Hjemli
Quoted 1 line · Lars Hjemli

branch.<name>.integrationonly

Btw: we might want to call this 'branch.<name>.mergepolicy' with the possible values 'synchronize' and 'integrate'.

IMHO this is way too limiting.

Ciao,
Dscho

#7 lore raw

[...joining two posts in one...]

Quoted 8 lines · Johannes Schindelin
Quoted 5 lines · Lars Hjemli
Quoted 1 line

branch.<name>.integrationonly

Btw: we might want to call this 'branch.<name>.mergepolicy' with the possible values 'synchronize' and 'integrate'.

IMHO this is way too limiting.
Why not have something like branch.<name>.mergeOptions instead?

Yeah, that would be more powerful, I'll give it a try.

--
larsh