bisect run: keep some of the post-v2.30.0 output

Preceding commits fixed output and behavior regressions in d1bbbe45df8 (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 <avarab@gmail.com> Based-on-patch-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Đoàn Trần Công Danh committed Nov 10, 2022 at 23:36 UTC 461fec41fa79803c367ccaf11f713d6c67ba709f
2 files changed +58 -21
builtin/bisect--helper.c
+11 -13
@@ -1141,17 +1141,17 @@ static int get_first_good(const char *refname UNUSED,
1141 return 1;
1142 }
1143
1144 -static int do_bisect_run(const char *command, const char *unquoted_cmd)
1144 +static int do_bisect_run(const char *command)
1145 {
1146 struct child_process cmd = CHILD_PROCESS_INIT;
1147
1148 - printf(_("running %s\n"), unquoted_cmd);
1148 + printf(_("running %s\n"), command);
1149 cmd.use_shell = 1;
1150 strvec_push(&cmd.args, command);
1151 return run_command(&cmd);
1152 }
1153
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)
1155 {
1156 int rc;
1157 enum bisect_error res;
@@ -1171,7 +1171,7 @@ static int verify_good(const struct bisect_terms *terms, const char *command, co
1171 if (res != BISECT_OK)
1172 return -1;
1173
1174 - rc = do_bisect_run(command, unquoted_cmd);
1174 + rc = do_bisect_run(command);
1175
1176 res = bisect_checkout(&current_rev, no_checkout);
1177 if (res != BISECT_OK)
@@ -1184,7 +1184,6 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1184 {
1185 int res = BISECT_OK;
1186 struct strbuf command = STRBUF_INIT;
1187 - struct strbuf unquoted = STRBUF_INIT;
1187 const char *new_state;
1188 int temporary_stdout_fd, saved_stdout;
1189 int is_first_run = 1;
@@ -1198,9 +1197,9 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1197 }
1198
1199 sq_quote_argv(&command, argv);
1201 - strbuf_join_argv(&unquoted, argc, argv,' ');
1200 + strbuf_ltrim(&command);
1201 while (1) {
1203 - res = do_bisect_run(command.buf, unquoted.buf);
1202 + res = do_bisect_run(command.buf);
1203
1204 /*
1205 * 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)
1209 * missing or non-executable script.
1210 */
1211 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);
1213 is_first_run = 0;
1214 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);
1217 res = BISECT_FAILED;
1218 break;
1219 }
@@ -1228,7 +1227,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1227
1228 if (res < 0 || 128 <= res) {
1229 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);
1231 break;
1232 }
1233
@@ -1265,7 +1264,7 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1264 puts(_("bisect run success"));
1265 res = BISECT_OK;
1266 } else if (res == BISECT_INTERNAL_SUCCESS_1ST_BAD_FOUND) {
1268 - puts(_("bisect run success"));
1267 + puts(_("bisect found first bad commit"));
1268 res = BISECT_OK;
1269 } else if (res) {
1270 error(_("bisect run failed: 'bisect-state %s'"
@@ -1276,7 +1275,6 @@ static int bisect_run(struct bisect_terms *terms, const char **argv, int argc)
1275 break;
1276 }
1277
1279 - strbuf_release(&unquoted);
1278 strbuf_release(&command);
1279 return res;
1280 }
t/t6030-bisect-porcelain.sh
+47 -8
@@ -288,9 +288,9 @@ test_bisect_run_args () {
288 test_expect_success 'git bisect run: args, stdout and stderr with no arguments' "
289 test_bisect_run_args <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR'
290 EOF_ARGS
291 - running ./run.sh
291 + running './run.sh'
292 $HASH4 is the first bad commit
293 - bisect run success
293 + bisect found first bad commit
294 EOF_OUT
295 EOF_ERR
296 "
@@ -299,9 +299,9 @@ test_expect_success 'git bisect run: args, stdout and stderr: "--" argument' "
299 test_bisect_run_args -- <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR'
300 <-->
301 EOF_ARGS
302 - running ./run.sh --
302 + running './run.sh' '--'
303 $HASH4 is the first bad commit
304 - bisect run success
304 + bisect found first bad commit
305 EOF_OUT
306 EOF_ERR
307 "
@@ -313,9 +313,9 @@ test_expect_success 'git bisect run: args, stdout and stderr: "--log foo --no-lo
313 <--no-log>
314 <bar>
315 EOF_ARGS
316 - running ./run.sh --log foo --no-log bar
316 + running './run.sh' '--log' 'foo' '--no-log' 'bar'
317 $HASH4 is the first bad commit
318 - bisect run success
318 + bisect found first bad commit
319 EOF_OUT
320 EOF_ERR
321 "
@@ -324,13 +324,52 @@ test_expect_success 'git bisect run: args, stdout and stderr: "--bisect-start" a
324 test_bisect_run_args --bisect-start <<-'EOF_ARGS' 6<<-EOF_OUT 7<<-'EOF_ERR'
325 <--bisect-start>
326 EOF_ARGS
327 - running ./run.sh --bisect-start
327 + running './run.sh' '--bisect-start'
328 $HASH4 is the first bad commit
329 - bisect run success
329 + bisect found first bad commit
330 EOF_OUT
331 EOF_ERR
332 "
333
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 +
373 # We want to automatically find the commit that
374 # added "Another" into hello.
375 test_expect_success '"git bisect run" simple case' '