Skip to contentSkip to conversation

Fix some tab/space inconsistencies in git-mergetool.sh

PATCH In review Charles Bailey 5 participants 13 messages Jun 15, 2016 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/3 Fix some tab/space inconsistencies in git-mergetool.sh

git-mergetool.sh mostly uses 8 space tabs and 4 spaces per indent. This change corrects this in a part of the file affect by a later commit in this patch series. diff -w considers this change is to be a null change.

---
 git-mergetool.sh |   38 +++++++++++++++++++-------------------
 1 files changed, 19 insertions(+), 19 deletions(-)
git-mergetool.sh +19 -19
index 94187c3..e2da5fc 100755
@@ -401,25 +401,25 @@ fi
 
 
 if test $# -eq 0 ; then
-	files=`git ls-files -u | sed -e 's/^[^	]*	//' | sort -u`
-	if test -z "$files" ; then
-		echo "No files need merging"
-		exit 0
-	fi
-	echo Merging the files: "$files"
-	git ls-files -u |
-	sed -e 's/^[^	]*	//' |
-	sort -u |
-	while IFS= read i
-	do
-		printf "\n"
-		merge_file "$i" < /dev/tty > /dev/tty
-	done
+    files=`git ls-files -u | sed -e 's/^[^	]*	//' | sort -u`
+    if test -z "$files" ; then
+	echo "No files need merging"
+	exit 0
+    fi
+    echo Merging the files: "$files"
+    git ls-files -u |
+    sed -e 's/^[^	]*	//' |
+    sort -u |
+    while IFS= read i
+    do
+	printf "\n"
+	merge_file "$i" < /dev/tty > /dev/tty
+    done
 else
-	while test $# -gt 0; do
-		printf "\n"
-		merge_file "$1"
-		shift
-	done
+    while test $# -gt 0; do
+	printf "\n"
+	merge_file "$1"
+	shift
+    done
 fi
 exit 0
Signature · 1 line
1.6.0.2.534.g5ab59
#1 lore raw

PATCH 2/3 Add -n/--no-prompt option to mergetool

This option lets git mergetool invoke the conflict resolution program without waiting for a user response each time.

Also added a mergetool.prompt (default true) configuration variable controlling the same behaviour.

---
 Documentation/config.txt        |    3 +++
 Documentation/git-mergetool.txt |   11 ++++++++++-
 git-mergetool.sh                |   16 +++++++++++++---
 3 files changed, 26 insertions(+), 4 deletions(-)
Documentation/config.txt +3 -0
index 29369d0..b4e4ee4 100644
@@ -976,6 +976,9 @@ mergetool.keepBackup::
 	is set to `false` then this file is not preserved.  Defaults to
 	`true` (i.e. keep the backup files).
 
+mergetool.prompt::
+	Prompt before each invocation of the merge resolution program.
+
 pack.window::
 	The size of the window used by linkgit:git-pack-objects[1] when no
 	window size is given on the command line. Defaults to 10.
Documentation/git-mergetool.txt +10 -1
index e0b2703..6d6bfe0 100644
@@ -7,7 +7,7 @@ git-mergetool - Run merge conflict resolution tools to resolve merge conflicts
 
 SYNOPSIS
 --------
-'git mergetool' [--tool=<tool>] [<file>]...
+'git mergetool' [--tool=<tool>] [-n|--no-prompt|--prompt] [<file>]...
 
 DESCRIPTION
 -----------
@@ -60,6 +60,15 @@ variable `mergetool.<tool>.trustExitCode` can be set to `true`.
 Otherwise, 'git-mergetool' will prompt the user to indicate the
 success of the resolution after the custom tool has exited.
 
+-n or --no-prompt::
+	Don't prompt before each invocation of the merge resolution
+	program.
+
+--prompt::
+	Prompt before each invocation of the merge resolution program.
+	This is the default behaviour; the option is provided to
+	override any configuration settings.
+
 Author
 ------
 Written by Theodore Y Ts'o <[email protected]>
git-mergetool.sh +13 -3
index e2da5fc..8bc5366 100755
@@ -8,7 +8,7 @@
 # at the discretion of Junio C Hamano.
 #
 
-USAGE='[--tool=tool] [file to merge] ...'
+USAGE='[--tool=tool] [-n|--no-prompt|--prompt] [file to merge] ...'
 SUBDIRECTORY_OK=Yes
 OPTIONS_SPEC=
 . git-sh-setup
@@ -176,8 +176,10 @@ merge_file () {
     echo "Normal merge conflict for '$MERGED':"
     describe_file "$local_mode" "local" "$LOCAL"
     describe_file "$remote_mode" "remote" "$REMOTE"
-    printf "Hit return to start merge resolution tool (%s): " "$merge_tool"
-    read ans
+    if "$prompt" = true; then
+	printf "Hit return to start merge resolution tool (%s): " "$merge_tool"
+	read ans
+    fi
 
     case "$merge_tool" in
 	kdiff3)
@@ -280,6 +282,8 @@ merge_file () {
     cleanup_temp_files
 }
 
+prompt=$(git config --bool mergetool.prompt || echo true)
+
 while test $# != 0
 do
     case "$1" in
@@ -295,6 +299,12 @@ do
 		    shift ;;
 	    esac
 	    ;;
+	-n|--no-prompt)
+	    prompt=false
+	    ;;
+	--prompt)
+	    prompt=true
+	    ;;
 	--)
 	    break
 	    ;;
Signature · 1 line
1.6.0.2.534.g5ab59
#2 lore raw

PATCH 3/3 Add -k/--keep-going option to mergetool

This option stops git mergetool from aborting at the first failed merge. This allows some additional use patterns. Merge conflicts can now be previewed one at time and merges can also be skipped so that they can be performed in a later pass.

There is also a mergetool.keepGoing configuration variable covering the same behaviour.

---
 Documentation/config.txt        |    4 +++
 Documentation/git-mergetool.txt |   12 +++++++++-
 git-mergetool.sh                |   46 ++++++++++++++++++++++++++++++--------
 3 files changed, 51 insertions(+), 11 deletions(-)
Documentation/config.txt +4 -0
index b4e4ee4..789c88a 100644
@@ -976,6 +976,10 @@ mergetool.keepBackup::
 	is set to `false` then this file is not preserved.  Defaults to
 	`true` (i.e. keep the backup files).
 
+mergetool.keepGoing::
+	Continue to attempt resolution of remaining conflicted files even
+	after a merge has failed or been aborted.
+
 mergetool.prompt::
 	Prompt before each invocation of the merge resolution program.
 
Documentation/git-mergetool.txt +11 -1
index 6d6bfe0..15466f3 100644
@@ -7,7 +7,8 @@ git-mergetool - Run merge conflict resolution tools to resolve merge conflicts
 
 SYNOPSIS
 --------
-'git mergetool' [--tool=<tool>] [-n|--no-prompt|--prompt] [<file>]...
+'git mergetool' [--tool=<tool>] [-n|--no-prompt|--prompt]
+	[-k|--keep-going|--no-keep-going] [<file>]...
 
 DESCRIPTION
 -----------
@@ -69,6 +70,15 @@ success of the resolution after the custom tool has exited.
 	This is the default behaviour; the option is provided to
 	override any configuration settings.
 
+-k or --keep-going::
+	Continue to attempt resolution of remaining conflicted files
+	even after a merge has failed or been aborted.
+
+--no-keep-going::
+	Abort the conflict resolution attempt if any single conflict
+	resolution fails or is aborted. This is the default behaviour;
+	the option is provided to override any configuration settings.
+
 Author
 ------
 Written by Theodore Y Ts'o <[email protected]>
git-mergetool.sh +36 -10

121 lines not on this page · raw message

Signature · 1 line
1.6.0.2.534.g5ab59
#3 lore raw

Re: [PATCH 3/3] Add -k/--keep-going option to mergetool

Quoted 4 lines · Charles Bailey

This option stops git mergetool from aborting at the first failed merge. This allows some additional use patterns. Merge conflicts can now be previewed one at time and merges can also be skipped so that they can be performed in a later pass.

All 3 patches look good to me, and match what I expected from our earlier discussion. But I am not too familiar with mergetool, so take my approval with a grain of salt. :)

-Peff

#4 lore raw

Re: [PATCH 2/3] Add -n/--no-prompt option to mergetool

In reply to Charles Bailey
Quoted 41 lines · Charles Bailey

This option lets git mergetool invoke the conflict resolution program without waiting for a user response each time.

Also added a mergetool.prompt (default true) configuration variable controlling the same behaviour.

---
 Documentation/config.txt        |    3 +++
 Documentation/git-mergetool.txt |   11 ++++++++++-
 git-mergetool.sh                |   16 +++++++++++++---
 3 files changed, 26 insertions(+), 4 deletions(-)
Documentation/config.txt +3 -0
index 29369d0..b4e4ee4 100644
@@ -976,6 +976,9 @@ mergetool.keepBackup::
 	is set to `false` then this file is not preserved.  Defaults to
 	`true` (i.e. keep the backup files).
 
+mergetool.prompt::
+	Prompt before each invocation of the merge resolution program.
+
 pack.window::
 	The size of the window used by linkgit:git-pack-objects[1] when no
 	window size is given on the command line. Defaults to 10.
Documentation/git-mergetool.txt +1 -1
index e0b2703..6d6bfe0 100644
@@ -7,7 +7,7 @@ git-mergetool - Run merge conflict resolution tools to resolve merge conflicts
 
 SYNOPSIS
 --------
-'git mergetool' [--tool=<tool>] [<file>]...
+'git mergetool' [--tool=<tool>] [-n|--no-prompt|--prompt] [<file>]...
 
 DESCRIPTION
 -----------

Documentation/git-mergetool.txt variable `mergetool.<tool>.trustExitCode` can be set to `true`. · line 66

Quoted 7 lines
Documentation/git-mergetool.txt +4 -0
@@ -60,6 +60,15 @@ variable `mergetool.<tool>.trustExitCode` can be set to `true`.
 Otherwise, 'git-mergetool' will prompt the user to indicate the
 success of the resolution after the custom tool has exited.
 
+-n or --no-prompt::
+	Don't prompt before each invocation of the merge resolution
+	program.
+

There is discussion already about "-n should be for dry-run!" and git's inconsistencies in such matters. Wouldn't -y ("assume yes on prompt") be better?

Signature · 3 lines
Andreas Ericsson                   [email protected]
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
#5 lore raw

Re: [PATCH 2/3] Add -n/--no-prompt option to mergetool

Quoted 5 lines · Andreas Ericsson

There is discussion already about "-n should be for dry-run!" and git's inconsistencies in such matters. Wouldn't -y ("assume yes on prompt") be better?

I must have missed this discussion. I've just had a very quick look at a handful of basic modifying git commands (merge, pull, commit, checkout, reset, revert) and only found 'add' that used -n as --dry-run.

That said, I've no real objections to -y if that makes for a better consensus.

Signature · 2 lines
Charles Bailey
http://ccgi.hashpling.plus.com/blog/
#6 lore raw

Re: [PATCH 2/3] Add -n/--no-prompt option to mergetool

Quoted 7 lines · Charles Bailey
Quoted 5 lines · Andreas Ericsson

There is discussion already about "-n should be for dry-run!" and git's inconsistencies in such matters. Wouldn't -y ("assume yes on prompt") be better?

Quoted 8 lines

I must have missed this discussion. I've just had a very quick look at a handful of basic modifying git commands (merge, pull, commit, checkout, reset, revert) and only found 'add' that used -n as --dry-run.

That said, I've no real objections to -y if that makes for a better consensus.

I'm pretty keen on this patch, but have no strong opinions on which short option is used, so are there any votes against -y?

If I re-roll with the favoured short option is there anything else that would prevent its adoption into next or master?

Signature · 2 lines
Charles Bailey
http://ccgi.hashpling.plus.com/blog/
#7 lore raw

Re: [PATCH 2/3] Add -n/--no-prompt option to mergetool

Quoted 2 lines · Charles Bailey

I'm pretty keen on this patch, but have no strong opinions on which short option is used, so are there any votes against -y?

Between 'n' and 'y', I am in favour of the latter, but at the same time I have to wonder if there are other commands that would want "Assume yes" option. It could be that this single command that prompts for "Is this Ok" is an oddball and giving it an "interactive" option to trigger the current behaviour might make things more consistent. I dunno.

#8 lore raw

Re: [PATCH 2/3] Add -n/--no-prompt option to mergetool

Quoted 11 lines · Junio C Hamano
Quoted 2 lines · Charles Bailey

I'm pretty keen on this patch, but have no strong opinions on which short option is used, so are there any votes against -y?

Between 'n' and 'y', I am in favour of the latter, but at the same time I have to wonder if there are other commands that would want "Assume yes" option. It could be that this single command that prompts for "Is this Ok" is an oddball and giving it an "interactive" option to trigger the current behaviour might make things more consistent. I dunno.

I think that git mergetool probably counts as at least 'unusual', and I think that there is some merit in the current default behaviour. It gives you a prompt at which you can C-c if it's about to run something that you don't want it to do the first few times that you try mergetool.

After more thoughts, I'm somewhat in favour of dropping the short switch altogether. As it just saves a single keypress per merge I imagine that most mergetool users, once they discover this new feature and decide that they want to use it, will prefer to use a user config option to switch it on. The command line option then becomes something that you would only need to use to override your normal default and something on which to hang the option description in the man page.

Signature · 2 lines
Charles Bailey
http://ccgi.hashpling.plus.com/blog/
#9 lore raw

Re: [PATCH 2/3] Add -n/--no-prompt option to mergetool

Quoted 9 lines · Charles Bailey

After more thoughts, I'm somewhat in favour of dropping the short switch altogether. As it just saves a single keypress per merge I imagine that most mergetool users, once they discover this new feature and decide that they want to use it, will prefer to use a user config option to switch it on. The command line option then becomes something that you would only need to use to override your normal default and something on which to hang the option description in the man page.

If the short option is dropped, the config option should probably associated with mergetool.<tool>.interactive rather than mergetool.interactive. (s/interactive/whatever)

Signature · 1 line
William Pursell
#10 lore raw

Re: [PATCH 2/3] Add -n/--no-prompt option to mergetool

Quoted 4 lines · William Pursell

If the short option is dropped, the config option should probably associated with mergetool.<tool>.interactive rather than mergetool.interactive. (s/interactive/whatever)

I'm not sure I understand your reasoning. The no-prompt/interactive option affects the behaviour of the mergetool script independent of which particular merge tool is being used. Why should the presence or absence of a short option affect whether the config option is global or per tool?

Signature · 2 lines
Charles Bailey
http://ccgi.hashpling.plus.com/blog/
#11 lore raw

Re: [PATCH 2/3] Add -n/--no-prompt option to mergetool

Quoted 11 lines · Charles Bailey
Quoted 3 lines · William Pursell

If the short option is dropped, the config option should probably associated with mergetool.<tool>.interactive rather than mergetool.interactive. (s/interactive/whatever)

I'm not sure I understand your reasoning. The no-prompt/interactive option affects the behaviour of the mergetool script independent of which particular merge tool is being used. Why should the presence or absence of a short option affect whether the config option is global or per tool?

My thinking is that when using an interactive tool like vimdiff, the user is probably not going to care as much about being prompted, or may prefer to have the prompt in that situation. However, if they've written a script to do the merge non-interactively, then the prompt is undesirable.

So a person might want to be prompted with git mergetool -t vimdiff, and prefer no prompt with git mergetool -t my-script. Being able to configure the behavior on a per-tool basis would allow that.

Signature · 1 line
William Pursell
#12 lore raw

Re: [PATCH 2/3] Add -n/--no-prompt option to mergetool

Quoted 8 lines · William Pursell

My thinking is that when using an interactive tool like vimdiff, the user is probably not going to care as much about being prompted, or may prefer to have the prompt in that situation. However, if they've written a script to do the merge non-interactively, then the prompt is undesirable.

Quoted 5 lines

So a person might want to be prompted with git mergetool -t vimdiff, and prefer no prompt with git mergetool -t my-script. Being able to configure the behavior on a per-tool basis would allow that.

I can see your point, although personally I feel that if you've gone to the trouble of writing a special script, the extra typing of an extra long option (if you prefer prompting normally) is not that big compared with the hassle of maintaining per-tool config settings if you like to regularly swap between merge tools.

Both scenarios are probably not too common so I wouldn't object strongly to either. (But per tool configs is more dev work!)

Signature · 2 lines
Charles Bailey
http://ccgi.hashpling.plus.com/blog/