Skip to content

Commit 30b4e5c

Browse files
committed
Merge branch 'ab/bisect-cleanup'
Code clean-up. * ab/bisect-cleanup: bisect: no longer try to clean up left-over `.git/head-name` files bisect: remove Cogito-related code bisect run: fix the error message bisect: verify that a bogus option won't try to start a bisection bisect--helper: make the order consistently `argc, argv` bisect--helper: simplify exit code computation
2 parents 38a49ab + de54b5f commit 30b4e5c

File tree

3 files changed

+40
-36
lines changed

3 files changed

+40
-36
lines changed

bisect.c

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,6 @@ static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
472472
static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
473473
static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
474474
static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT")
475-
static GIT_PATH_FUNC(git_path_head_name, "head-name")
476475

477476
static void read_bisect_paths(struct strvec *array)
478477
{
@@ -1188,8 +1187,6 @@ int bisect_clean_state(void)
11881187
unlink_or_warn(git_path_bisect_run());
11891188
unlink_or_warn(git_path_bisect_terms());
11901189
unlink_or_warn(git_path_bisect_first_parent());
1191-
/* Cleanup head-name if it got left by an old version of git-bisect */
1192-
unlink_or_warn(git_path_head_name());
11931190
/*
11941191
* Cleanup BISECT_START last to support the --no-checkout option
11951192
* introduced in the commit 4796e823a.

builtin/bisect.c

Lines changed: 20 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ static GIT_PATH_FUNC(git_path_bisect_expected_rev, "BISECT_EXPECTED_REV")
1515
static GIT_PATH_FUNC(git_path_bisect_ancestors_ok, "BISECT_ANCESTORS_OK")
1616
static GIT_PATH_FUNC(git_path_bisect_start, "BISECT_START")
1717
static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
18-
static GIT_PATH_FUNC(git_path_head_name, "head-name")
1918
static GIT_PATH_FUNC(git_path_bisect_names, "BISECT_NAMES")
2019
static GIT_PATH_FUNC(git_path_bisect_first_parent, "BISECT_FIRST_PARENT")
2120
static GIT_PATH_FUNC(git_path_bisect_run, "BISECT_RUN")
@@ -678,7 +677,8 @@ static enum bisect_error bisect_auto_next(struct bisect_terms *terms, const char
678677
return bisect_next(terms, prefix);
679678
}
680679

681-
static enum bisect_error bisect_start(struct bisect_terms *terms, const char **argv, int argc)
680+
static enum bisect_error bisect_start(struct bisect_terms *terms, int argc,
681+
const char **argv)
682682
{
683683
int no_checkout = 0;
684684
int first_parent_only = 0;
@@ -807,13 +807,6 @@ static enum bisect_error bisect_start(struct bisect_terms *terms, const char **a
807807
strbuf_addstr(&start_head, oid_to_hex(&head_oid));
808808
} else if (!get_oid(head, &head_oid) &&
809809
skip_prefix(head, "refs/heads/", &head)) {
810-
/*
811-
* This error message should only be triggered by
812-
* cogito usage, and cogito users should understand
813-
* it relates to cg-seek.
814-
*/
815-
if (!is_empty_or_missing_file(git_path_head_name()))
816-
return error(_("won't bisect on cg-seek'ed tree"));
817810
strbuf_addstr(&start_head, head);
818811
} else {
819812
return error(_("bad HEAD - strange symbolic ref"));
@@ -908,13 +901,13 @@ static int bisect_autostart(struct bisect_terms *terms)
908901
yesno = git_prompt(_("Do you want me to do it for you "
909902
"[Y/n]? "), PROMPT_ECHO);
910903
res = tolower(*yesno) == 'n' ?
911-
-1 : bisect_start(terms, empty_strvec, 0);
904+
-1 : bisect_start(terms, 0, empty_strvec);
912905

913906
return res;
914907
}
915908

916-
static enum bisect_error bisect_state(struct bisect_terms *terms, const char **argv,
917-
int argc)
909+
static enum bisect_error bisect_state(struct bisect_terms *terms, int argc,
910+
const char **argv)
918911
{
919912
const char *state;
920913
int i, verify_expected = 1;
@@ -1033,7 +1026,7 @@ static int process_replay_line(struct bisect_terms *terms, struct strbuf *line)
10331026
struct strvec argv = STRVEC_INIT;
10341027
int res;
10351028
sq_dequote_to_strvec(rev, &argv);
1036-
res = bisect_start(terms, argv.v, argv.nr);
1029+
res = bisect_start(terms, argv.nr, argv.v);
10371030
strvec_clear(&argv);
10381031
return res;
10391032
}
@@ -1083,7 +1076,8 @@ static enum bisect_error bisect_replay(struct bisect_terms *terms, const char *f
10831076
return bisect_auto_next(terms, NULL);
10841077
}
10851078

1086-
static enum bisect_error bisect_skip(struct bisect_terms *terms, const char **argv, int argc)
1079+
static enum bisect_error bisect_skip(struct bisect_terms *terms, int argc,
1080+
const char **argv)
10871081
{
10881082
int i;
10891083
enum bisect_error res;
@@ -1113,13 +1107,14 @@ static enum bisect_error bisect_skip(struct bisect_terms *terms, const char **ar
11131107
strvec_push(&argv_state, argv[i]);
11141108
}
11151109
}
1116-
res = bisect_state(terms, argv_state.v, argv_state.nr);
1110+
res = bisect_state(terms, argv_state.nr, argv_state.v);
11171111

11181112
strvec_clear(&argv_state);
11191113
return res;
11201114
}
11211115

1122-
static int bisect_visualize(struct bisect_terms *terms, const char **argv, int argc)
1116+
static int bisect_visualize(struct bisect_terms *terms, int argc,
1117+
const char **argv)
11231118
{
11241119
struct child_process cmd = CHILD_PROCESS_INIT;
11251120
struct strbuf sb = STRBUF_INIT;
@@ -1202,7 +1197,7 @@ static int verify_good(const struct bisect_terms *terms, const char *command)
12021197
return rc;
12031198
}
12041199

1205-
static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1200+
static int bisect_run(struct bisect_terms *terms, int argc, const char **argv)
12061201
{
12071202
int res = BISECT_OK;
12081203
struct strbuf command = STRBUF_INIT;
@@ -1271,7 +1266,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12711266
saved_stdout = dup(1);
12721267
dup2(temporary_stdout_fd, 1);
12731268

1274-
res = bisect_state(terms, &new_state, 1);
1269+
res = bisect_state(terms, 1, &new_state);
12751270

12761271
fflush(stdout);
12771272
dup2(saved_stdout, 1);
@@ -1289,7 +1284,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12891284
puts(_("bisect found first bad commit"));
12901285
res = BISECT_OK;
12911286
} else if (res) {
1292-
error(_("bisect run failed: 'bisect-state %s'"
1287+
error(_("bisect run failed: 'git bisect %s'"
12931288
" exited with error code %d"), new_state, res);
12941289
} else {
12951290
continue;
@@ -1328,7 +1323,7 @@ static int cmd_bisect__start(int argc, const char **argv, const char *prefix UNU
13281323
struct bisect_terms terms = { 0 };
13291324

13301325
set_terms(&terms, "bad", "good");
1331-
res = bisect_start(&terms, argv, argc);
1326+
res = bisect_start(&terms, argc, argv);
13321327
free_terms(&terms);
13331328
return res;
13341329
}
@@ -1372,7 +1367,7 @@ static int cmd_bisect__skip(int argc, const char **argv, const char *prefix UNUS
13721367

13731368
set_terms(&terms, "bad", "good");
13741369
get_terms(&terms);
1375-
res = bisect_skip(&terms, argv, argc);
1370+
res = bisect_skip(&terms, argc, argv);
13761371
free_terms(&terms);
13771372
return res;
13781373
}
@@ -1383,7 +1378,7 @@ static int cmd_bisect__visualize(int argc, const char **argv, const char *prefix
13831378
struct bisect_terms terms = { 0 };
13841379

13851380
get_terms(&terms);
1386-
res = bisect_visualize(&terms, argv, argc);
1381+
res = bisect_visualize(&terms, argc, argv);
13871382
free_terms(&terms);
13881383
return res;
13891384
}
@@ -1396,7 +1391,7 @@ static int cmd_bisect__run(int argc, const char **argv, const char *prefix UNUSE
13961391
if (!argc)
13971392
return error(_("'%s' failed: no command provided."), "git bisect run");
13981393
get_terms(&terms);
1399-
res = bisect_run(&terms, argv, argc);
1394+
res = bisect_run(&terms, argc, argv);
14001395
free_terms(&terms);
14011396
return res;
14021397
}
@@ -1432,20 +1427,13 @@ int cmd_bisect(int argc, const char **argv, const char *prefix)
14321427
if (check_and_set_terms(&terms, argv[0]))
14331428
usage_msg_optf(_("unknown command: '%s'"), git_bisect_usage,
14341429
options, argv[0]);
1435-
res = bisect_state(&terms, argv, argc);
1430+
res = bisect_state(&terms, argc, argv);
14361431
free_terms(&terms);
14371432
} else {
14381433
argc--;
14391434
argv++;
14401435
res = fn(argc, argv, prefix);
14411436
}
14421437

1443-
/*
1444-
* Handle early success
1445-
* From check_merge_bases > check_good_are_ancestors_of_bad > bisect_next_all
1446-
*/
1447-
if ((res == BISECT_INTERNAL_SUCCESS_MERGE_BASE) || (res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND))
1448-
res = BISECT_OK;
1449-
1450-
return -res;
1438+
return is_bisect_success(res) ? 0 : -res;
14511439
}

t/t6030-bisect-porcelain.sh

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1058,6 +1058,16 @@ test_expect_success 'bisect start with one term1 and term2' '
10581058
git bisect reset
10591059
'
10601060

1061+
test_expect_success 'bogus command does not start bisect' '
1062+
git bisect reset &&
1063+
test_must_fail git bisect --bisect-terms 1 2 2>out &&
1064+
! grep "You need to start" out &&
1065+
test_must_fail git bisect --bisect-terms 2>out &&
1066+
! grep "You need to start" out &&
1067+
grep "git bisect.*visualize" out &&
1068+
git bisect reset
1069+
'
1070+
10611071
test_expect_success 'bisect replay with term1 and term2' '
10621072
git bisect replay log_to_replay.txt >bisect_result &&
10631073
grep "$HASH2 is the first term1 commit" bisect_result &&
@@ -1148,7 +1158,6 @@ test_expect_success 'git bisect reset cleans bisection state properly' '
11481158
test_path_is_missing ".git/BISECT_LOG" &&
11491159
test_path_is_missing ".git/BISECT_RUN" &&
11501160
test_path_is_missing ".git/BISECT_TERMS" &&
1151-
test_path_is_missing ".git/head-name" &&
11521161
test_path_is_missing ".git/BISECT_HEAD" &&
11531162
test_path_is_missing ".git/BISECT_START"
11541163
'
@@ -1211,4 +1220,14 @@ test_expect_success 'bisect state output with bad commit' '
12111220
grep -F "waiting for good commit(s), bad commit known" output
12121221
'
12131222

1223+
test_expect_success 'verify correct error message' '
1224+
git bisect reset &&
1225+
git bisect start $HASH4 $HASH1 &&
1226+
write_script test_script.sh <<-\EOF &&
1227+
rm .git/BISECT*
1228+
EOF
1229+
test_must_fail git bisect run ./test_script.sh 2>error &&
1230+
grep "git bisect good.*exited with error code" error
1231+
'
1232+
12141233
test_done

0 commit comments

Comments
 (0)