3
#include "parse-options.h"
4
#include "bisect.h"
5
#include "refs.h"
6
+#include "dir.h"
7
+#include "argv-array.h"
8
+#include "run-command.h"
9
10
static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
11
static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
12
static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK")
13
+static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
14
+static GIT_PATH_FUNC(git_path_bisect_head, "BISECT_HEAD")
15
16
static const char * const git_bisect_helper_usage[] = {
17
N_("git bisect--helper --next-all [--no-checkout]"),
18
N_("git bisect--helper --write-terms <bad_term> <good_term>"),
19
N_("git bisect--helper --bisect-clean-state"),
20
+ N_("git bisect--helper --bisect-reset [<commit>]"),
21
NULL
22
};
23
112
}
113
}
114
115
+static int bisect_reset(const char *commit)
116
+{
117
+ struct strbuf branch = STRBUF_INIT;
118
+
119
+ if (!commit) {
120
+ if (strbuf_read_file(&branch, git_path_bisect_start(), 0) < 1) {
121
+ printf(_("We are not bisecting.\n"));
122
+ return 0;
123
+ }
124
+ strbuf_rtrim(&branch);
125
+ } else {
126
+ struct object_id oid;
127
+
128
+ if (get_oid_commit(commit, &oid))
129
+ return error(_("'%s' is not a valid commit"), commit);
130
+ strbuf_addstr(&branch, commit);
131
+ }
132
+
133
+ if (!file_exists(git_path_bisect_head())) {
134
+ struct argv_array argv = ARGV_ARRAY_INIT;
135
+
136
+ argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL);
137
+ if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) {
138
+ strbuf_release(&branch);
139
+ argv_array_clear(&argv);
140
+ return error(_("could not check out original"
141
+ " HEAD '%s'. Try 'git bisect"
142
+ "reset <commit>'."), branch.buf);
143
+ }
144
+ argv_array_clear(&argv);
145
+ }
146
+
147
+ strbuf_release(&branch);
148
+ return bisect_clean_state();
149
+}
150
+
151
int cmd_bisect__helper(int argc, const char **argv, const char *prefix)
152
{
153
enum {
154
NEXT_ALL = 1,
155
WRITE_TERMS,
156
BISECT_CLEAN_STATE,
115
- CHECK_EXPECTED_REVS
157
+ CHECK_EXPECTED_REVS,
158
+ BISECT_RESET
159
} cmdmode = 0;
160
int no_checkout = 0;
161
struct option options[] = {
167
N_("cleanup the bisection state"), BISECT_CLEAN_STATE),
168
OPT_CMDMODE(0, "check-expected-revs", &cmdmode,
169
N_("check for expected revs"), CHECK_EXPECTED_REVS),
170
+ OPT_CMDMODE(0, "bisect-reset", &cmdmode,
171
+ N_("reset the bisection state"), BISECT_RESET),
172
OPT_BOOL(0, "no-checkout", &no_checkout,
173
N_("update BISECT_HEAD instead of checking out the current commit")),
174
OPT_END()
194
case CHECK_EXPECTED_REVS:
195
check_expected_revs(argv, argc);
196
return 0;
197
+ case BISECT_RESET:
198
+ if (argc > 1)
199
+ return error(_("--bisect-reset requires either no argument or a commit"));
200
+ return !!bisect_reset(argc ? argv[0] : NULL);
201
default:
202
return error("BUG: unknown subcommand '%d'", cmdmode);
203
}