mirror of
https://github.com/git/git
synced 2024-08-27 11:39:22 +00:00
Merge branch 'dd/bisect-helper-subcommand'
Fix a regression in the bisect-helper which mistakenly treats arguments to the command given to 'git bisect run' as arguments to the helper. * dd/bisect-helper-subcommand: bisect--helper: parse subcommand with OPT_SUBCOMMAND bisect--helper: move all subcommands into their own functions bisect--helper: remove unused options
This commit is contained in:
commit
e3d40fb240
|
@ -1279,115 +1279,144 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int cmd_bisect__reset(int argc, const char **argv, const char *prefix UNUSED)
|
||||||
|
{
|
||||||
|
if (argc > 1)
|
||||||
|
return error(_("--bisect-reset requires either no argument or a commit"));
|
||||||
|
return bisect_reset(argc ? argv[0] : NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_bisect__terms(int argc, const char **argv, const char *prefix UNUSED)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
struct bisect_terms terms = { 0 };
|
||||||
|
|
||||||
|
if (argc > 1)
|
||||||
|
return error(_("--bisect-terms requires 0 or 1 argument"));
|
||||||
|
res = bisect_terms(&terms, argc == 1 ? argv[0] : NULL);
|
||||||
|
free_terms(&terms);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNUSED)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
struct bisect_terms terms = { 0 };
|
||||||
|
|
||||||
|
set_terms(&terms, "bad", "good");
|
||||||
|
res = bisect_start(&terms, argv, argc);
|
||||||
|
free_terms(&terms);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_bisect__next(int argc, const char **argv UNUSED, const char *prefix)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
struct bisect_terms terms = { 0 };
|
||||||
|
|
||||||
|
if (argc)
|
||||||
|
return error(_("--bisect-next requires 0 arguments"));
|
||||||
|
get_terms(&terms);
|
||||||
|
res = bisect_next(&terms, prefix);
|
||||||
|
free_terms(&terms);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_bisect__state(int argc, const char **argv, const char *prefix UNUSED)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
struct bisect_terms terms = { 0 };
|
||||||
|
|
||||||
|
set_terms(&terms, "bad", "good");
|
||||||
|
get_terms(&terms);
|
||||||
|
res = bisect_state(&terms, argv, argc);
|
||||||
|
free_terms(&terms);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_bisect__log(int argc, const char **argv UNUSED, const char *prefix UNUSED)
|
||||||
|
{
|
||||||
|
if (argc)
|
||||||
|
return error(_("--bisect-log requires 0 arguments"));
|
||||||
|
return bisect_log();
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_bisect__replay(int argc, const char **argv, const char *prefix UNUSED)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
struct bisect_terms terms = { 0 };
|
||||||
|
|
||||||
|
if (argc != 1)
|
||||||
|
return error(_("no logfile given"));
|
||||||
|
set_terms(&terms, "bad", "good");
|
||||||
|
res = bisect_replay(&terms, argv[0]);
|
||||||
|
free_terms(&terms);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUSED)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
struct bisect_terms terms = { 0 };
|
||||||
|
|
||||||
|
set_terms(&terms, "bad", "good");
|
||||||
|
get_terms(&terms);
|
||||||
|
res = bisect_skip(&terms, argv, argc);
|
||||||
|
free_terms(&terms);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix UNUSED)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
struct bisect_terms terms = { 0 };
|
||||||
|
|
||||||
|
get_terms(&terms);
|
||||||
|
res = bisect_visualize(&terms, argv, argc);
|
||||||
|
free_terms(&terms);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSED)
|
||||||
|
{
|
||||||
|
int res;
|
||||||
|
struct bisect_terms terms = { 0 };
|
||||||
|
|
||||||
|
if (!argc)
|
||||||
|
return error(_("bisect run failed: no command provided."));
|
||||||
|
get_terms(&terms);
|
||||||
|
res = bisect_run(&terms, argv, argc);
|
||||||
|
free_terms(&terms);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
|
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
|
||||||
{
|
{
|
||||||
enum {
|
int res = 0;
|
||||||
BISECT_RESET = 1,
|
parse_opt_subcommand_fn *fn = NULL;
|
||||||
BISECT_NEXT_CHECK,
|
|
||||||
BISECT_TERMS,
|
|
||||||
BISECT_START,
|
|
||||||
BISECT_AUTOSTART,
|
|
||||||
BISECT_NEXT,
|
|
||||||
BISECT_STATE,
|
|
||||||
BISECT_LOG,
|
|
||||||
BISECT_REPLAY,
|
|
||||||
BISECT_SKIP,
|
|
||||||
BISECT_VISUALIZE,
|
|
||||||
BISECT_RUN,
|
|
||||||
} cmdmode = 0;
|
|
||||||
int res = 0, nolog = 0;
|
|
||||||
struct option options[] = {
|
struct option options[] = {
|
||||||
OPT_CMDMODE(0, "bisect-reset", &cmdmode,
|
OPT_SUBCOMMAND("reset", &fn, cmd_bisect__reset),
|
||||||
N_("reset the bisection state"), BISECT_RESET),
|
OPT_SUBCOMMAND("terms", &fn, cmd_bisect__terms),
|
||||||
OPT_CMDMODE(0, "bisect-next-check", &cmdmode,
|
OPT_SUBCOMMAND("start", &fn, cmd_bisect__start),
|
||||||
N_("check whether bad or good terms exist"), BISECT_NEXT_CHECK),
|
OPT_SUBCOMMAND("next", &fn, cmd_bisect__next),
|
||||||
OPT_CMDMODE(0, "bisect-terms", &cmdmode,
|
OPT_SUBCOMMAND("state", &fn, cmd_bisect__state),
|
||||||
N_("print out the bisect terms"), BISECT_TERMS),
|
OPT_SUBCOMMAND("log", &fn, cmd_bisect__log),
|
||||||
OPT_CMDMODE(0, "bisect-start", &cmdmode,
|
OPT_SUBCOMMAND("replay", &fn, cmd_bisect__replay),
|
||||||
N_("start the bisect session"), BISECT_START),
|
OPT_SUBCOMMAND("skip", &fn, cmd_bisect__skip),
|
||||||
OPT_CMDMODE(0, "bisect-next", &cmdmode,
|
OPT_SUBCOMMAND("visualize", &fn, cmd_bisect__visualize),
|
||||||
N_("find the next bisection commit"), BISECT_NEXT),
|
OPT_SUBCOMMAND("view", &fn, cmd_bisect__visualize),
|
||||||
OPT_CMDMODE(0, "bisect-state", &cmdmode,
|
OPT_SUBCOMMAND("run", &fn, cmd_bisect__run),
|
||||||
N_("mark the state of ref (or refs)"), BISECT_STATE),
|
|
||||||
OPT_CMDMODE(0, "bisect-log", &cmdmode,
|
|
||||||
N_("list the bisection steps so far"), BISECT_LOG),
|
|
||||||
OPT_CMDMODE(0, "bisect-replay", &cmdmode,
|
|
||||||
N_("replay the bisection process from the given file"), BISECT_REPLAY),
|
|
||||||
OPT_CMDMODE(0, "bisect-skip", &cmdmode,
|
|
||||||
N_("skip some commits for checkout"), BISECT_SKIP),
|
|
||||||
OPT_CMDMODE(0, "bisect-visualize", &cmdmode,
|
|
||||||
N_("visualize the bisection"), BISECT_VISUALIZE),
|
|
||||||
OPT_CMDMODE(0, "bisect-run", &cmdmode,
|
|
||||||
N_("use <cmd>... to automatically bisect"), BISECT_RUN),
|
|
||||||
OPT_BOOL(0, "no-log", &nolog,
|
|
||||||
N_("no log for BISECT_WRITE")),
|
|
||||||
OPT_END()
|
OPT_END()
|
||||||
};
|
};
|
||||||
struct bisect_terms terms = { .term_good = NULL, .term_bad = NULL };
|
|
||||||
|
|
||||||
argc = parse_options(argc, argv, prefix, options,
|
argc = parse_options(argc, argv, prefix, options,
|
||||||
git_bisect_helper_usage,
|
git_bisect_helper_usage, 0);
|
||||||
PARSE_OPT_KEEP_DASHDASH | PARSE_OPT_KEEP_UNKNOWN_OPT);
|
|
||||||
|
|
||||||
if (!cmdmode)
|
if (!fn)
|
||||||
usage_with_options(git_bisect_helper_usage, options);
|
usage_with_options(git_bisect_helper_usage, options);
|
||||||
|
argc--;
|
||||||
|
argv++;
|
||||||
|
|
||||||
switch (cmdmode) {
|
res = fn(argc, argv, prefix);
|
||||||
case BISECT_RESET:
|
|
||||||
if (argc > 1)
|
|
||||||
return error(_("--bisect-reset requires either no argument or a commit"));
|
|
||||||
res = bisect_reset(argc ? argv[0] : NULL);
|
|
||||||
break;
|
|
||||||
case BISECT_TERMS:
|
|
||||||
if (argc > 1)
|
|
||||||
return error(_("--bisect-terms requires 0 or 1 argument"));
|
|
||||||
res = bisect_terms(&terms, argc == 1 ? argv[0] : NULL);
|
|
||||||
break;
|
|
||||||
case BISECT_START:
|
|
||||||
set_terms(&terms, "bad", "good");
|
|
||||||
res = bisect_start(&terms, argv, argc);
|
|
||||||
break;
|
|
||||||
case BISECT_NEXT:
|
|
||||||
if (argc)
|
|
||||||
return error(_("--bisect-next requires 0 arguments"));
|
|
||||||
get_terms(&terms);
|
|
||||||
res = bisect_next(&terms, prefix);
|
|
||||||
break;
|
|
||||||
case BISECT_STATE:
|
|
||||||
set_terms(&terms, "bad", "good");
|
|
||||||
get_terms(&terms);
|
|
||||||
res = bisect_state(&terms, argv, argc);
|
|
||||||
break;
|
|
||||||
case BISECT_LOG:
|
|
||||||
if (argc)
|
|
||||||
return error(_("--bisect-log requires 0 arguments"));
|
|
||||||
res = bisect_log();
|
|
||||||
break;
|
|
||||||
case BISECT_REPLAY:
|
|
||||||
if (argc != 1)
|
|
||||||
return error(_("no logfile given"));
|
|
||||||
set_terms(&terms, "bad", "good");
|
|
||||||
res = bisect_replay(&terms, argv[0]);
|
|
||||||
break;
|
|
||||||
case BISECT_SKIP:
|
|
||||||
set_terms(&terms, "bad", "good");
|
|
||||||
get_terms(&terms);
|
|
||||||
res = bisect_skip(&terms, argv, argc);
|
|
||||||
break;
|
|
||||||
case BISECT_VISUALIZE:
|
|
||||||
get_terms(&terms);
|
|
||||||
res = bisect_visualize(&terms, argv, argc);
|
|
||||||
break;
|
|
||||||
case BISECT_RUN:
|
|
||||||
if (!argc)
|
|
||||||
return error(_("bisect run failed: no command provided."));
|
|
||||||
get_terms(&terms);
|
|
||||||
res = bisect_run(&terms, argv, argc);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
BUG("unknown subcommand %d", cmdmode);
|
|
||||||
}
|
|
||||||
free_terms(&terms);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Handle early success
|
* Handle early success
|
||||||
|
|
|
@ -57,28 +57,11 @@ case "$#" in
|
||||||
case "$cmd" in
|
case "$cmd" in
|
||||||
help)
|
help)
|
||||||
git bisect -h ;;
|
git bisect -h ;;
|
||||||
start)
|
|
||||||
git bisect--helper --bisect-start "$@" ;;
|
|
||||||
bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD")
|
bad|good|new|old|"$TERM_BAD"|"$TERM_GOOD")
|
||||||
git bisect--helper --bisect-state "$cmd" "$@" ;;
|
git bisect--helper state "$cmd" "$@" ;;
|
||||||
skip)
|
|
||||||
git bisect--helper --bisect-skip "$@" || exit;;
|
|
||||||
next)
|
|
||||||
# Not sure we want "next" at the UI level anymore.
|
|
||||||
git bisect--helper --bisect-next "$@" || exit ;;
|
|
||||||
visualize|view)
|
|
||||||
git bisect--helper --bisect-visualize "$@" || exit;;
|
|
||||||
reset)
|
|
||||||
git bisect--helper --bisect-reset "$@" ;;
|
|
||||||
replay)
|
|
||||||
git bisect--helper --bisect-replay "$@" || exit;;
|
|
||||||
log)
|
log)
|
||||||
git bisect--helper --bisect-log || exit ;;
|
git bisect--helper log || exit ;;
|
||||||
run)
|
|
||||||
git bisect--helper --bisect-run "$@" || exit;;
|
|
||||||
terms)
|
|
||||||
git bisect--helper --bisect-terms "$@" || exit;;
|
|
||||||
*)
|
*)
|
||||||
usage ;;
|
git bisect--helper "$cmd" "$@" ;;
|
||||||
esac
|
esac
|
||||||
esac
|
esac
|
||||||
|
|
|
@ -266,6 +266,16 @@ test_expect_success '"git bisect run" simple case' '
|
||||||
git bisect reset
|
git bisect reset
|
||||||
'
|
'
|
||||||
|
|
||||||
|
# We want to make sure no arguments has been eaten
|
||||||
|
test_expect_success '"git bisect run" simple case' '
|
||||||
|
git bisect start &&
|
||||||
|
git bisect good $HASH1 &&
|
||||||
|
git bisect bad $HASH4 &&
|
||||||
|
git bisect run printf "%s %s\n" reset --bisect-skip >my_bisect_log.txt &&
|
||||||
|
grep -e "reset --bisect-skip" my_bisect_log.txt &&
|
||||||
|
git bisect reset
|
||||||
|
'
|
||||||
|
|
||||||
# We want to automatically find the commit that
|
# We want to automatically find the commit that
|
||||||
# added "Ciao" into hello.
|
# added "Ciao" into hello.
|
||||||
test_expect_success '"git bisect run" with more complex "git bisect start"' '
|
test_expect_success '"git bisect run" with more complex "git bisect start"' '
|
||||||
|
|
Loading…
Reference in a new issue