path: root/builtin/update-ref.c
diff options
authorPatrick Steinhardt <>2021-09-03 09:06:37 (GMT)
committerJunio C Hamano <>2021-09-03 18:35:15 (GMT)
commitefa3d64ce86a600563c8bf909c46dd0985ee6c11 (patch)
treead4c6667386cccdacad27ee6adddae0cb4ddf43c /builtin/update-ref.c
parent225bc32a989d7a22fa6addafd4ce7dcd04675dbf (diff)
update-ref: fix streaming of status updates
When executing git-update-ref(1) with the `--stdin` flag, then the user can queue updates and, since e48cf33b61 (update-ref: implement interactive transaction handling, 2020-04-02), interactively drive the transaction's state via a set of transactional verbs. This interactivity is somewhat broken though: while the caller can use these verbs to drive the transaction's state, the status messages which confirm that a verb has been processed is not flushed. The caller may thus be left hanging waiting for the acknowledgement. Fix the bug by flushing stdout after writing the status update. Add a test which catches this bug. Signed-off-by: Patrick Steinhardt <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/update-ref.c')
1 files changed, 10 insertions, 4 deletions
diff --git a/builtin/update-ref.c b/builtin/update-ref.c
index 6029a80..a84e7b4 100644
--- a/builtin/update-ref.c
+++ b/builtin/update-ref.c
@@ -302,6 +302,12 @@ static void parse_cmd_verify(struct ref_transaction *transaction,
+static void report_ok(const char *command)
+ fprintf(stdout, "%s: ok\n", command);
+ fflush(stdout);
static void parse_cmd_option(struct ref_transaction *transaction,
const char *next, const char *end)
@@ -317,7 +323,7 @@ static void parse_cmd_start(struct ref_transaction *transaction,
if (*next != line_termination)
die("start: extra input: %s", next);
- puts("start: ok");
+ report_ok("start");
static void parse_cmd_prepare(struct ref_transaction *transaction,
@@ -328,7 +334,7 @@ static void parse_cmd_prepare(struct ref_transaction *transaction,
die("prepare: extra input: %s", next);
if (ref_transaction_prepare(transaction, &error))
die("prepare: %s", error.buf);
- puts("prepare: ok");
+ report_ok("prepare");
static void parse_cmd_abort(struct ref_transaction *transaction,
@@ -339,7 +345,7 @@ static void parse_cmd_abort(struct ref_transaction *transaction,
die("abort: extra input: %s", next);
if (ref_transaction_abort(transaction, &error))
die("abort: %s", error.buf);
- puts("abort: ok");
+ report_ok("abort");
static void parse_cmd_commit(struct ref_transaction *transaction,
@@ -350,7 +356,7 @@ static void parse_cmd_commit(struct ref_transaction *transaction,
die("commit: extra input: %s", next);
if (ref_transaction_commit(transaction, &error))
die("commit: %s", error.buf);
- puts("commit: ok");
+ report_ok("commit");