Merge branch 'da/mergetool-tool-help'
authorJunio C Hamano <gitster@pobox.com>
Tue, 21 Oct 2014 20:28:37 +0000 (13:28 -0700)
committerJunio C Hamano <gitster@pobox.com>
Tue, 21 Oct 2014 20:28:37 +0000 (13:28 -0700)
Allow "git mergetool --help" to run outside a Git repository.

* da/mergetool-tool-help:
difftool: don't assume that default sh is sane
mergetool: don't require a work tree for --tool-help
git-sh-setup: move GIT_DIR initialization into a function
mergetool: use more conservative temporary filenames
test-lib-functions: adjust style to match CodingGuidelines
t7610-mergetool: prefer test_config over git config

git-difftool.perl
git-mergetool.sh
git-sh-setup.sh
t/t7610-mergetool.sh
index 18ca61e8d0493bde9c21ed337043bc72fa5c73a7..598fcc23b930832a8cd3cfcff0c0d0c84ecd32bc 100755 (executable)
@@ -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));
 }
 
index 96a61ba6f470d7634552a42547de57f63fae8d81..ec644d542d9754fa09ac7fb1b0f1f932a9bedbed 100755 (executable)
 
 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 () {
@@ -327,6 +327,10 @@ guessed_merge_tool=false
 while test $# != 0
 do
        case "$1" in
+       --tool-help=*)
+               TOOL_MODE=${1#--tool-help=}
+               show_tool_help
+               ;;
        --tool-help)
                show_tool_help
                ;;
@@ -378,6 +382,9 @@ prompt_after_failed_merge () {
        done
 }
 
+git_dir_init
+require_work_tree
+
 if test -z "$merge_tool"
 then
        # Check if a merge tool has been configured
index 9447980330ce7892757f9b11fa45cfeb3e6fcb34..d968760139b0e7b9219a1602a2e646a3ed398136 100644 (file)
@@ -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 () {
index 2834ded84d83d308a65e5e6a51d2e4703b213a5d..3502ec9fe567af2a029c0c0d6faa3b189be8717f 100755 (executable)
@@ -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 &&
@@ -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 &&