From 0eea345111a9b9fea4dd2841b80bc7d62964e812 Mon Sep 17 00:00:00 2001 From: Charles Bailey Date: Thu, 13 Nov 2008 12:41:13 +0000 Subject: [PATCH 1/4] 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. Signed-off-by: Charles Bailey Signed-off-by: Junio C Hamano --- git-mergetool.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/git-mergetool.sh b/git-mergetool.sh index 94187c306..e2da5fc54 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -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 From 682b451f84c046aa5b082e89e3db62950cb6261a Mon Sep 17 00:00:00 2001 From: Charles Bailey Date: Thu, 13 Nov 2008 12:41:14 +0000 Subject: [PATCH 2/4] Add -y/--no-prompt option to mergetool This option lets git mergetool invoke the conflict resolution program without waiting for a user prompt each time. Also added a mergetool.prompt (default true) configuration variable controlling the same behaviour Signed-off-by: Charles Bailey Signed-off-by: Junio C Hamano --- Documentation/config.txt | 3 +++ Documentation/git-mergetool.txt | 11 ++++++++++- git-mergetool.sh | 16 +++++++++++++--- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Documentation/config.txt b/Documentation/config.txt index 32dcd643d..bc5642d60 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -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. diff --git a/Documentation/git-mergetool.txt b/Documentation/git-mergetool.txt index e0b2703b3..176483a1a 100644 --- a/Documentation/git-mergetool.txt +++ b/Documentation/git-mergetool.txt @@ -7,7 +7,7 @@ git-mergetool - Run merge conflict resolution tools to resolve merge conflicts SYNOPSIS -------- -'git mergetool' [--tool=] []... +'git mergetool' [--tool=] [-y|--no-prompt|--prompt] []... DESCRIPTION ----------- @@ -60,6 +60,15 @@ variable `mergetool..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. +-y 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 diff --git a/git-mergetool.sh b/git-mergetool.sh index e2da5fc54..507028f85 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -8,7 +8,7 @@ # at the discretion of Junio C Hamano. # -USAGE='[--tool=tool] [file to merge] ...' +USAGE='[--tool=tool] [-y|--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 ;; + -y|--no-prompt) + prompt=false + ;; + --prompt) + prompt=true + ;; --) break ;; From b0169d84df4c09ed7dfcc6aea5aecd177ddda75b Mon Sep 17 00:00:00 2001 From: Charles Bailey Date: Fri, 12 Dec 2008 21:48:40 +0000 Subject: [PATCH 3/4] mergetool: Add prompt to continue after failing to merge a file This option stops git mergetool from aborting at the first failed merge. After a failed merge the user will be prompted to indicated whether he wishes to continue with attempting to merge subsequent paths or to abort. 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. Signed-off-by: Charles Bailey Signed-off-by: Junio C Hamano --- git-mergetool.sh | 52 +++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 43 insertions(+), 9 deletions(-) diff --git a/git-mergetool.sh b/git-mergetool.sh index 507028f85..514497164 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -70,16 +70,16 @@ resolve_symlink_merge () { git checkout-index -f --stage=2 -- "$MERGED" git add -- "$MERGED" cleanup_temp_files --save-backup - return + return 0 ;; [rR]*) git checkout-index -f --stage=3 -- "$MERGED" git add -- "$MERGED" cleanup_temp_files --save-backup - return + return 0 ;; [aA]*) - exit 1 + return 1 ;; esac done @@ -97,15 +97,15 @@ resolve_deleted_merge () { [mMcC]*) git add -- "$MERGED" cleanup_temp_files --save-backup - return + return 0 ;; [dD]*) git rm -- "$MERGED" > /dev/null cleanup_temp_files - return + return 0 ;; [aA]*) - exit 1 + return 1 ;; esac done @@ -137,7 +137,7 @@ merge_file () { else echo "$MERGED: file does not need merging" fi - exit 1 + return 1 fi ext="$$$(expr "$MERGED" : '.*\(\.[^/]*\)$')" @@ -269,7 +269,7 @@ merge_file () { if test "$status" -ne 0; then echo "merge of $MERGED failed" 1>&2 mv -- "$BACKUP" "$MERGED" - exit 1 + return 1 fi if test "$merge_keep_backup" = "true"; then @@ -280,6 +280,7 @@ merge_file () { git add -- "$MERGED" cleanup_temp_files + return 0 } prompt=$(git config --bool mergetool.prompt || echo true) @@ -350,6 +351,22 @@ init_merge_tool_path() { fi } +prompt_after_failed_merge() { + while true; do + printf "Continue merging other unresolved paths (y/n) ? " + read ans + case "$ans" in + + [yY]*) + return 0 + ;; + + [nN]*) + return 1 + ;; + esac + done +} if test -z "$merge_tool"; then merge_tool=`git config merge.tool` @@ -409,6 +426,8 @@ else fi fi +last_status=0 +rollup_status=0 if test $# -eq 0 ; then files=`git ls-files -u | sed -e 's/^[^ ]* //' | sort -u` @@ -422,14 +441,29 @@ if test $# -eq 0 ; then sort -u | while IFS= read i do + if test $last_status -ne 0; then + prompt_after_failed_merge < /dev/tty || exit 1 + fi printf "\n" merge_file "$i" < /dev/tty > /dev/tty + last_status=$? + if test $last_status -ne 0; then + rollup_status=1 + fi done else while test $# -gt 0; do + if test $last_status -ne 0; then + prompt_after_failed_merge || exit 1 + fi printf "\n" merge_file "$1" + last_status=$? + if test $last_status -ne 0; then + rollup_status=1 + fi shift done fi -exit 0 + +exit $rollup_status From 162eba8b43a0e665c8e3439191981412815cc6db Mon Sep 17 00:00:00 2001 From: Charles Bailey Date: Fri, 12 Dec 2008 21:48:41 +0000 Subject: [PATCH 4/4] mergetool: Don't keep temporary merge files unless told to This changes git mergetool to remove the temporary files used to invoke the merge tool even if it returns non-zero. This also adds a configuration option (mergetool.keepTemporaries) to retain the previous behaviour if desired. Signed-off-by: Charles Bailey Signed-off-by: Junio C Hamano --- Documentation/config.txt | 7 +++++++ git-mergetool.sh | 6 ++++++ 2 files changed, 13 insertions(+) diff --git a/Documentation/config.txt b/Documentation/config.txt index bc5642d60..3d5a8df0c 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -976,6 +976,13 @@ mergetool.keepBackup:: is set to `false` then this file is not preserved. Defaults to `true` (i.e. keep the backup files). +mergetool.keepTemporaries:: + When invoking a custom merge tool, git uses a set of temporary + files to pass to the tool. If the tool returns an error and this + variable is set to `true`, then these temporary files will be + preserved, otherwise they will be removed after the tool has + exited. Defaults to `false`. + mergetool.prompt:: Prompt before each invocation of the merge resolution program. diff --git a/git-mergetool.sh b/git-mergetool.sh index 514497164..f04240dac 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -269,6 +269,11 @@ merge_file () { if test "$status" -ne 0; then echo "merge of $MERGED failed" 1>&2 mv -- "$BACKUP" "$MERGED" + + if test "$merge_keep_temporaries" = "false"; then + cleanup_temp_files + fi + return 1 fi @@ -415,6 +420,7 @@ else init_merge_tool_path "$merge_tool" merge_keep_backup="$(git config --bool merge.keepBackup || echo true)" + merge_keep_temporaries="$(git config --bool mergetool.keepTemporaries || echo false)" if test -z "$merge_tool_cmd" && ! type "$merge_tool_path" > /dev/null 2>&1; then echo "The merge tool $merge_tool is not available as '$merge_tool_path'"