Merge branch 'js/difftool-no-index'
"git difftool" can now run outside a repository. * js/difftool-no-index: difftool: allow running outside Git worktrees with --no-index parse-options: make OPT_ARGUMENT() more useful difftool: remove obsolete (and misleading) comment
This commit is contained in:
commit
b72e90712e
@ -198,8 +198,10 @@ There are some macros to easily define options:
|
||||
The filename will be prefixed by passing the filename along with
|
||||
the prefix argument of `parse_options()` to `prefix_filename()`.
|
||||
|
||||
`OPT_ARGUMENT(long, description)`::
|
||||
`OPT_ARGUMENT(long, &int_var, description)`::
|
||||
Introduce a long-option argument that will be kept in `argv[]`.
|
||||
If this option was seen, `int_var` will be set to one (except
|
||||
if a `NULL` pointer was passed).
|
||||
|
||||
`OPT_NUMBER_CALLBACK(&var, description, func_ptr)`::
|
||||
Recognize numerical options like -123 and feed the integer as
|
||||
|
@ -690,7 +690,7 @@ static int run_file_diff(int prompt, const char *prefix,
|
||||
int cmd_difftool(int argc, const char **argv, const char *prefix)
|
||||
{
|
||||
int use_gui_tool = 0, dir_diff = 0, prompt = -1, symlinks = 0,
|
||||
tool_help = 0;
|
||||
tool_help = 0, no_index = 0;
|
||||
static char *difftool_cmd = NULL, *extcmd = NULL;
|
||||
struct option builtin_difftool_options[] = {
|
||||
OPT_BOOL('g', "gui", &use_gui_tool,
|
||||
@ -714,6 +714,7 @@ int cmd_difftool(int argc, const char **argv, const char *prefix)
|
||||
"tool returns a non - zero exit code")),
|
||||
OPT_STRING('x', "extcmd", &extcmd, N_("command"),
|
||||
N_("specify a custom command for viewing diffs")),
|
||||
OPT_ARGUMENT("no-index", &no_index, N_("passed to `diff`")),
|
||||
OPT_END()
|
||||
};
|
||||
|
||||
@ -727,9 +728,14 @@ 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 (!no_index && !startup_info->have_repository)
|
||||
die(_("difftool requires worktree or --no-index"));
|
||||
|
||||
if (!no_index){
|
||||
setup_work_tree();
|
||||
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);
|
||||
|
2
git.c
2
git.c
@ -498,7 +498,7 @@ static struct cmd_struct commands[] = {
|
||||
{ "diff-files", cmd_diff_files, RUN_SETUP | NEED_WORK_TREE | NO_PARSEOPT },
|
||||
{ "diff-index", cmd_diff_index, RUN_SETUP | NO_PARSEOPT },
|
||||
{ "diff-tree", cmd_diff_tree, RUN_SETUP | NO_PARSEOPT },
|
||||
{ "difftool", cmd_difftool, RUN_SETUP | NEED_WORK_TREE },
|
||||
{ "difftool", cmd_difftool, RUN_SETUP_GENTLY },
|
||||
{ "fast-export", cmd_fast_export, RUN_SETUP },
|
||||
{ "fetch", cmd_fetch, RUN_SETUP },
|
||||
{ "fetch-pack", cmd_fetch_pack, RUN_SETUP | NO_PARSEOPT },
|
||||
|
@ -288,6 +288,8 @@ again:
|
||||
optname(options, flags));
|
||||
if (*rest)
|
||||
continue;
|
||||
if (options->value)
|
||||
*(int *)options->value = options->defval;
|
||||
p->out[p->cpidx++] = arg - 2;
|
||||
return PARSE_OPT_DONE;
|
||||
}
|
||||
|
@ -140,8 +140,8 @@ struct option {
|
||||
#define OPT_INTEGER_F(s, l, v, h, f) { OPTION_INTEGER, (s), (l), (v), N_("n"), (h), (f) }
|
||||
|
||||
#define OPT_END() { OPTION_END }
|
||||
#define OPT_ARGUMENT(l, h) { OPTION_ARGUMENT, 0, (l), NULL, NULL, \
|
||||
(h), PARSE_OPT_NOARG}
|
||||
#define OPT_ARGUMENT(l, v, h) { OPTION_ARGUMENT, 0, (l), (v), NULL, \
|
||||
(h), PARSE_OPT_NOARG, NULL, 1 }
|
||||
#define OPT_GROUP(h) { OPTION_GROUP, 0, NULL, NULL, NULL, (h) }
|
||||
#define OPT_BIT(s, l, v, h, b) OPT_BIT_F(s, l, v, h, b, 0)
|
||||
#define OPT_BITOP(s, l, v, h, set, clear) { OPTION_BITOP, (s), (l), (v), NULL, (h), \
|
||||
|
@ -132,7 +132,7 @@ int cmd__parse_options(int argc, const char **argv)
|
||||
OPT_NOOP_NOARG(0, "obsolete"),
|
||||
OPT_STRING_LIST(0, "list", &list, "str", "add str to list"),
|
||||
OPT_GROUP("Magic arguments"),
|
||||
OPT_ARGUMENT("quux", "means --quux"),
|
||||
OPT_ARGUMENT("quux", NULL, "means --quux"),
|
||||
OPT_NUMBER_CALLBACK(&integer, "set integer to NUM",
|
||||
number_callback),
|
||||
{ OPTION_COUNTUP, '+', NULL, &boolean, NULL, "same as -b",
|
||||
|
@ -705,4 +705,14 @@ test_expect_success SYMLINKS 'difftool --dir-diff handles modified symlinks' '
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_expect_success 'outside worktree' '
|
||||
echo 1 >1 &&
|
||||
echo 2 >2 &&
|
||||
test_expect_code 1 nongit git \
|
||||
-c diff.tool=echo -c difftool.echo.cmd="echo \$LOCAL \$REMOTE" \
|
||||
difftool --no-prompt --no-index ../1 ../2 >actual &&
|
||||
echo "../1 ../2" >expect &&
|
||||
test_cmp expect actual
|
||||
'
|
||||
|
||||
test_done
|
||||
|
Loading…
Reference in New Issue
Block a user