From efa3d64ce86a600563c8bf909c46dd0985ee6c11 Mon Sep 17 00:00:00 2001 From: Patrick Steinhardt Date: Fri, 3 Sep 2021 11:06:37 +0200 Subject: 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 --- t/t1400-update-ref.sh | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) (limited to 't') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 4506cd435b..1e754e258f 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -1598,6 +1598,38 @@ test_expect_success 'transaction cannot restart ongoing transaction' ' test_must_fail git show-ref --verify refs/heads/restart ' +test_expect_success PIPE 'transaction flushes status updates' ' + mkfifo in out && + (git update-ref --stdin out &) && + + exec 9>in && + test_when_finished "exec 9>&-" && + + echo "start" >&9 && + echo "start: ok" >expected && + read line actual && + test_cmp expected actual && + + echo "create refs/heads/flush $A" >&9 && + + echo prepare >&9 && + echo "prepare: ok" >expected && + read line actual && + test_cmp expected actual && + + # This must now fail given that we have locked the ref. + test_must_fail git update-ref refs/heads/flush $B 2>stderr && + grep "fatal: update_ref failed for ref ${SQ}refs/heads/flush${SQ}: cannot lock ref" stderr && + + echo commit >&9 && + echo "commit: ok" >expected && + read line actual && + test_cmp expected actual +' + test_expect_success 'directory not created deleting packed ref' ' git branch d1/d2/r1 HEAD && git pack-refs --all && -- cgit v1.2.3 From 7c1200745bec3034c98d6e44bd5f620849dbe2ba Mon Sep 17 00:00:00 2001 From: Jeff King Date: Wed, 15 Sep 2021 13:24:52 -0400 Subject: t1400: avoid SIGPIPE race condition on fifo t1400.190 sometimes fails or even hangs because of the way it uses fifos. Our goal is to interactively read and write lines from update-ref, so we have two fifos, in and out. We open a descriptor connected to "in" and redirect output to that, so that update-ref does not see EOF as it would if we opened and closed it for each "echo" call. But we don't do the same for the output. This leads to a race where our "read response Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 't') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 1e754e258f..0d4f73acaa 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -1603,11 +1603,13 @@ test_expect_success PIPE 'transaction flushes status updates' ' (git update-ref --stdin out &) && exec 9>in && + exec 8&-" && + test_when_finished "exec 8<&-" && echo "start" >&9 && echo "start: ok" >expected && - read line actual && test_cmp expected actual && @@ -1615,7 +1617,7 @@ test_expect_success PIPE 'transaction flushes status updates' ' echo prepare >&9 && echo "prepare: ok" >expected && - read line actual && test_cmp expected actual && @@ -1625,7 +1627,7 @@ test_expect_success PIPE 'transaction flushes status updates' ' echo commit >&9 && echo "commit: ok" >expected && - read line actual && test_cmp expected actual ' -- cgit v1.2.3