Skip to content

Commit 461fec4

Browse files
sgnttaylorr
authored andcommitted
bisect run: keep some of the post-v2.30.0 output
Preceding commits fixed output and behavior regressions in d1bbbe4 (bisect--helper: reimplement `bisect_run` shell function in C, 2021-09-13), which did not claim to be changing the output of "git bisect run". But some of the output it emitted was subjectively better, so once we've asserted that we're back on v2.29.0 behavior, let's change some of it back: - We now quote the arguments again, but omit the first " " when printing the "running" line. - Ditto for other cases where we emitted the argument - We say "found first bad commit" again, not just "run success" Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]> Based-on-patch-by: Ævar Arnfjörð Bjarmason <[email protected]> Signed-off-by: Đoàn Trần Công Danh <[email protected]> Signed-off-by: Taylor Blau <[email protected]>
1 parent f37d0bd commit 461fec4

File tree

2 files changed

+58
-21
lines changed

2 files changed

+58
-21
lines changed

builtin/bisect--helper.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1141,17 +1141,17 @@ static int get_first_good(const char *refname UNUSED,
11411141
return 1;
11421142
}
11431143

1144-
static int do_bisect_run(const char *command, const char *unquoted_cmd)
1144+
static int do_bisect_run(const char *command)
11451145
{
11461146
struct child_process cmd = CHILD_PROCESS_INIT;
11471147

1148-
printf(_("running %s\n"), unquoted_cmd);
1148+
printf(_("running %s\n"), command);
11491149
cmd.use_shell = 1;
11501150
strvec_push(&cmd.args, command);
11511151
return run_command(&cmd);
11521152
}
11531153

1154-
static int verify_good(const struct bisect_terms *terms, const char *command, const char *unquoted_cmd)
1154+
static int verify_good(const struct bisect_terms *terms, const char *command)
11551155
{
11561156
int rc;
11571157
enum bisect_error res;
@@ -1171,7 +1171,7 @@ static int verify_good(const struct bisect_terms *terms, const char *command, co
11711171
if (res != BISECT_OK)
11721172
return -1;
11731173

1174-
rc = do_bisect_run(command, unquoted_cmd);
1174+
rc = do_bisect_run(command);
11751175

11761176
res = bisect_checkout(&current_rev, no_checkout);
11771177
if (res != BISECT_OK)
@@ -1184,7 +1184,6 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
11841184
{
11851185
int res = BISECT_OK;
11861186
struct strbuf command = STRBUF_INIT;
1187-
struct strbuf unquoted = STRBUF_INIT;
11881187
const char *new_state;
11891188
int temporary_stdout_fd, saved_stdout;
11901189
int is_first_run = 1;
@@ -1198,9 +1197,9 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
11981197
}
11991198

12001199
sq_quote_argv(&command, argv);
1201-
strbuf_join_argv(&unquoted, argc, argv,' ');
1200+
strbuf_ltrim(&command);
12021201
while (1) {
1203-
res = do_bisect_run(command.buf, unquoted.buf);
1202+
res = do_bisect_run(command.buf);
12041203

12051204
/*
12061205
* Exit code 126 and 127 can either come from the shell
@@ -1210,11 +1209,11 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12101209
* missing or non-executable script.
12111210
*/
12121211
if (is_first_run && (res == 126 || res == 127)) {
1213-
int rc = verify_good(terms, command.buf, unquoted.buf);
1212+
int rc = verify_good(terms, command.buf);
12141213
is_first_run = 0;
12151214
if (rc < 0) {
1216-
error(_("unable to verify '%s' on good"
1217-
" revision"), unquoted.buf);
1215+
error(_("unable to verify %s on good"
1216+
" revision"), command.buf);
12181217
res = BISECT_FAILED;
12191218
break;
12201219
}
@@ -1228,7 +1227,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12281227

12291228
if (res < 0 || 128 <= res) {
12301229
error(_("bisect run failed: exit code %d from"
1231-
" '%s' is < 0 or >= 128"), res, unquoted.buf);
1230+
" %s is < 0 or >= 128"), res, command.buf);
12321231
break;
12331232
}
12341233

@@ -1265,7 +1264,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12651264
puts(_("bisect run success"));
12661265
res = BISECT_OK;
12671266
} else if (res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND) {
1268-
puts(_("bisect run success"));
1267+
puts(_("bisect found first bad commit"));
12691268
res = BISECT_OK;
12701269
} else if (res) {
12711270
error(_("bisect run failed: 'bisect-state %s'"
@@ -1276,7 +1275,6 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
12761275
break;
12771276
}
12781277

1279-
strbuf_release(&unquoted);
12801278
strbuf_release(&command);
12811279
return res;
12821280
}

t/t6030-bisect-porcelain.sh

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,9 @@ test_bisect_run_args () {
288288
test_expect_success 'git bisect run: args, stdout and stderr with no arguments' "
289289
test_bisect_run_args <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR'
290290
EOF_ARGS
291-
running ./run.sh
291+
running './run.sh'
292292
$HASH4 is the first bad commit
293-
bisect run success
293+
bisect found first bad commit
294294
EOF_OUT
295295
EOF_ERR
296296
"
@@ -299,9 +299,9 @@ test_expect_success 'git bisect run: args, stdout and stderr: "--" argument' "
299299
test_bisect_run_args -- <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR'
300300
<-->
301301
EOF_ARGS
302-
running ./run.sh --
302+
running './run.sh' '--'
303303
$HASH4 is the first bad commit
304-
bisect run success
304+
bisect found first bad commit
305305
EOF_OUT
306306
EOF_ERR
307307
"
@@ -313,9 +313,9 @@ test_expect_success 'git bisect run: args, stdout and stderr: "--log foo --no-lo
313313
<--no-log>
314314
<bar>
315315
EOF_ARGS
316-
running ./run.sh --log foo --no-log bar
316+
running './run.sh' '--log' 'foo' '--no-log' 'bar'
317317
$HASH4 is the first bad commit
318-
bisect run success
318+
bisect found first bad commit
319319
EOF_OUT
320320
EOF_ERR
321321
"
@@ -324,13 +324,52 @@ test_expect_success 'git bisect run: args, stdout and stderr: "--bisect-start" a
324324
test_bisect_run_args --bisect-start <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR'
325325
<--bisect-start>
326326
EOF_ARGS
327-
running ./run.sh --bisect-start
327+
running './run.sh' '--bisect-start'
328328
$HASH4 is the first bad commit
329-
bisect run success
329+
bisect found first bad commit
330330
EOF_OUT
331331
EOF_ERR
332332
"
333333

334+
test_expect_success 'git bisect run: negative exit code' "
335+
write_script fail.sh <<-'EOF' &&
336+
exit 255
337+
EOF
338+
cat <<-'EOF' >expect &&
339+
bisect run failed: exit code -1 from './fail.sh' is < 0 or >= 128
340+
EOF
341+
test_when_finished 'git bisect reset' &&
342+
git bisect start &&
343+
git bisect good $HASH1 &&
344+
git bisect bad $HASH4 &&
345+
! git bisect run ./fail.sh 2>err &&
346+
sed -En 's/.*(bisect.*code) (-?[0-9]+) (from.*)/\1 -1 \3/p' err >actual &&
347+
test_cmp expect actual
348+
"
349+
350+
test_expect_failure 'git bisect run: unable to verify on good' "
351+
write_script fail.sh <<-'EOF' &&
352+
head=\$(git rev-parse --verify HEAD)
353+
good=\$(git rev-parse --verify $HASH1)
354+
if test "\$head" = "\$good"
355+
then
356+
exit 255
357+
else
358+
exit 127
359+
fi
360+
EOF
361+
cat <<-'EOF' >expect &&
362+
unable to verify './fail.sh' on good revision
363+
EOF
364+
test_when_finished 'git bisect reset' &&
365+
git bisect start &&
366+
git bisect good $HASH1 &&
367+
git bisect bad $HASH4 &&
368+
! git bisect run ./fail.sh 2>err &&
369+
sed -n 's/.*\(unable to verify.*\)/\1/p' err >actual &&
370+
test_cmp expect actual
371+
"
372+
334373
# We want to automatically find the commit that
335374
# added "Another" into hello.
336375
test_expect_success '"git bisect run" simple case' '

0 commit comments

Comments
 (0)