From f9e43085bb95034a36a223f4eba75174b096179c Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Wed, 15 Oct 2014 01:35:20 -0700 Subject: [PATCH 1/6] t7610-mergetool: prefer test_config over git config Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano --- t/t7610-mergetool.sh | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/t/t7610-mergetool.sh b/t/t7610-mergetool.sh index 214edfbcfc..3502ec9fe5 100755 --- a/t/t7610-mergetool.sh +++ b/t/t7610-mergetool.sh @@ -14,7 +14,7 @@ Testing basic merge tool invocation' # running mergetool test_expect_success 'setup' ' - git config rerere.enabled true && + test_config rerere.enabled true && echo master >file1 && echo master spaced >"spaced name" && echo master file11 >file11 && @@ -112,7 +112,7 @@ test_expect_success 'custom mergetool' ' ' test_expect_success 'mergetool crlf' ' - git config core.autocrlf true && + test_config core.autocrlf true && git checkout -b test2 branch1 && test_must_fail git merge master >/dev/null 2>&1 && ( yes "" | git mergetool file1 >/dev/null 2>&1 ) && @@ -129,7 +129,7 @@ test_expect_success 'mergetool crlf' ' git submodule update -N && test "$(cat submod/bar)" = "master submodule" && git commit -m "branch1 resolved with mergetool - autocrlf" && - git config core.autocrlf false && + test_config core.autocrlf false && git reset --hard ' @@ -176,7 +176,7 @@ test_expect_success 'mergetool skips autoresolved' ' test_expect_success 'mergetool merges all from subdir' ' ( cd subdir && - git config rerere.enabled false && + test_config rerere.enabled false && test_must_fail git merge master && ( yes "r" | git mergetool ../submod ) && ( yes "d" "d" | git mergetool --no-prompt ) && @@ -190,7 +190,7 @@ test_expect_success 'mergetool merges all from subdir' ' ' test_expect_success 'mergetool skips resolved paths when rerere is active' ' - git config rerere.enabled true && + test_config rerere.enabled true && rm -rf .git/rr-cache && git checkout -b test5 branch1 && git submodule update -N && @@ -204,7 +204,7 @@ test_expect_success 'mergetool skips resolved paths when rerere is active' ' ' test_expect_success 'conflicted stash sets up rerere' ' - git config rerere.enabled true && + test_config rerere.enabled true && git checkout stash1 && echo "Conflicting stash content" >file11 && git stash && @@ -232,7 +232,7 @@ test_expect_success 'conflicted stash sets up rerere' ' test_expect_success 'mergetool takes partial path' ' git reset --hard && - git config rerere.enabled false && + test_config rerere.enabled false && git checkout -b test12 branch1 && git submodule update -N && test_must_fail git merge master && @@ -505,14 +505,12 @@ test_expect_success 'file with no base' ' test_expect_success 'custom commands override built-ins' ' git checkout -b test14 branch1 && - git config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && - git config mergetool.defaults.trustExitCode true && + test_config mergetool.defaults.cmd "cat \"\$REMOTE\" >\"\$MERGED\"" && + test_config mergetool.defaults.trustExitCode true && test_must_fail git merge master && git mergetool --no-prompt --tool defaults -- both && echo master both added >expected && test_cmp both expected && - git config --unset mergetool.defaults.cmd && - git config --unset mergetool.defaults.trustExitCode && git reset --hard master >/dev/null 2>&1 ' From 76ee96a9b6f75e7d1c01e68ade72194179aa512d Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Wed, 15 Oct 2014 01:35:21 -0700 Subject: [PATCH 2/6] test-lib-functions: adjust style to match CodingGuidelines Prefer "test" over "[ ]" for conditionals. Prefer "$()" over backticks for command substitutions. Avoid control structures on a single line with semicolons. Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano --- t/test-lib-functions.sh | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index cf7b41f66d..6bb7e9767b 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -413,7 +413,7 @@ test_external () { # test_run_, but keep its stdout on our stdout even in # non-verbose mode. "$@" 2>&4 - if [ "$?" = 0 ] + if test "$?" = 0 then if test $test_external_has_tap -eq 0; then test_ok_ "$descr" @@ -440,11 +440,12 @@ test_external_without_stderr () { tmp=${TMPDIR:-/tmp} stderr="$tmp/git-external-stderr.$$.tmp" test_external "$@" 4> "$stderr" - [ -f "$stderr" ] || error "Internal error: $stderr disappeared." + test -f "$stderr" || error "Internal error: $stderr disappeared." descr="no stderr: $1" shift say >&3 "# expecting no stderr from previous command" - if [ ! -s "$stderr" ]; then + if test ! -s "$stderr" + then rm "$stderr" if test $test_external_has_tap -eq 0; then @@ -454,8 +455,9 @@ test_external_without_stderr () { test_success=$(($test_success + 1)) fi else - if [ "$verbose" = t ]; then - output=`echo; echo "# Stderr is:"; cat "$stderr"` + if test "$verbose" = t + then + output=$(echo; echo "# Stderr is:"; cat "$stderr") else output= fi @@ -474,7 +476,7 @@ test_external_without_stderr () { # The commands test the existence or non-existence of $1. $2 can be # given to provide a more precise diagnosis. test_path_is_file () { - if ! [ -f "$1" ] + if ! test -f "$1" then echo "File $1 doesn't exist. $*" false @@ -482,7 +484,7 @@ test_path_is_file () { } test_path_is_dir () { - if ! [ -d "$1" ] + if ! test -d "$1" then echo "Directory $1 doesn't exist. $*" false @@ -490,11 +492,12 @@ test_path_is_dir () { } test_path_is_missing () { - if [ -e "$1" ] + if test -e "$1" then echo "Path exists:" ls -ld "$1" - if [ $# -ge 1 ]; then + if test $# -ge 1 + then echo "$*" fi false @@ -646,9 +649,12 @@ test_cmp_rev () { # similar to GNU seq(1), but the latter might not be available # everywhere (and does not do letters). It may be used like: # -# for i in `test_seq 100`; do -# for j in `test_seq 10 20`; do -# for k in `test_seq a z`; do +# for i in $(test_seq 100) +# do +# for j in $(test_seq 10 20) +# do +# for k in $(test_seq a z) +# do # echo $i-$j-$k # done # done From 9c66cd3bd0a70b2cf56589a4df2cf63814270635 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Fri, 10 Oct 2014 01:19:47 -0700 Subject: [PATCH 3/6] mergetool: use more conservative temporary filenames Avoid filenames with multiple dots so that overly-picky tools do not misinterpret their extension. Previously, foo/bar.ext in the worktree would result in e.g. ./foo/bar.ext.BASE.1234.ext This can be improved by having only a single .ext and using underscore instead of dot so that the extension cannot be misinterpreted. The resulting path becomes: ./foo/bar_BASE_1234.ext Suggested-by: Sergio Ferrero Helped-by: Junio C Hamano Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano --- git-mergetool.sh | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/git-mergetool.sh b/git-mergetool.sh index 332528ff45..0ff6566a0e 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -228,11 +228,17 @@ merge_file () { return 1 fi - ext="$$$(expr "$MERGED" : '.*\(\.[^/]*\)$')" - BACKUP="./$MERGED.BACKUP.$ext" - LOCAL="./$MERGED.LOCAL.$ext" - REMOTE="./$MERGED.REMOTE.$ext" - BASE="./$MERGED.BASE.$ext" + if BASE=$(expr "$MERGED" : '\(.*\)\.[^/]*$') + then + ext=$(expr "$MERGED" : '.*\(\.[^/]*\)$') + else + BASE=$MERGED + ext= + fi + BACKUP="./${BASE}_BACKUP_$$$ext" + LOCAL="./${BASE}_LOCAL_$$$ext" + REMOTE="./${BASE}_REMOTE_$$$ext" + BASE="./${BASE}_BASE_$$$ext" base_mode=$(git ls-files -u -- "$MERGED" | awk '{if ($3==1) print $1;}') local_mode=$(git ls-files -u -- "$MERGED" | awk '{if ($3==2) print $1;}') From 1c7e2d23e4f22f1599570d9c5d0cc2f4156b5b74 Mon Sep 17 00:00:00 2001 From: David Aguilar Date: Sat, 11 Oct 2014 01:39:36 -0700 Subject: [PATCH 4/6] git-sh-setup: move GIT_DIR initialization into a function Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano --- git-sh-setup.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/git-sh-setup.sh b/git-sh-setup.sh index 5f28b32dc7..3eb1b67838 100644 --- a/git-sh-setup.sh +++ b/git-sh-setup.sh @@ -330,8 +330,7 @@ esac # Make sure we are in a valid repository of a vintage we understand, # if we require to be in a git repository. -if test -z "$NONGIT_OK" -then +git_dir_init () { GIT_DIR=$(git rev-parse --git-dir) || exit if [ -z "$SUBDIRECTORY_OK" ] then @@ -346,6 +345,11 @@ then exit 1 } : ${GIT_OBJECT_DIRECTORY="$GIT_DIR/objects"} +} + +if test -z "$NONGIT_OK" +then + git_dir_init fi peel_committish () { From 7bfb7c357cd33a9f3a72d65b0df96e054d2a9f06 Mon Sep 17 00:00:00 2001 From: Charles Bailey Date: Sat, 11 Oct 2014 01:39:37 -0700 Subject: [PATCH 5/6] mergetool: don't require a work tree for --tool-help Signed-off-by: Charles Bailey Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano --- git-mergetool.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/git-mergetool.sh b/git-mergetool.sh index 0ff6566a0e..8098d2dc07 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -10,11 +10,11 @@ USAGE='[--tool=tool] [--tool-help] [-y|--no-prompt|--prompt] [file to merge] ...' SUBDIRECTORY_OK=Yes +NONGIT_OK=Yes OPTIONS_SPEC= TOOL_MODE=merge . git-sh-setup . git-mergetool--lib -require_work_tree # Returns true if the mode reflects a symlink is_symlink () { @@ -377,6 +377,9 @@ prompt_after_failed_merge () { done } +git_dir_init +require_work_tree + if test -z "$merge_tool" then merge_tool=$(get_merge_tool "$merge_tool") || exit From 4fb4b02d98310f4f859f7d52f57f36d49198be5c Mon Sep 17 00:00:00 2001 From: Charles Bailey Date: Sat, 11 Oct 2014 01:39:38 -0700 Subject: [PATCH 6/6] difftool: don't assume that default sh is sane git-difftool used to create a command list script containing $( ... ) and explicitly calls "sh -c" with this list. Instead, allow mergetool --tool-help to take a mode parameter and call mergetool directly to invoke the show_tool_help function. This mode parameter is intented for use solely by difftool. Signed-off-by: Charles Bailey Helped-by: John Keeping Signed-off-by: David Aguilar Signed-off-by: Junio C Hamano --- git-difftool.perl | 6 +----- git-mergetool.sh | 4 ++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/git-difftool.perl b/git-difftool.perl index 18ca61e8d0..598fcc23b9 100755 --- a/git-difftool.perl +++ b/git-difftool.perl @@ -47,13 +47,9 @@ sub find_worktree sub print_tool_help { - my $cmd = 'TOOL_MODE=diff'; - $cmd .= ' && . "$(git --exec-path)/git-mergetool--lib"'; - $cmd .= ' && show_tool_help'; - # See the comment at the bottom of file_diff() for the reason behind # using system() followed by exit() instead of exec(). - my $rc = system('sh', '-c', $cmd); + my $rc = system(qw(git mergetool --tool-help=diff)); exit($rc | ($rc >> 8)); } diff --git a/git-mergetool.sh b/git-mergetool.sh index 8098d2dc07..821253e368 100755 --- a/git-mergetool.sh +++ b/git-mergetool.sh @@ -326,6 +326,10 @@ prompt=$(git config --bool mergetool.prompt || echo true) while test $# != 0 do case "$1" in + --tool-help=*) + TOOL_MODE=${1#--tool-help=} + show_tool_help + ;; --tool-help) show_tool_help ;;