提交 d81345ce 编写于 作者: D David Aguilar 提交者: Junio C Hamano

difftool: fix bug when printing usage

"git difftool -h" reports an error:

	fatal: BUG: setup_git_env called without repository

Defer repository setup so that the help option processing happens before
the repository is initialized.

Add tests to ensure that the basic usage works inside and outside of a
repository.
Signed-off-by: NDavid Aguilar <davvid@gmail.com>
Acked-by: NJohannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: NJunio C Hamano <gitster@pobox.com>
上级 94d3997e
......@@ -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) {
......
......@@ -23,6 +23,19 @@ prompt_given ()
test "$prompt" = "Launch 'test-tool' [Y/n]? branch"
}
test_expect_success 'basic usage requires no repo' '
lines=$(git difftool -h | grep ^usage: | wc -l) &&
test "$lines" -eq 1 &&
# create a ceiling directory to prevent Git from finding a repo
mkdir -p not/repo &&
ceiling="$PWD/not" &&
lines=$(cd not/repo &&
GIT_CEILING_DIRECTORIES="$ceiling" git difftool -h |
grep ^usage: | wc -l) &&
test "$lines" -eq 1 &&
rmdir -p not/repo
'
# Create a file on master and change it on branch
test_expect_success 'setup' '
echo master >file &&
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册