Skip to contentSkip to conversation

mergetools: add config option to disable auto-merge

PATCH New Michael Rappazzo 3 participants 6 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 mergetools: add config option to disable auto-merge

During conflict resolution, invoking a mergetool which supports auto-merge will pass that option by default to the underlying tool.

This patch is intended to allow one to set 'merge.automerge' to 'false' in order to override this behavior.

Michael Rappazzo (1):
mergetools: add config option to disable auto-merge

 Documentation/config.txt        |  6 ++++++
 Documentation/git-mergetool.txt | 19 +++++++++++++------
 mergetools/araxis               |  4 +++-
 mergetools/diffmerge            |  4 +++-
 mergetools/kdiff3               |  4 +++-
 5 files changed, 28 insertions(+), 9 deletions(-)
Signature · 1 line
2.4.2
#1 lore raw

PATCH 1/1 mergetools: add config option to disable auto-merge

For some mergetools, the current invocation of git mergetool will include an auto-merge flag. By default the flag is included, however if the git config option 'merge.automerge' is set to 'false', then that flag will now be omitted.

---
 Documentation/config.txt        |  6 ++++++
 Documentation/git-mergetool.txt | 19 +++++++++++++------
 mergetools/araxis               |  4 +++-
 mergetools/diffmerge            |  4 +++-
 mergetools/kdiff3               |  4 +++-
 5 files changed, 28 insertions(+), 9 deletions(-)
Documentation/config.txt +6 -0
index 43bb53c..658d8f7 100644
@@ -1864,6 +1864,12 @@ mergetool.meld.hasOutput::
 	to `true` tells Git to unconditionally use the `--output` option,
 	and `false` avoids using `--output`.
 
+mergetool.automerge::
+	When invoking a custom merge tool which includes an auto-merge
+	option, Git will include that option by default.  If this variable
+	is set to `false` then the auto-merge option is not used when 
+	invoking the custom merge tool.
+
 mergetool.keepBackup::
 	After performing a merge, the original file with conflict markers
 	can be saved as a file with a `.orig` extension.  If this variable
Documentation/git-mergetool.txt +13 -6
index e846c2e..3461d3a 100644
@@ -79,16 +79,23 @@ success of the resolution after the custom tool has exited.
 	Prompt before each invocation of the merge resolution program
 	to give the user a chance to skip the path.
 
-TEMPORARY FILES
----------------
-`git mergetool` creates `*.orig` backup files while resolving merges.
-These are safe to remove once a file has been merged and its
-`git mergetool` session has completed.
-
+CONFIGURATION OPTIONS
+---------------------
+mergetool.keepBackup::
+	`git mergetool` creates `*.orig` backup files while resolving merges.
+	These are safe to remove once a file has been merged and its
+	`git mergetool` session has completed.
++
 Setting the `mergetool.keepBackup` configuration variable to `false`
 causes `git mergetool` to automatically remove the backup as files
 are successfully merged.
 
+mergetool.automerge::
+	For some mergetools, the current invocation of git mergetool will
+	include an auto-merge flag.  By default the flag is included, however if
+	the git config option `merge.automerge` is set to `false`, then that
+	flag will be omitted.
+
 GIT
 ---
 Part of the linkgit:git[1] suite
mergetools/araxis +3 -1
index 64f97c5..00e63da 100644
@@ -6,7 +6,9 @@ merge_cmd () {
 	touch "$BACKUP"
 	if $base_present
 	then
-		"$merge_tool_path" -wait -merge -3 -a1 \
+		automerge="-merge"
+		test "$(git config --get --bool mergetool.automerge)" = false && automerge=''
+		"$merge_tool_path" -wait ${automerge} -3 -a1 \
 			"$BASE" "$LOCAL" "$REMOTE" "$MERGED" >/dev/null 2>&1
 	else
 		"$merge_tool_path" -wait -2 \
mergetools/diffmerge +3 -1
index f138cb4..287489b 100644
@@ -5,7 +5,9 @@ diff_cmd () {
 merge_cmd () {
 	if $base_present
 	then
-		"$merge_tool_path" --merge --result="$MERGED" \
+		automerge="--merge"
+		test "$(git config --get --bool mergetool.automerge)" = false && automerge=''
+		"$merge_tool_path" ${automerge} --result="$MERGED" \
 			"$LOCAL" "$BASE" "$REMOTE"
 	else
 		"$merge_tool_path" --merge \
mergetools/kdiff3 +3 -1
index 793d129..8e1d063 100644
@@ -7,7 +7,9 @@ diff_cmd () {
 merge_cmd () {
 	if $base_present
 	then
-		"$merge_tool_path" --auto \
+		automerge="--auto"
+		test "$(git config --get --bool mergetool.automerge)" = false && automerge=''
+		"$merge_tool_path" ${automerge} \
 			--L1 "$MERGED (Base)" \
 			--L2 "$MERGED (Local)" \
 			--L3 "$MERGED (Remote)" \
Signature · 1 line
2.4.2
#2 lore raw
Quoted 4 lines · Michael Rappazzo

For some mergetools, the current invocation of git mergetool will include an auto-merge flag. By default the flag is included, however if the git config option 'merge.automerge' is set to 'false', then that flag will now be omitted.

... and why is the "automerge" a bad thing that user would want to avoid triggering under which condition? That description may not have to be in the proposed log message, but it would help users when they decide if they want to use the configuration to describe it in the mergetool.automerge configuration.

And depending on the answer to the above question, a configuration variable may turn out be a bad mechanism to customize this (namely, set-and-forget configuration variable is a bad match for a knob that is more "per invocation" than "user taste").

Is this not about "automerge" but more about "always-show-UI because I like GUI?" Then that may be a "user taste" thing that is a good match for a configuration variable. I simply cannot tell from what was in the message I am responding to.

Documentation/git-mergetool.txt success of the resolution after the custom tool has exited. · line 88

Quoted 13 lines
Documentation/git-mergetool.txt +7 -6
-TEMPORARY FILES
----------------
-`git mergetool` creates `*.orig` backup files while resolving merges.
-These are safe to remove once a file has been merged and its
-`git mergetool` session has completed.
-
+CONFIGURATION OPTIONS
+---------------------
+mergetool.keepBackup::
+	`git mergetool` creates `*.orig` backup files while resolving merges.
+	These are safe to remove once a file has been merged and its
+	`git mergetool` session has completed.
++

This is an unrelated change; I think it is a good change, though.

I however suspect that we would not want to repeat the configuration description in this file and instead mention these in "see also" section referring the readers to git-config(1).

#3 lore raw
Quoted 18 lines · Junio C Hamano
Quoted 4 lines · Michael Rappazzo

For some mergetools, the current invocation of git mergetool will include an auto-merge flag. By default the flag is included, however if the git config option 'merge.automerge' is set to 'false', then that flag will now be omitted.

... and why is the "automerge" a bad thing that user would want to avoid triggering under which condition? That description may not have to be in the proposed log message, but it would help users when they decide if they want to use the configuration to describe it in the mergetool.automerge configuration.

And depending on the answer to the above question, a configuration variable may turn out be a bad mechanism to customize this (namely, set-and-forget configuration variable is a bad match for a knob that is more "per invocation" than "user taste").

Quoted 4 lines

Is this not about "automerge" but more about "always-show-UI because I like GUI?" Then that may be a "user taste" thing that is a good match for a configuration variable. I simply cannot tell from what was in the message I am responding to.

I feel that the auto-merge takes away the context of the changes.

I use araxis merge as my mergetool of choice. I almost always immediately undo the auto-merge. After taking a moment to look at each file, I will then (usually) use the keyboard shortcut for auto-merge.

It sure would be nice to "set-and-forget" a config variable to remove the annoyance of having to undo the auto-merge. I think that this config option is reasonable. Perhaps my documentation leaves something to be desired. I can take another stab at it.

Quoted 17 lines
Quoted 4 lines
Documentation/git-mergetool.txt +0 -3
-TEMPORARY FILES
----------------
-`git mergetool` creates `*.orig` backup files while resolving merges.

Documentation/git-mergetool.txt success of the resolution after the custom tool has exited. · line 88

Quoted 10 lines
Documentation/git-mergetool.txt +7 -3
-These are safe to remove once a file has been merged and its
-`git mergetool` session has completed.
-
+CONFIGURATION OPTIONS
+---------------------
+mergetool.keepBackup::
+     `git mergetool` creates `*.orig` backup files while resolving merges.
+     These are safe to remove once a file has been merged and its
+     `git mergetool` session has completed.
++

This is an unrelated change; I think it is a good change, though.

Quoted 4 lines

I however suspect that we would not want to repeat the configuration description in this file and instead mention these in "see also" section referring the readers to git-config(1).

I felt that adding a separate header for a different config option was more appropriate, so I went with this. Pointing to the config.txt doc is probably better.

#4 lore raw
Quoted 26 lines · Mike Rappazzo
Quoted 18 lines · Junio C Hamano
Quoted 4 lines · Michael Rappazzo

For some mergetools, the current invocation of git mergetool will include an auto-merge flag. By default the flag is included, however if the git config option 'merge.automerge' is set to 'false', then that flag will now be omitted.

... and why is the "automerge" a bad thing that user would want to avoid triggering under which condition? That description may not have to be in the proposed log message, but it would help users when they decide if they want to use the configuration to describe it in the mergetool.automerge configuration.

And depending on the answer to the above question, a configuration variable may turn out be a bad mechanism to customize this (namely, set-and-forget configuration variable is a bad match for a knob that is more "per invocation" than "user taste").

Quoted 4 lines

Is this not about "automerge" but more about "always-show-UI because I like GUI?" Then that may be a "user taste" thing that is a good match for a configuration variable. I simply cannot tell from what was in the message I am responding to.

I feel that the auto-merge takes away the context of the changes.

Quoted 8 lines

I use araxis merge as my mergetool of choice. I almost always immediately undo the auto-merge. After taking a moment to look at each file, I will then (usually) use the keyboard shortcut for auto-merge.

It sure would be nice to "set-and-forget" a config variable to remove the annoyance of having to undo the auto-merge. I think that this config option is reasonable. Perhaps my documentation leaves something to be desired. I can take another stab at it.

If this is the case then I would recommend making it more granular. Just because Araxis' automerge is undesirable does not mean that some other tools' automerge is as well. e.g. the config variable could be "mergetool.<tool>.automerge" rather than the top-level "mergetool.automerge" variable.

But, as Junio suggested, having a command-line flag to skip the behavior might be a better first step. Something like, "git mergetool --no-automerge".

Most of Git's behavior that can be modified via configuration can also be modified on the command-line, so exposing this feature as a flag would probably be a good idea.

Even without a config variable, it can still be fire-and-forget convenient by using a git alias to supply the flag.

In lieu of any of these features, another option is that you can override the default command by setting "mergetool.araxis.cmd", and "git mergetool" will use your definition rather than its built-in command. We left that escape hatch in for just this purpose.

I'm curious, is this a common use case? I'm personally not a good judge of that, but I'll let the list chime in. Thoughts?

Signature · 1 line
David
#5 lore raw
Quoted 14 lines · David Aguilar
Quoted 11 lines · Mike Rappazzo

I feel that the auto-merge takes away the context of the changes.

I use araxis merge as my mergetool of choice. I almost always immediately undo the auto-merge. After taking a moment to look at each file, I will then (usually) use the keyboard shortcut for auto-merge.

It sure would be nice to "set-and-forget" a config variable to remove the annoyance of having to undo the auto-merge. I think that this config option is reasonable. Perhaps my documentation leaves something to be desired. I can take another stab at it.

Quoted 5 lines

If this is the case then I would recommend making it more granular. Just because Araxis' automerge is undesirable does not mean that some other tools' automerge is as well. e.g. the config variable could be "mergetool.<tool>.automerge" rather than the top-level "mergetool.automerge" variable.

I don't necessarily think that araxis' automerge is bad, but I like to look at the before and after to understand the context of a conflict. I can't imagine that this is a quirk of araxis, but is probably something that exists for any auto-merging tool. The feature doesn't seem to be that widely supported among the other tooling. I only found the three to use such a feature.

Since the automerge option is not available on every merge tool, it seems reasonable to use "mergetool.<tool>.automerge" instead of "merge.automerge".

Quoted 9 lines

But, as Junio suggested, having a command-line flag to skip the behavior might be a better first step. Something like, "git mergetool --no-automerge".

Most of Git's behavior that can be modified via configuration can also be modified on the command-line, so exposing this feature as a flag would probably be a good idea.

This makes sense, and if this change is to go forward, I will implement the command line option.

Quoted 9 lines

Even without a config variable, it can still be fire-and-forget convenient by using a git alias to supply the flag.

In lieu of any of these features, another option is that you can override the default command by setting "mergetool.araxis.cmd", and "git mergetool" will use your definition rather than its built-in command. We left that escape hatch in for just this purpose.

I guess that if this patch does not go forward, I will have to use this workaround.