Merge branch 'js/difftool-builtin'
authorJunio C Hamano <gitster@pobox.com>
Fri, 10 Feb 2017 20:52:25 +0000 (12:52 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 10 Feb 2017 20:52:25 +0000 (12:52 -0800)
A few hot-fixes to C-rewrite of "git difftool".

* js/difftool-builtin:
t7800: simplify basic usage test
difftool: fix bug when printing usage

builtin/difftool.c
t/t7800-difftool.sh
index b5e85ab0794fc08941cfdb87c4a8c2e62447e199..d13350ce832cd8c0064c8a5b2d3c9be64f876b8d 100644 (file)
@@ -647,10 +647,6 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
                OPT_END()
        };
 
-       /* NEEDSWORK: once we no longer spawn anything, remove this */
-       setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1);
-       setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1);
-
        git_config(difftool_config, NULL);
        symlinks = has_symlinks;
 
@@ -661,6 +657,10 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
        if (tool_help)
                return print_tool_help();
 
+       /* NEEDSWORK: once we no longer spawn anything, remove this */
+       setenv(GIT_DIR_ENVIRONMENT, absolute_path(get_git_dir()), 1);
+       setenv(GIT_WORK_TREE_ENVIRONMENT, absolute_path(get_git_work_tree()), 1);
+
        if (use_gui_tool && diff_gui_tool && *diff_gui_tool)
                setenv("GIT_DIFF_TOOL", diff_gui_tool, 1);
        else if (difftool_cmd) {
index aa0ef02597f051b17747df4c9cf3d4b50563ed69..97bae54d8343dc2cdfb0ea259b0f231429468c78 100755 (executable)
@@ -23,6 +23,18 @@ prompt_given ()
        test "$prompt" = "Launch 'test-tool' [Y/n]? branch"
 }
 
+test_expect_success 'basic usage requires no repo' '
+       test_expect_code 129 git difftool -h >output &&
+       grep ^usage: output &&
+       # create a ceiling directory to prevent Git from finding a repo
+       mkdir -p not/repo &&
+       test_when_finished rm -r not &&
+       test_expect_code 129 \
+       env GIT_CEILING_DIRECTORIES="$(pwd)/not" \
+       git -C not/repo difftool -h >output &&
+       grep ^usage: output
+'
+
 # Create a file on master and change it on branch
 test_expect_success 'setup' '
        echo master >file &&