3 #include "parse-options.h"
7 static const char * const git_bisect_helper_usage[] = {
8 N_("git bisect--helper --next-all [--no-checkout]"),
9 N_("git bisect--helper --check-term-format <term> <orig_term>"),
14 * Check whether the string `term` belongs to the set of strings
15 * included in the variable arguments.
18 static int one_of(const char *term, ...)
24 va_start(matches, term);
25 while (!res && (match = va_arg(matches, const char *)))
26 res = !strcmp(term, match);
32 static int check_term_format(const char *term, const char *orig_term)
35 char *new_term = xstrfmt("refs/bisect/%s", term);
37 res = check_refname_format(new_term, 0);
41 return error(_("'%s' is not a valid term"), term);
43 if (one_of(term, "help", "start", "skip", "next", "reset",
44 "visualize", "replay", "log", "run", "terms", NULL))
45 return error(_("can't use the builtin command '%s' as a term"), term);
48 * In theory, nothing prevents swapping completely good and bad,
49 * but this situation could be confusing and hasn't been tested
50 * enough. Forbid it for now.
53 if ((strcmp(orig_term, "bad") && one_of(term, "bad", "new", NULL)) ||
54 (strcmp(orig_term, "good") && one_of(term, "good", "old", NULL)))
55 return error(_("can't change the meaning of the term '%s'"), term);
60 int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
67 struct option options[] = {
68 OPT_CMDMODE(0, "next-all", &cmdmode,
69 N_("perform 'git bisect next'"), NEXT_ALL),
70 OPT_CMDMODE(0, "check-term-format", &cmdmode,
71 N_("check format of the term"), CHECK_TERM_FMT),
72 OPT_BOOL(0, "no-checkout", &no_checkout,
73 N_("update BISECT_HEAD instead of checking out the current commit")),
77 argc = parse_options(argc, argv, prefix, options,
78 git_bisect_helper_usage, 0);
81 usage_with_options(git_bisect_helper_usage, options);
85 return bisect_next_all(prefix, no_checkout);
88 return error(_("--check-term-format requires two arguments"));
89 return check_term_format(argv[0], argv[1]);
91 return error("BUG: unknown subcommand '%d'", cmdmode);