]> git.ipfire.org Git - thirdparty/git.git/commitdiff
bisect: output bisect setup status in bisect log
authorChris Down <chris@chrisdown.name>
Wed, 11 May 2022 18:00:14 +0000 (19:00 +0100)
committerJunio C Hamano <gitster@pobox.com>
Wed, 11 May 2022 19:35:13 +0000 (12:35 -0700)
This allows seeing the current intermediate status without adding a new
good or bad commit:

    $ git bisect log | tail -1
    # status: waiting for bad commit, 1 good commit known

Signed-off-by: Chris Down <chris@chrisdown.name>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/bisect--helper.c
t/t6030-bisect-porcelain.sh

index fa8024a8641d5a02b5317a5c05162d10735adf71..e358e3dd5bb36aebcafd0b111351e26b1cf687a8 100644 (file)
@@ -400,6 +400,22 @@ static void bisect_status(struct bisect_state *state,
        free(bad_ref);
 }
 
+__attribute__((format (printf, 1, 2)))
+static void bisect_log_printf(const char *fmt, ...)
+{
+       struct strbuf buf = STRBUF_INIT;
+       va_list ap;
+
+       va_start(ap, fmt);
+       strbuf_vaddf(&buf, fmt, ap);
+       va_end(ap);
+
+       printf("%s", buf.buf);
+       append_to_file(git_path_bisect_log(), "# %s", buf.buf);
+
+       strbuf_release(&buf);
+}
+
 static void bisect_print_status(const struct bisect_terms *terms)
 {
        struct bisect_state state = { 0 };
@@ -411,13 +427,13 @@ static void bisect_print_status(const struct bisect_terms *terms)
                return;
 
        if (!state.nr_good && !state.nr_bad)
-               printf(_("status: waiting for both good and bad commits\n"));
+               bisect_log_printf(_("status: waiting for both good and bad commits\n"));
        else if (state.nr_good)
-               printf(Q_("status: waiting for bad commit, %d good commit known\n",
-                         "status: waiting for bad commit, %d good commits known\n",
-                         state.nr_good), state.nr_good);
+               bisect_log_printf(Q_("status: waiting for bad commit, %d good commit known\n",
+                                    "status: waiting for bad commit, %d good commits known\n",
+                                    state.nr_good), state.nr_good);
        else
-               printf(_("status: waiting for good commit(s), bad commit known\n"));
+               bisect_log_printf(_("status: waiting for good commit(s), bad commit known\n"));
 }
 
 static int bisect_next_check(const struct bisect_terms *terms,
index 686f6d5c7f65d6fe48b81cd172770fd882ac1e6a..83931d482fb23b0b774310a49e8dcd6ad7eac4b9 100755 (executable)
@@ -1029,9 +1029,15 @@ test_expect_success 'bisect state output with multiple good commits' '
        git bisect reset &&
        git bisect start >output &&
        grep "waiting for both good and bad commits" output &&
+       git bisect log >output &&
+       grep "waiting for both good and bad commits" output &&
        git bisect good "$HASH1" >output &&
        grep "waiting for bad commit, 1 good commit known" output &&
+       git bisect log >output &&
+       grep "waiting for bad commit, 1 good commit known" output &&
        git bisect good "$HASH2" >output &&
+       grep "waiting for bad commit, 2 good commits known" output &&
+       git bisect log >output &&
        grep "waiting for bad commit, 2 good commits known" output
 '
 
@@ -1039,7 +1045,11 @@ test_expect_success 'bisect state output with bad commit' '
        git bisect reset &&
        git bisect start >output &&
        grep "waiting for both good and bad commits" output &&
+       git bisect log >output &&
+       grep "waiting for both good and bad commits" output &&
        git bisect bad "$HASH4" >output &&
+       grep -F "waiting for good commit(s), bad commit known" output &&
+       git bisect log >output &&
        grep -F "waiting for good commit(s), bad commit known" output
 '