Skip to contentSkip to conversation

New execute-commands hook for centralized workflow

PATCH In review Jiang Xin 6 participants 266 messages Mar 4, 2020 – Feb 13, 2021 Page 3 of 4

Subsystems (2)
lore
Share & tools
lore
#152 lore raw

Re: [PATCH v2] t5411: consistent result for proc-receive broken test

In reply to Junio C Hamano
Quoted 9 lines · Junio C Hamano
Quoted 9 lines
(quoted diff) +2 -0
@@ -1196,11 +1197,12 @@ static int run_proc_receive_hook(struct command *commands,
 		packet_flush(proc.in);
 	}
 
+	close(proc.in);
+
 	/* Read result from proc-receive */
 	code = read_proc_receive_report(&reader, commands, &errmsg);
 
Quoted 8 lines

Review static int run_proc_receive_hook(struct command *commands, · line 1208

Quoted 5 lines
(quoted diff) +0 -1
 cleanup:
-	close(proc.in);
 	close(proc.out);
 	if (use_sideband)
 		finish_async(&muxer);

OK, without us closing our end, the hook cannot even tell that it read to the end of our input.

That doesn't seem right. It should be expecting our flush packet, shouldn't it? And if it sees an EOF before the flush packet, that would be an error from the hook's perspective.

This part of the patch seems like a red herring to me.

Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -52,8 +53,10 @@ static void proc_receive_verison(struct packet_reader *reader) {
 		}
 	}
 
Quoted 8 lines

Review static void proc_receive_verison(struct packet_reader *reader) { · line 59

Quoted 5 lines
(quoted diff) +3 -1
-	if (server_version != 1 || die_version)
+	if (server_version != 1)
 		die("bad protocol version: %d", server_version);
+	if (die_version)
+		die("die with the --die-version option");

If any of these trigger, wouldn't we end up dying without consuming what receive-pack said?

Yeah, I think they would have the same race that the commit message describes (proc-receive hook writes to stderr and dies, receive-pack gets an error writing to now-closed hook pipe and never relays the stderr).

But it seems like fixing this in the hook is the wrong place. The hook has failed and has nothing else to say. Adding a pump-the-stdin-to-eof loop to every die() is a lot of effort. Not to mention that the hook could fail for reasons outside its usual flow control (e.g., segfault, oom, etc, and receive-pack should be able to handle that gracefully, even if the hook doesn't appear to behave.

I.e., I think the bug is in receive-pack's run_proc_receive_hook(). It cleverly ignores SIGPIPE exactly to avoid dying during the write phase, but then it proceeds to call packet_write_fmt(), etc, that will die on any error (going to extra effort to emulate sigpipe, no less!). So we die and take our sideband muxer with us.

So instead of this hunk:

Quoted 10 lines
Quoted 10 lines
(quoted diff) +5 -1
@@ -79,9 +82,15 @@ static void proc_receive_read_commands(struct packet_reader *reader,
 		    *p++ != ' ' ||
 		    parse_oid_hex(p, &new_oid, &p) ||
 		    *p++ != ' ' ||
-		    die_readline)
+		    die_readline) {
+			char *bad_line = xstrdup(reader->line);
+			while (packet_reader_read(reader) != PACKET_READ_EOF)
+				; /* do nothing */
+			if (die_readline)
Quoted 8 lines

Review static void proc_receive_read_commands(struct packet_reader *reader, · line 93

Quoted 5 lines
(quoted diff) +3 -1
+				die("die with the --die-readline option");
 			die("protocol error: expected 'old new ref', got '%s'",
-			    reader->line);
+			    bad_line);
+		}

This part is different from the previous one in that it slurps all the input before dying evein in die_readline case.

I think the patch really ought to be in receive-pack, converting packet_write_fmt() and packet_flush() into their "gently" forms.

And when we see a write error, close our pipe to the hook, set errmsg to "hook failed to run" or similar, and then jump to the "cleanup" label, where we'll wait on our sideband muxer to finish (which in turn will wait pump any remaining data out of the hook's stderr).

Optionally we can pump the hook stdout to see if it gave us a better message, but I think if write() failed, then all bets are off. The hook broke protocol; a well-behaved hook that wanted to pass along a specific per-ref message to the user would actually read all the input and then report on each ref).

-Peff

#153 lore raw

Re: [PATCH v2] t5411: consistent result for proc-receive broken test

Quoted 1 line · Jeff King

I.e., I think the bug is in receive-pack's run_proc_receive_hook().

I thought that this was merely to work it around and give the particular test a reliable failure code, though. Either way, receive-pack will get a failure when the hook fails (either the failure message from the hook, or unexpected EOF), so no matter what this patch does around this area, it would not affect interactions with real-life hooks, I would think.

Quoted 27 lines

It
cleverly ignores SIGPIPE exactly to avoid dying during the write phase, but then it proceeds to call packet_write_fmt(), etc, that will die on any error (going to extra effort to emulate sigpipe, no less!). So we die and take our sideband muxer with us.

So instead of this hunk:

Quoted 10 lines
Quoted 10 lines
(quoted diff) +5 -1
@@ -79,9 +82,15 @@ static void proc_receive_read_commands(struct packet_reader *reader,
 		    *p++ != ' ' ||
 		    parse_oid_hex(p, &new_oid, &p) ||
 		    *p++ != ' ' ||
-		    die_readline)
+		    die_readline) {
+			char *bad_line = xstrdup(reader->line);
+			while (packet_reader_read(reader) != PACKET_READ_EOF)
+				; /* do nothing */
+			if (die_readline)
Quoted 8 lines

Review static void proc_receive_read_commands(struct packet_reader *reader, · line 93

Quoted 5 lines
(quoted diff) +3 -1
+				die("die with the --die-readline option");
 			die("protocol error: expected 'old new ref', got '%s'",
-			    reader->line);
+			    bad_line);
+		}

This part is different from the previous one in that it slurps all the input before dying evein in die_readline case.

Quoted 2 lines

I think the patch really ought to be in receive-pack, converting packet_write_fmt() and packet_flush() into their "gently" forms.

That would be a real fix, not "work around flakey tests". Yes, the hook driver roughly mimics run_and_feed_hook() and I suspect it started from copy-and-paste from that function, so we might need to review that original copy, too.

Quoted 10 lines

And when we see a write error, close our pipe to the hook, set errmsg to "hook failed to run" or similar, and then jump to the "cleanup" label, where we'll wait on our sideband muxer to finish (which in turn will wait pump any remaining data out of the hook's stderr).

Optionally we can pump the hook stdout to see if it gave us a better message, but I think if write() failed, then all bets are off. The hook broke protocol; a well-behaved hook that wanted to pass along a specific per-ref message to the user would actually read all the input and then report on each ref).

Yup, sounds good.

#154 lore raw

Re: [PATCH v2] t5411: consistent result for proc-receive broken test

Quoted 10 lines · Junio C Hamano
Quoted 1 line · Jeff King

I.e., I think the bug is in receive-pack's run_proc_receive_hook().

I thought that this was merely to work it around and give the particular test a reliable failure code, though. Either way, receive-pack will get a failure when the hook fails (either the failure message from the hook, or unexpected EOF), so no matter what this patch does around this area, it would not affect interactions with real-life hooks, I would think.

Yes. Either way receive-pack will fail and won't update any refs, which is good. The question is whether or not it gives a useful message back to the client or not. So the tests are exposing an interesting user-visible behavior, albeit one which we wouldn't expect to come up much in practice.

Quoted 7 lines
Quoted 2 lines

I think the patch really ought to be in receive-pack, converting packet_write_fmt() and packet_flush() into their "gently" forms.

That would be a real fix, not "work around flakey tests". Yes, the hook driver roughly mimics run_and_feed_hook() and I suspect it started from copy-and-paste from that function, so we might need to review that original copy, too.

Good idea. I think it is fine, though. It does all of its writing through write_in_full(), and breaks out of the write loop on error. Whereas run_proc_receive_hook() switched to using the packet_* functions, which by default die on write errors. So I think that's the root of the problem.

I found it a little curious that run_and_feed_hook() did not complain on write error, but I think it is explicitly allowing a hook to "exit 0" immediately without even reading the input. As long as the hook exits non-zero, we'd still consider that an error (and because we handled the write error gracefully, we'd do so reliably). It would be weird if we saw some _other_ error (EIO or something) while writing, though. I suspect that's all but impossible for a pipe write like this, but it wouldn't be wrong to tighten it up, I suppose.

And back to run_proc_receive_hook(), I think it _should_ complain about a write error, rather than allowing the hook to quietly say "exit 0". The protocol for the proc-receive hook is more complicated, and we are looking for an exchange of pkt-lines, and not just "we dumped some data and it gave us an exit code". So I think it failing to read should probably be considered a break of that pkt-line protocol.

-Peff

author
#155 lore raw

Re: [PATCH v2] t5411: consistent result for proc-receive broken test

In reply to Jeff King
Quoted 52 lines · Jeff King <[email protected]> 于2020年11月10日周二 上午7:12写道:
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0
@@ -52,8 +53,10 @@ static void proc_receive_verison(struct packet_reader *reader) {
            }
    }
 
Quoted 8 lines

Review static void proc_receive_verison(struct packet_reader *reader) { · line 59

Quoted 5 lines
(quoted diff) +3 -1
-   if (server_version != 1 || die_version)
+   if (server_version != 1)
            die("bad protocol version: %d", server_version);
+   if (die_version)
+           die("die with the --die-version option");

If any of these trigger, wouldn't we end up dying without consuming what receive-pack said?

Yeah, I think they would have the same race that the commit message describes (proc-receive hook writes to stderr and dies, receive-pack gets an error writing to now-closed hook pipe and never relays the stderr).

But it seems like fixing this in the hook is the wrong place. The hook has failed and has nothing else to say. Adding a pump-the-stdin-to-eof loop to every die() is a lot of effort. Not to mention that the hook could fail for reasons outside its usual flow control (e.g., segfault, oom, etc, and receive-pack should be able to handle that gracefully, even if the hook doesn't appear to behave.

I.e., I think the bug is in receive-pack's run_proc_receive_hook(). It cleverly ignores SIGPIPE exactly to avoid dying during the write phase, but then it proceeds to call packet_write_fmt(), etc, that will die on any error (going to extra effort to emulate sigpipe, no less!). So we die and take our sideband muxer with us.

So instead of this hunk:

Quoted 10 lines
Quoted 10 lines
(quoted diff) +5 -1
@@ -79,9 +82,15 @@ static void proc_receive_read_commands(struct packet_reader *reader,
                *p++ != ' ' ||
                parse_oid_hex(p, &new_oid, &p) ||
                *p++ != ' ' ||
-               die_readline)
+               die_readline) {
+                   char *bad_line = xstrdup(reader->line);
+                   while (packet_reader_read(reader) != PACKET_READ_EOF)
+                           ; /* do nothing */
+                   if (die_readline)
Quoted 8 lines

Review static void proc_receive_read_commands(struct packet_reader *reader, · line 93

Quoted 5 lines
(quoted diff) +3 -1
+                           die("die with the --die-readline option");
                    die("protocol error: expected 'old new ref', got '%s'",
-                       reader->line);
+                       bad_line);
+           }

This part is different from the previous one in that it slurps all the input before dying evein in die_readline case.

Quoted 2 lines

I think the patch really ought to be in receive-pack, converting packet_write_fmt() and packet_flush() into their "gently" forms.

Thanks Peff for pointing the root cause. Will use the "gently" forms of packet_write_fmt() and packet_flush() in patch v3.

--
Jiang Xin

author
#156 lore raw

PATCH v3 1/2 t5411: refactor make_user_friendly_and_stable_output

Common function make_user_friendly_and_stable_output() can take additional arguments to format messages for special cases.

---
 t/t5411/common-functions.sh                       | 10 ++++++++--
 t/t5411/test-0000-standard-git-push.sh            |  9 ++++-----
 t/t5411/test-0001-standard-git-push--porcelain.sh | 15 +++++++--------
 3 files changed, 19 insertions(+), 15 deletions(-)
t/t5411/common-functions.sh +8 -2
index 521a347710..b7cca2d8fb 100644
@@ -42,7 +42,7 @@ create_commits_in () {
 make_user_friendly_and_stable_output () {
 	sed \
 		-e "s/  *\$//" \
-		-e "s/   */ /g" \
+		-e "s/  */ /g" \
 		-e "s/'/\"/g" \
 		-e "s/	/    /g" \
 		-e "s/$A/<COMMIT-A>/g" \
@@ -52,5 +52,11 @@ make_user_friendly_and_stable_output () {
 		-e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \
 		-e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \
 		-e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
-		-e "/^error: / d"
+		-e "/^error: / d" | \
+	if test $# -eq 0
+	then
+		cat
+	else
+		sed ${1+"$@"}
+	fi
 }
t/t5411/test-0000-standard-git-push.sh +4 -5
index 2b04b49367..b3af3f59b0 100644
@@ -36,11 +36,10 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
 		main \
 		$B:refs/heads/next \
 		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out |
-		sed -n \
-			-e "/^To / { s/   */ /g; p; }" \
-			-e "/^ ! / { s/   */ /g; p; }" \
-			>actual &&
+	make_user_friendly_and_stable_output -n \
+		-e "/^To / { p; }" \
+		-e "/^ ! / { p; }" \
+		<out >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	 ! [rejected] main -> main (non-fast-forward)
t/t5411/test-0001-standard-git-push--porcelain.sh +7 -8
index 747307f8da..16ff2d5666 100644
@@ -37,16 +37,15 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
 		main \
 		$B:refs/heads/next \
 		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out |
-		sed -n \
-			-e "s/^# GETTEXT POISON #//" \
-			-e "/^To / { s/   */ /g; p; }" \
-			-e "/^! / { s/   */ /g; p; }" \
-			>actual &&
+	make_user_friendly_and_stable_output -n \
+		-e "s/^# GETTEXT POISON #//" \
+		-e "/^To / { p; }" \
+		-e "/^! / { p; }" \
+		<out >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
-	! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
-	! <COMMIT-B>:refs/heads/next [rejected] (atomic push failed)
+	!    refs/heads/main:refs/heads/main    [rejected] (non-fast-forward)
+	!    <COMMIT-B>:refs/heads/next    [rejected] (atomic push failed)
 	EOF
 	test_cmp expect actual &&
 	git -C "$upstream" show-ref >out &&
Signature · 1 line
2.29.0.dirty
#157 lore raw

Re: [PATCH v3 1/2] t5411: refactor make_user_friendly_and_stable_output

Quoted 16 lines · Jiang Xin
t/t5411/common-functions.sh +1 -1
index 521a347710..b7cca2d8fb 100644
@@ -42,7 +42,7 @@ create_commits_in () {
 make_user_friendly_and_stable_output () {
 	sed \
 		-e "s/  *\$//" \
-		-e "s/   */ /g" \
+		-e "s/  */ /g" \
 		-e "s/'/\"/g" \
 		-e "s/	/    /g" \
 		-e "s/$A/<COMMIT-A>/g" \
@@ -52,5 +52,11 @@ make_user_friendly_and_stable_output () {
 		-e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \
 		-e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \

t/t5411/common-functions.sh make_user_friendly_and_stable_output () { · line 62

Quoted 10 lines
t/t5411/common-functions.sh +7 -1
 		-e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
-		-e "/^error: / d"
+		-e "/^error: / d" | \
+	if test $# -eq 0
+	then
+		cat
+	else
+		sed ${1+"$@"}
+	fi
 }

I may have suggested it, but looking at this implementation I'd have to say it is not worth the extra process here. The only reason why I made the suggestion was that way we can make the single "sed" invocation to do what we want.

If you need custom output for just two tests in 5411-0000, define the custom one that wraps make_user_friendly_and_stable_output in that single script like so:

    filter_out_remote_messages () {
	make_user_friendly_and_stable_output |
	sed -n -e ...
    }

and then use that ...

Quoted 7 lines
t/t5411/test-0000-standard-git-push.sh +0 -0
index 2b04b49367..b3af3f59b0 100644
@@ -36,11 +36,10 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
 		main \
 		$B:refs/heads/next \

t/t5411/test-0000-standard-git-push.sh test_expect_success "git-push --atomic ($PROTOCOL)" ' · line 42

Quoted 10 lines
t/t5411/test-0000-standard-git-push.sh +4 -5
 		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out |
-		sed -n \
-			-e "/^To / { s/   */ /g; p; }" \
-			-e "/^ ! / { s/   */ /g; p; }" \
-			>actual &&
+	make_user_friendly_and_stable_output -n \
+		-e "/^To / { p; }" \
+		-e "/^ ! / { p; }" \
+		<out >actual &&

... perhaps like

	filter_out_remote_messages <out >actual &&	

here?

Quoted 28 lines
t/t5411/test-0001-standard-git-push--porcelain.sh +7 -8
index 747307f8da..16ff2d5666 100644
@@ -37,16 +37,15 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
 		main \
 		$B:refs/heads/next \
 		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out |
-		sed -n \
-			-e "s/^# GETTEXT POISON #//" \
-			-e "/^To / { s/   */ /g; p; }" \
-			-e "/^! / { s/   */ /g; p; }" \
-			>actual &&
+	make_user_friendly_and_stable_output -n \
+		-e "s/^# GETTEXT POISON #//" \
+		-e "/^To / { p; }" \
+		-e "/^! / { p; }" \
+		<out >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
-	! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
-	! <COMMIT-B>:refs/heads/next [rejected] (atomic push failed)
+	!    refs/heads/main:refs/heads/main    [rejected] (non-fast-forward)
+	!    <COMMIT-B>:refs/heads/next    [rejected] (atomic push failed)
 	EOF
 	test_cmp expect actual &&
 	git -C "$upstream" show-ref >out &&
author
#158 lore raw

Re: [PATCH v3 1/2] t5411: refactor make_user_friendly_and_stable_output

Quoted 39 lines · Junio C Hamano <[email protected]> 于2020年11月11日周三 上午4:51写道:
Quoted 16 lines · Jiang Xin
t/t5411/common-functions.sh +1 -1
index 521a347710..b7cca2d8fb 100644
@@ -42,7 +42,7 @@ create_commits_in () {
 make_user_friendly_and_stable_output () {
      sed \
              -e "s/  *\$//" \
-             -e "s/   */ /g" \
+             -e "s/  */ /g" \
              -e "s/'/\"/g" \
              -e "s/  /    /g" \
              -e "s/$A/<COMMIT-A>/g" \
@@ -52,5 +52,11 @@ make_user_friendly_and_stable_output () {
              -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \
              -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \

t/t5411/common-functions.sh make_user_friendly_and_stable_output () { · line 62

Quoted 10 lines
t/t5411/common-functions.sh +7 -1
              -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
-             -e "/^error: / d"
+             -e "/^error: / d" | \
+     if test $# -eq 0
+     then
+             cat
+     else
+             sed ${1+"$@"}
+     fi
 }

I may have suggested it, but looking at this implementation I'd have to say it is not worth the extra process here. The only reason why I made the suggestion was that way we can make the single "sed" invocation to do what we want.

If you need custom output for just two tests in 5411-0000, define the custom one that wraps make_user_friendly_and_stable_output in that single script like so:

Quoted 6 lines
    filter_out_remote_messages () {
        make_user_friendly_and_stable_output |
        sed -n -e ...
    }

and then use that ...

Will add new helper function filter_out_user_friendly_and_stable_output like this, and use it for 5411-0000, 5411-0001, 5411-0013 and 5411-0014.

author
#159 lore raw

PATCH v3 2/2 receive-pack: gently write messages to proc-receive

In reply to Jiang Xin

Johannes found a flaky hang in t5411/test-0013-bad-protocol.sh in the osx-clang job of the CI/PR builds, and ran into an issue when using the --stress option with the following error messages:

fatal: unable to write flush packet: Broken pipe
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly

In this test case, the "proc-receive" hook sends an error message and dies earlier. While "receive-pack" on the other side of the pipe should forward the error message of the "proc-receive" hook to the client side, but it fails to do so. This is because "receive-pack" uses packet_write_fmt() and packet_flush() to write pkt-line message to "proc-receive" hook, and these functions die immediately when pipe is broken. Using "gently" forms for these functions will get more predicable output.

Add more "--die-*" options to test helper to test different stages of the protocol between "receive-pack" and "proc-receive" hook.

---
 builtin/receive-pack.c                       |  62 +++++--
 t/helper/test-proc-receive.c                 |  42 +++--
 t/t5411/test-0013-bad-protocol.sh            | 141 +++++++++++++--
 t/t5411/test-0014-bad-protocol--porcelain.sh | 176 ++++++++++++++++++-
 4 files changed, 380 insertions(+), 41 deletions(-)
builtin/receive-pack.c +47 -15
index bb9909c52e..697a4e8802 100644
@@ -974,9 +974,10 @@ static int read_proc_receive_report(struct packet_reader *reader,
 	struct command *cmd;
 	struct command *hint = NULL;
 	struct ref_push_report *report = NULL;
-	int new_report = 0;
 	int code = 0;
+	int new_report = 0;
 	int once = 0;
+	int response = 0;
 
 	for (;;) {
 		struct object_id old_oid, new_oid;
@@ -984,8 +985,14 @@ static int read_proc_receive_report(struct packet_reader *reader,
 		const char *refname;
 		char *p;
 
-		if (packet_reader_read(reader) != PACKET_READ_NORMAL)
+		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
+			if (!response) {
+				strbuf_addstr(errmsg, "no response from proc-receive hook");
+				return -1;
+			}
 			break;
+		}
+		response++;
 
 		head = reader->line;
 		p = strchr(head, ' ');
@@ -1100,7 +1107,7 @@ static int run_proc_receive_hook(struct command *commands,
 	struct strbuf cap = STRBUF_INIT;
 	struct strbuf errmsg = STRBUF_INIT;
 	int hook_use_push_options = 0;
-	int version = 0;
+	int version = -1;
 	int code;
 
 	argv[0] = find_hook("proc-receive");
@@ -1145,12 +1152,17 @@ static int run_proc_receive_hook(struct command *commands,
 	if (use_push_options)
 		strbuf_addstr(&cap, " push-options");
 	if (cap.len) {
-		packet_write_fmt(proc.in, "version=1%c%s\n", '\0', cap.buf + 1);
+		code = packet_write_fmt_gently(proc.in, "version=1%c%s\n", '\0', cap.buf + 1);
 		strbuf_release(&cap);
 	} else {
-		packet_write_fmt(proc.in, "version=1\n");
+		code = packet_write_fmt_gently(proc.in, "version=1\n");
+	}
+	if (!code)
+		code = packet_flush_gently(proc.in);
+	if (code) {
+		strbuf_addstr(&errmsg, "fail to negotiate version with proc-receive hook");
+		goto cleanup;
 	}
-	packet_flush(proc.in);
 
 	for (;;) {
 		int linelen;
@@ -1169,7 +1181,11 @@ static int run_proc_receive_hook(struct command *commands,
 		}
 	}
 
-	if (version != 1) {
+	if (version == -1) {
+		strbuf_addstr(&errmsg, "fail to negotiate version with proc-receive hook");
+		code = -1;
+		goto cleanup;
+	} else if (version != 1) {
 		strbuf_addf(&errmsg, "proc-receive version '%d' is not supported",
 			    version);
 		code = -1;
@@ -1180,20 +1196,36 @@ static int run_proc_receive_hook(struct command *commands,
 	for (cmd = commands; cmd; cmd = cmd->next) {
 		if (!cmd->run_proc_receive || cmd->skip_update || cmd->error_string)
 			continue;
-		packet_write_fmt(proc.in, "%s %s %s",
-				 oid_to_hex(&cmd->old_oid),
-				 oid_to_hex(&cmd->new_oid),
-				 cmd->ref_name);
+		code = packet_write_fmt_gently(proc.in, "%s %s %s",
+					       oid_to_hex(&cmd->old_oid),
+					       oid_to_hex(&cmd->new_oid),
+					       cmd->ref_name);
+		if (code)
+			break;
+	}
+	if (!code)
+		code = packet_flush_gently(proc.in);
+	if (code) {
+		strbuf_addstr(&errmsg, "fail to write commands to proc-receive hook");
+		goto cleanup;
 	}
-	packet_flush(proc.in);
 
 	/* Send push options */
 	if (hook_use_push_options) {
 		struct string_list_item *item;
 
-		for_each_string_list_item(item, push_options)
-			packet_write_fmt(proc.in, "%s", item->string);
-		packet_flush(proc.in);
+		for_each_string_list_item(item, push_options) {
+			code = packet_write_fmt_gently(proc.in, "%s", item->string);
+			if (code)
+				break;
+		}
+		if (!code)
+			code = packet_flush_gently(proc.in);
+		if (code) {
+			strbuf_addstr(&errmsg,
+				      "fail to write push-options to proc-receive hook");
+			goto cleanup;
+		}
 	}
 
 	/* Read result from proc-receive */
t/helper/test-proc-receive.c +32 -10

95 lines not on this page · raw message

t/t5411/test-0013-bad-protocol.sh +127 -14

214 lines not on this page · raw message

t/t5411/test-0014-bad-protocol--porcelain.sh +174 -2

213 lines not on this page · raw message

Signature · 1 line
2.29.0.dirty
#160 lore raw

Re: [PATCH v3 2/2] receive-pack: gently write messages to proc-receive

Quoted 8 lines · Jiang Xin

Johannes found a flaky hang in t5411/test-0013-bad-protocol.sh in the osx-clang job of the CI/PR builds, and ran into an issue when using the --stress option with the following error messages:

fatal: unable to write flush packet: Broken pipe
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly

Quoted 8 lines

In this test case, the "proc-receive" hook sends an error message and dies earlier. While "receive-pack" on the other side of the pipe should forward the error message of the "proc-receive" hook to the client side, but it fails to do so. This is because "receive-pack" uses packet_write_fmt() and packet_flush() to write pkt-line message to "proc-receive" hook, and these functions die immediately when pipe is broken. Using "gently" forms for these functions will get more predicable output.

The changes to use gently() in the code looked good to me, and I think you got all of the relevant spots.

I was surprised by a few bits:

builtin/receive-pack.c static int read_proc_receive_report(struct packet_reader *reader, · line 978

Quoted 11 lines
builtin/receive-pack.c +1 -1
index bb9909c52e..697a4e8802 100644
@@ -974,9 +974,10 @@ static int read_proc_receive_report(struct packet_reader *reader,
 	struct command *cmd;
 	struct command *hint = NULL;
 	struct ref_push_report *report = NULL;
-	int new_report = 0;
 	int code = 0;
+	int new_report = 0;

This is just noise in the diff, I think. It does not matter either way.

builtin/receive-pack.c static int read_proc_receive_report(struct packet_reader *reader, · line 995

Quoted 13 lines
builtin/receive-pack.c +7 -1
@@ -984,8 +985,14 @@ static int read_proc_receive_report(struct packet_reader *reader,
 		const char *refname;
 		char *p;
 
-		if (packet_reader_read(reader) != PACKET_READ_NORMAL)
+		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
+			if (!response) {
+				strbuf_addstr(errmsg, "no response from proc-receive hook");
+				return -1;
+			}
 			break;
+		}
+		response++;

This extra check seems orthogonal to the rest of the commit. It does seem like it might be a reasonable thing to check, but I wondered:

- if the hook has nothing to report, wouldn't it just send a flush packet? Does that break protocol or not?

- if not, then I guess we're expecting a response for every ref we mentioned (and presumably we would not trigger the hook at all if there are no refs). But in that case, shouldn't we be checking that we counted up the number of responses we expected? But we already do that, by annotating the items in the commands list that didn't get RUN_PROC_RECEIVE_RETURNED set.

So at best, it seems like this check is redundant (and at worst it may complain unnecessarily about a corner case).

Quoted 5 lines
builtin/receive-pack.c +0 -1
@@ -1100,7 +1107,7 @@ static int run_proc_receive_hook(struct command *commands,
 	struct strbuf cap = STRBUF_INIT;
 	struct strbuf errmsg = STRBUF_INIT;
 	int hook_use_push_options = 0;
-	int version = 0;

builtin/receive-pack.c static int run_proc_receive_hook(struct command *commands,

Quoted 10 lines
builtin/receive-pack.c +6 -1
+	int version = -1;
[...]
-	if (version != 1) {
+	if (version == -1) {
+		strbuf_addstr(&errmsg, "fail to negotiate version with proc-receive hook");
+		code = -1;
+		goto cleanup;
+	} else if (version != 1) {
 		strbuf_addf(&errmsg, "proc-receive version '%d' is not supported",
 			    version);

Likewise this seems orthogonal to the main point of the patch. Though it seems like a good idea in general to check when the other side doesn't report a version (assuming it is a protocol breakage not to report the version, and we're not simply supposed to default).

-Peff

author
#161 lore raw

Re: [PATCH v3 2/2] receive-pack: gently write messages to proc-receive

Quoted 31 lines · Jeff King <[email protected]> 于2020年11月11日周三 上午5:52写道:

builtin/receive-pack.c static int read_proc_receive_report(struct packet_reader *reader, · line 978

Quoted 11 lines
builtin/receive-pack.c +1 -1
index bb9909c52e..697a4e8802 100644
@@ -974,9 +974,10 @@ static int read_proc_receive_report(struct packet_reader *reader,
      struct command *cmd;
      struct command *hint = NULL;
      struct ref_push_report *report = NULL;
-     int new_report = 0;
      int code = 0;
+     int new_report = 0;

This is just noise in the diff, I think. It does not matter either way.

builtin/receive-pack.c static int read_proc_receive_report(struct packet_reader *reader, · line 995

Quoted 13 lines
builtin/receive-pack.c +7 -1
@@ -984,8 +985,14 @@ static int read_proc_receive_report(struct packet_reader *reader,
              const char *refname;
              char *p;
 
-             if (packet_reader_read(reader) != PACKET_READ_NORMAL)
+             if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
+                     if (!response) {
+                             strbuf_addstr(errmsg, "no response from proc-receive hook");
+                             return -1;
+                     }
                      break;
+             }
+             response++;

This extra check seems orthogonal to the rest of the commit. It does seem like it might be a reasonable thing to check, but I wondered:

Quoted 2 lines

- if the hook has nothing to report, wouldn't it just send a flush packet? Does that break protocol or not?

It's OK to send a flush packet without any payload, so will check status PACKET_READ_EOF for broken proc-receive.

-- snip --
@@ -977,15 +977,25 @@ static int read_proc_receive_report(struct packet_reader *reader,

        for (;;) {
                struct object_id old_oid, new_oid;
                const char *head;
                const char *refname;
                char *p;

-
- if (packet_reader_read(reader) != PACKET_READ_NORMAL)
+ enum packet_read_status status;
+
+ status = packet_reader_read(reader);
+ if (status != PACKET_READ_NORMAL) {
+ /* Check whether proc-receive exited abnormally */
+ if (status == PACKET_READ_EOF && !response) {
+ strbuf_addstr(errmsg, "proc-receive
exited abnormally");
+ return -1;
+ }

                        break;

+ }
+ response++;
-- snap --

Quoted 13 lines
Quoted 13 lines
builtin/receive-pack.c +5 -2
@@ -1100,7 +1107,7 @@ static int run_proc_receive_hook(struct command *commands,
      struct strbuf cap = STRBUF_INIT;
      struct strbuf errmsg = STRBUF_INIT;
      int hook_use_push_options = 0;
-     int version = 0;
+     int version = -1;
[...]
-     if (version != 1) {
+     if (version == -1) {
+             strbuf_addstr(&errmsg, "fail to negotiate version with proc-receive hook");
+             code = -1;
+             goto cleanup;
Quoted 8 lines
Quoted 3 lines

+ } else if (version != 1) {
strbuf_addf(&errmsg, "proc-receive version '%d' is not supported",
version);

Likewise this seems orthogonal to the main point of the patch. Though it seems like a good idea in general to check when the other side doesn't report a version (assuming it is a protocol breakage not to report the version, and we're not simply supposed to default).

Will add a new patch for default version for proc-receive.

#162 lore raw

Re: [PATCH v2] t5411: consistent result for proc-receive broken test

In reply to Jiang Xin
Quoted 2 lines · Jiang Xin

Thanks Peff for pointing the root cause. Will use the "gently" forms of packet_write_fmt() and packet_flush() in patch v3.

Another thing I noticed. Its tests are based on a codebase where master is called main, which means it is not designed to be usable with the 'master' or 'maint' track.

Because the topic is no longer "just apply a band-aid to paper over test flakeyness" but is fixing the codepath that matters in real user experience, I'd prefer to see it applicable even to the maintenance track.

Thanks.

#163 lore raw

Re: [PATCH v2] t5411: consistent result for proc-receive broken test

Quoted 5 lines · Junio C Hamano
Quoted 2 lines · Jiang Xin

Thanks Peff for pointing the root cause. Will use the "gently" forms of packet_write_fmt() and packet_flush() in patch v3.

Quoted 8 lines

Another thing I noticed. Its tests are based on a codebase where master is called main, which means it is not designed to be usable with the 'master' or 'maint' track.

Because the topic is no longer "just apply a band-aid to paper over test flakeyness" but is fixing the codepath that matters in real user experience, I'd prefer to see it applicable even to the maintenance track.

I've queued these patches on top of js/default-branch-name-adjust-t5411; that makes the topic mergeable to 'master' but not to 'maint'. Perhaps that is good enough, as the maintenance track of today would become obsolete by the end of this year.

Thanks.

author
#164 lore raw

PATCH v4 1/3 t5411: new helper filter_out_user_friendly_and_stable_output

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

New helper filter_out_user_friendly_and_stable_output will call common helpr function make_user_friendly_and_stable_output and use additional arguments to filter out messages for specific test cases.

---
 t/t5411/common-functions.sh                       |  7 ++++++-
 t/t5411/test-0000-standard-git-push.sh            |  9 ++++-----
 t/t5411/test-0001-standard-git-push--porcelain.sh | 15 +++++++--------
 3 files changed, 17 insertions(+), 14 deletions(-)
t/t5411/common-functions.sh +6 -1
index 521a347710..344d13f61a 100644
@@ -42,7 +42,7 @@ create_commits_in () {
 make_user_friendly_and_stable_output () {
 	sed \
 		-e "s/  *\$//" \
-		-e "s/   */ /g" \
+		-e "s/  */ /g" \
 		-e "s/'/\"/g" \
 		-e "s/	/    /g" \
 		-e "s/$A/<COMMIT-A>/g" \
@@ -54,3 +54,8 @@ make_user_friendly_and_stable_output () {
 		-e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
 		-e "/^error: / d"
 }
+
+filter_out_user_friendly_and_stable_output () {
+	make_user_friendly_and_stable_output |
+		sed -n ${1+"$@"}
+}
t/t5411/test-0000-standard-git-push.sh +4 -5
index 2b04b49367..47b058af7e 100644
@@ -36,11 +36,10 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
 		main \
 		$B:refs/heads/next \
 		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out |
-		sed -n \
-			-e "/^To / { s/   */ /g; p; }" \
-			-e "/^ ! / { s/   */ /g; p; }" \
-			>actual &&
+	filter_out_user_friendly_and_stable_output \
+		-e "/^To / { p; }" \
+		-e "/^ ! / { p; }" \
+		<out >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	 ! [rejected] main -> main (non-fast-forward)
t/t5411/test-0001-standard-git-push--porcelain.sh +7 -8
index 747307f8da..bbead12bbb 100644
@@ -37,16 +37,15 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
 		main \
 		$B:refs/heads/next \
 		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out |
-		sed -n \
-			-e "s/^# GETTEXT POISON #//" \
-			-e "/^To / { s/   */ /g; p; }" \
-			-e "/^! / { s/   */ /g; p; }" \
-			>actual &&
+	filter_out_user_friendly_and_stable_output \
+		-e "s/^# GETTEXT POISON #//" \
+		-e "/^To / { p; }" \
+		-e "/^! / { p; }" \
+		<out >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
-	! refs/heads/main:refs/heads/main [rejected] (non-fast-forward)
-	! <COMMIT-B>:refs/heads/next [rejected] (atomic push failed)
+	!    refs/heads/main:refs/heads/main    [rejected] (non-fast-forward)
+	!    <COMMIT-B>:refs/heads/next    [rejected] (atomic push failed)
 	EOF
 	test_cmp expect actual &&
 	git -C "$upstream" show-ref >out &&
Signature · 1 line
2.29.0.dirty
author
#165 lore raw

v4 cover jx/t5411-flake-fix

In reply to Jiang Xin

The exchange between receive-pack and proc-receive hook did not carefully check for errors.

## Changes since v3

1. Patch 1/3:

Add new helper function filter_out_user_friendly_and_stable_output, and use it for 5411-0000, 5411-0001, 5411-0013 and 5411-0014.

2. Patch 2/3:

Check PACKET_READ_EOF status from reader for broken pipe.

3. Patch 3/3:

Add a new patch, which uses version 0 for proc-receive by default.

## Range-diff of v3...v4

1: 785b28333f ! 1: a3bdb5a5d6 t5411: refactor make_user_friendly_and_stable_output

    @@ Metadata
     Author: Jiang Xin <[email protected]>
     
      ## Commit message ##
    -    t5411: refactor make_user_friendly_and_stable_output
    +    t5411: new helper filter_out_user_friendly_and_stable_output
     
    -    Common function `make_user_friendly_and_stable_output()` can take
    -    additional arguments to format messages for special cases.
    +    New helper `filter_out_user_friendly_and_stable_output` will call
    +    common helpr function `make_user_friendly_and_stable_output` and use
    +    additional arguments to filter out messages for specific test cases.
     
         Suggested-by: Junio C Hamano <[email protected]>
         Signed-off-by: Jiang Xin <[email protected]>
     
      ## t/t5411/common-functions.sh ##
     @@ t/t5411/common-functions.sh: create_commits_in () {
    @@ t/t5411/common-functions.sh: create_commits_in () {
      		-e "s/	/    /g" \
      		-e "s/$A/<COMMIT-A>/g" \
     @@ t/t5411/common-functions.sh: make_user_friendly_and_stable_output () {
    - 		-e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \
    - 		-e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \
      		-e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
    --		-e "/^error: / d"
    -+		-e "/^error: / d" | \
    -+	if test $# -eq 0
    -+	then
    -+		cat
    -+	else
    -+		sed ${1+"$@"}
    -+	fi
    + 		-e "/^error: / d"
      }
    ++
    ++filter_out_user_friendly_and_stable_output () {
    ++	make_user_friendly_and_stable_output |
    ++		sed -n ${1+"$@"}
    ++}
     
      ## t/t5411/test-0000-standard-git-push.sh ##
     @@ t/t5411/test-0000-standard-git-push.sh: test_expect_success "git-push --atomic ($PROTOCOL)" '
    @@ t/t5411/test-0000-standard-git-push.sh: test_expect_success "git-push --atomic (
     -			-e "/^To / { s/   */ /g; p; }" \
     -			-e "/^ ! / { s/   */ /g; p; }" \
     -			>actual &&
    -+	make_user_friendly_and_stable_output -n \
    ++	filter_out_user_friendly_and_stable_output \
     +		-e "/^To / { p; }" \
     +		-e "/^ ! / { p; }" \
     +		<out >actual &&
    @@ t/t5411/test-0001-standard-git-push--porcelain.sh: test_expect_success "git-push
     -			-e "/^To / { s/   */ /g; p; }" \
     -			-e "/^! / { s/   */ /g; p; }" \
     -			>actual &&
    -+	make_user_friendly_and_stable_output -n \
    ++	filter_out_user_friendly_and_stable_output \
     +		-e "s/^# GETTEXT POISON #//" \
     +		-e "/^To / { p; }" \
     +		-e "/^! / { p; }" \
2:  d83d4519db ! 2:  4ca1c6e2bc receive-pack: gently write messages to proc-receive
    @@ Commit message
         Reported-by: Johannes Schindelin <[email protected]>
         Suggested-by: Jeff King <[email protected]>
         Signed-off-by: Jiang Xin <[email protected]>
     
      ## builtin/receive-pack.c ##
     @@ builtin/receive-pack.c: static int read_proc_receive_report(struct packet_reader *reader,
    - 	struct command *cmd;
    - 	struct command *hint = NULL;
    - 	struct ref_push_report *report = NULL;
    --	int new_report = 0;
    + 	int new_report = 0;
      	int code = 0;
    -+	int new_report = 0;
      	int once = 0;
     +	int response = 0;
      
      	for (;;) {
      		struct object_id old_oid, new_oid;
    -@@ builtin/receive-pack.c: static int read_proc_receive_report(struct packet_reader *reader,
    + 		const char *head;
      		const char *refname;
      		char *p;
    - 
    +-
     -		if (packet_reader_read(reader) != PACKET_READ_NORMAL)
    -+		if (packet_reader_read(reader) != PACKET_READ_NORMAL) {
    -+			if (!response) {
    -+				strbuf_addstr(errmsg, "no response from proc-receive hook");
    ++		enum packet_read_status status;
    ++
    ++		status = packet_reader_read(reader);
    ++		if (status != PACKET_READ_NORMAL) {
    ++			/* Check whether proc-receive exited abnormally */
    ++			if (status == PACKET_READ_EOF && !response) {
    ++				strbuf_addstr(errmsg, "proc-receive exited abnormally");
     +				return -1;
     +			}
      			break;
    @@ builtin/receive-pack.c: static int read_proc_receive_report(struct packet_reader
      
      		head = reader->line;
      		p = strchr(head, ' ');
    -@@ builtin/receive-pack.c: static int run_proc_receive_hook(struct command *commands,
    - 	struct strbuf cap = STRBUF_INIT;
    - 	struct strbuf errmsg = STRBUF_INIT;
    - 	int hook_use_push_options = 0;
    --	int version = 0;
    -+	int version = -1;
    - 	int code;
    - 
    - 	argv[0] = find_hook("proc-receive");
     @@ builtin/receive-pack.c: static int run_proc_receive_hook(struct command *commands,
      	if (use_push_options)
      		strbuf_addstr(&cap, " push-options");
    @@ builtin/receive-pack.c: static int run_proc_receive_hook(struct command *command
      	} else {
     -		packet_write_fmt(proc.in, "version=1\n");
     +		code = packet_write_fmt_gently(proc.in, "version=1\n");
    -+	}
    + 	}
    +-	packet_flush(proc.in);
     +	if (!code)
     +		code = packet_flush_gently(proc.in);
    + 
    +-	for (;;) {
    +-		int linelen;
    ++	if (!code)
    ++		for (;;) {
    ++			int linelen;
    ++			enum packet_read_status status;
    + 
    +-		if (packet_reader_read(&reader) != PACKET_READ_NORMAL)
    +-			break;
    ++			status = packet_reader_read(&reader);
    ++			if (status != PACKET_READ_NORMAL) {
    ++				/* Check whether proc-receive exited abnormally */
    ++				if (status == PACKET_READ_EOF)
    ++					code = -1;
    ++				break;
    ++			}
    + 
    +-		if (reader.pktlen > 8 && starts_with(reader.line, "version=")) {
    +-			version = atoi(reader.line + 8);
    +-			linelen = strlen(reader.line);
    +-			if (linelen < reader.pktlen) {
    +-				const char *feature_list = reader.line + linelen + 1;
    +-				if (parse_feature_request(feature_list, "push-options"))
    +-					hook_use_push_options = 1;
    ++			if (reader.pktlen > 8 && starts_with(reader.line, "version=")) {
    ++				version = atoi(reader.line + 8);
    ++				linelen = strlen(reader.line);
    ++				if (linelen < reader.pktlen) {
    ++					const char *feature_list = reader.line + linelen + 1;
    ++					if (parse_feature_request(feature_list, "push-options"))
    ++						hook_use_push_options = 1;
    ++				}
    + 			}
    + 		}
    ++
     +	if (code) {
     +		strbuf_addstr(&errmsg, "fail to negotiate version with proc-receive hook");
     +		goto cleanup;
      	}
    --	packet_flush(proc.in);
      
    - 	for (;;) {
    - 		int linelen;
    -@@ builtin/receive-pack.c: static int run_proc_receive_hook(struct command *commands,
    - 		}
    - 	}
    - 
    --	if (version != 1) {
    -+	if (version == -1) {
    -+		strbuf_addstr(&errmsg, "fail to negotiate version with proc-receive hook");
    -+		code = -1;
    -+		goto cleanup;
    -+	} else if (version != 1) {
    - 		strbuf_addf(&errmsg, "proc-receive version '%d' is not supported",
    - 			    version);
    - 		code = -1;
    + 	if (version != 1) {
     @@ builtin/receive-pack.c: static int run_proc_receive_hook(struct command *commands,
      	for (cmd = commands; cmd; cmd = cmd->next) {
      		if (!cmd->run_proc_receive || cmd->skip_update || cmd->error_string)
    @@ t/t5411/test-0013-bad-protocol.sh: test_expect_success "proc-receive: bad protoc
      	test_must_fail git -C workbench push origin \
      		HEAD:refs/for/main/topic \
      		>out 2>&1 &&
    -+	make_user_friendly_and_stable_output -n \
    ++	filter_out_user_friendly_and_stable_output \
     +		-e "/^To / { p; }" \
     +		-e "/^ ! / { p; }" \
     +		<out >actual &&
    @@ t/t5411/test-0013-bad-protocol.sh: test_expect_success "proc-receive: bad protoc
     +	test-tool proc-receive -v --die-write-version
     +	EOF
     +'
    -+
    + 
     +# Refs of upstream : main(A)
     +# Refs of workbench: main(A)  tags/v123
     +# git push         :                       refs/for/main/topic(A)
    @@ t/t5411/test-0013-bad-protocol.sh: test_expect_success "proc-receive: bad protoc
     +	test_must_fail git -C workbench push origin \
     +		HEAD:refs/for/main/topic \
     +		>out 2>&1 &&
    -+	make_user_friendly_and_stable_output -n \
    ++	filter_out_user_friendly_and_stable_output \
     +		-e "/^To / { p; }" \
     +		-e "/^ ! / { p; }" \
     +		<out >actual &&
    @@ t/t5411/test-0013-bad-protocol.sh: test_expect_success "proc-receive: bad protoc
     +	test_cmp expect actual &&
     +	grep "remote: fatal: die with the --die-write-version option" out &&
     +	grep "remote: error: fail to negotiate version with proc-receive hook" out &&
    - 
    ++
     +	git -C "$upstream" show-ref >out &&
     +	make_user_friendly_and_stable_output <out >actual &&
     +	cat >expect <<-EOF &&
    @@ t/t5411/test-0013-bad-protocol.sh: test_expect_success "proc-receive: bad protoc
     +	test_must_fail git -C workbench push origin \
     +		HEAD:refs/for/main/topic \
     +		>out 2>&1 &&
    -+	make_user_friendly_and_stable_output -n \
    ++	filter_out_user_friendly_and_stable_output \
     +		-e "/^To / { p; }" \
     +		-e "/^ ! / { p; }" \
     +		<out >actual &&
    @@ t/t5411/test-0013-bad-protocol.sh: test_expect_success "proc-receive: bad protoc
     +		-o reviewers=user1,user2 \
      		HEAD:refs/for/main/topic \
      		>out 2>&1 &&
    -+	make_user_friendly_and_stable_output -n \
    ++	filter_out_user_friendly_and_stable_output \
     +		-e "/^To / { p; }" \
     +		-e "/^ ! / { p; }" \
     +		<out >actual &&
    @@ t/t5411/test-0013-bad-protocol.sh: test_expect_success "proc-receive: bad protoc
     +	EOF
     +	test_cmp expect actual
     +'
    - 
    --	grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/main/topic\"" actual &&
    ++
     +test_expect_success "setup proc-receive hook (hook --die-write-report, $PROTOCOL)" '
     +	write_script "$upstream/hooks/proc-receive" <<-EOF
     +	printf >&2 "# proc-receive hook\n"
     +	test-tool proc-receive -v --die-write-report
     +	EOF
     +'
    -+
    + 
    +-	grep "remote: fatal: protocol error: expected \"old new ref\", got \"<ZERO-OID> <COMMIT-A> refs/for/main/topic\"" actual &&
     +# Refs of upstream : main(A)
     +# Refs of workbench: main(A)  tags/v123
     +# git push         :                       refs/for/main/topic(A)
    @@ t/t5411/test-0013-bad-protocol.sh: test_expect_success "proc-receive: bad protoc
     +	test_must_fail git -C workbench push origin \
     +		HEAD:refs/for/main/topic \
     +		>out 2>&1 &&
    -+	make_user_friendly_and_stable_output -n \
    ++	filter_out_user_friendly_and_stable_output \
     +		-e "/^To / { p; }" \
     +		-e "/^ ! / { p; }" \
     +		<out >actual &&
    @@ t/t5411/test-0013-bad-protocol.sh: test_expect_success "proc-receive: bad protoc
      	git -C "$upstream" show-ref >out &&
      	make_user_friendly_and_stable_output <out >actual &&
     @@ t/t5411/test-0013-bad-protocol.sh: test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" '
    - 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
    - 	remote: # proc-receive hook
    - 	remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
    -+	remote: error: no response from proc-receive hook
    - 	remote: # post-receive hook
    - 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
    - 	To <URL/of/upstream.git>
    - 	 * [new branch] HEAD -> next
    --	 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
    -+	 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
    + 	 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
      	EOF
      	test_cmp expect actual &&
     +
    @@ t/t5411/test-0014-bad-protocol--porcelain.sh: test_expect_success "proc-receive:
     +	test_must_fail git -C workbench push --porcelain origin \
     +		HEAD:refs/for/main/topic \
     +		>out 2>&1 &&
    -+	make_user_friendly_and_stable_output -n \
    ++	filter_out_user_friendly_and_stable_output \
     +		-e "/^To / { p; n; p; n; p; }" \
     +		<out >actual &&
     +	cat >expect <<-EOF &&
    @@ t/t5411/test-0014-bad-protocol--porcelain.sh: test_expect_success "proc-receive:
     +	test_must_fail git -C workbench push --porcelain origin \
     +		HEAD:refs/for/main/topic \
     +		>out 2>&1 &&
    -+	make_user_friendly_and_stable_output -n \
    ++	filter_out_user_friendly_and_stable_output \
     +		-e "/^To / { p; n; p; n; p; }" \
     +		<out >actual &&
     +	cat >expect <<-EOF &&
    @@ t/t5411/test-0014-bad-protocol--porcelain.sh: test_expect_success "proc-receive:
     +	test_must_fail git -C workbench push --porcelain origin \
     +		HEAD:refs/for/main/topic \
     +		>out 2>&1 &&
    -+	make_user_friendly_and_stable_output -n \
    ++	filter_out_user_friendly_and_stable_output \
     +		-e "/^To / { p; n; p; n; p; }" \
     +		<out >actual &&
     +	cat >expect <<-EOF &&
    @@ t/t5411/test-0014-bad-protocol--porcelain.sh: test_expect_success "proc-receive:
     +		-o reviewers=user1,user2 \
     +		HEAD:refs/for/main/topic \
     +		>out 2>&1 &&
    -+	make_user_friendly_and_stable_output -n \
    ++	filter_out_user_friendly_and_stable_output \
     +		-e "/^To / { p; n; p; n; p; }" \
     +		<out >actual &&
     +	cat >expect <<-EOF &&
    @@ t/t5411/test-0014-bad-protocol--porcelain.sh: test_expect_success "proc-receive:
     +	test_must_fail git -C workbench push --porcelain origin \
     +		HEAD:refs/for/main/topic \
     +		>out 2>&1 &&
    -+	make_user_friendly_and_stable_output -n \
    ++	filter_out_user_friendly_and_stable_output \
     +		-e "/^To / { p; n; p; n; p; }" \
     +		<out >actual &&
     +	cat >expect <<-EOF &&
    @@ t/t5411/test-0014-bad-protocol--porcelain.sh: test_expect_success "proc-receive:
      	write_script "$upstream/hooks/proc-receive" <<-EOF
      	printf >&2 "# proc-receive hook\n"
     @@ t/t5411/test-0014-bad-protocol--porcelain.sh: test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL/porcelain)
    - 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
    - 	remote: # proc-receive hook
    - 	remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
    -+	remote: error: no response from proc-receive hook
    - 	remote: # post-receive hook
    - 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
    - 	To <URL/of/upstream.git>
    - 	*    HEAD:refs/heads/next    [new branch]
    --	!    HEAD:refs/for/main/topic    [remote rejected] (proc-receive failed to report status)
    -+	!    HEAD:refs/for/main/topic    [remote rejected] (fail to run proc-receive hook)
      	Done
      	EOF
      	test_cmp expect actual &&

-: ---------- > 3: 82d03e6508 receive-pack: use default version 0 for proc-receive

---

Jiang Xin (3):
t5411: new helper filter_out_user_friendly_and_stable_output
receive-pack: gently write messages to proc-receive
receive-pack: use default version 0 for proc-receive

 builtin/receive-pack.c                        |  94 +++++++---
 t/helper/test-proc-receive.c                  |  54 ++++--
 t/t5411/common-functions.sh                   |   7 +-
 t/t5411/test-0000-standard-git-push.sh        |   9 +-
 .../test-0001-standard-git-push--porcelain.sh |  15 +-
 t/t5411/test-0013-bad-protocol.sh             | 138 ++++++++++++--
 t/t5411/test-0014-bad-protocol--porcelain.sh  | 173 +++++++++++++++++-
 t/t5411/test-0026-push-options.sh             |  60 ++++++
 t/t5411/test-0027-push-options--porcelain.sh  |  62 +++++++
 9 files changed, 545 insertions(+), 67 deletions(-)
Signature · 1 line
2.29.0.dirty
author
#166 lore raw

PATCH v4 2/3 receive-pack: gently write messages to proc-receive

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

Johannes found a flaky hang in t5411/test-0013-bad-protocol.sh in the osx-clang job of the CI/PR builds, and ran into an issue when using the --stress option with the following error messages:

fatal: unable to write flush packet: Broken pipe
send-pack: unexpected disconnect while reading sideband packet
fatal: the remote end hung up unexpectedly

In this test case, the "proc-receive" hook sends an error message and dies earlier. While "receive-pack" on the other side of the pipe should forward the error message of the "proc-receive" hook to the client side, but it fails to do so. This is because "receive-pack" uses packet_write_fmt() and packet_flush() to write pkt-line message to "proc-receive" hook, and these functions die immediately when pipe is broken. Using "gently" forms for these functions will get more predicable output.

Add more "--die-*" options to test helper to test different stages of the protocol between "receive-pack" and "proc-receive" hook.

---
 builtin/receive-pack.c                       |  87 +++++++---
 t/helper/test-proc-receive.c                 |  42 +++--
 t/t5411/test-0013-bad-protocol.sh            | 138 +++++++++++++--
 t/t5411/test-0014-bad-protocol--porcelain.sh | 173 ++++++++++++++++++-
 4 files changed, 392 insertions(+), 48 deletions(-)
builtin/receive-pack.c +63 -24
index bb9909c52e..2bd736525f 100644
@@ -977,15 +977,25 @@ static int read_proc_receive_report(struct packet_reader *reader,
 	int new_report = 0;
 	int code = 0;
 	int once = 0;
+	int response = 0;
 
 	for (;;) {
 		struct object_id old_oid, new_oid;
 		const char *head;
 		const char *refname;
 		char *p;
-
-		if (packet_reader_read(reader) != PACKET_READ_NORMAL)
+		enum packet_read_status status;
+
+		status = packet_reader_read(reader);
+		if (status != PACKET_READ_NORMAL) {
+			/* Check whether proc-receive exited abnormally */
+			if (status == PACKET_READ_EOF && !response) {
+				strbuf_addstr(errmsg, "proc-receive exited abnormally");
+				return -1;
+			}
 			break;
+		}
+		response++;
 
 		head = reader->line;
 		p = strchr(head, ' ');
@@ -1145,28 +1155,41 @@ static int run_proc_receive_hook(struct command *commands,
 	if (use_push_options)
 		strbuf_addstr(&cap, " push-options");
 	if (cap.len) {
-		packet_write_fmt(proc.in, "version=1%c%s\n", '\0', cap.buf + 1);
+		code = packet_write_fmt_gently(proc.in, "version=1%c%s\n", '\0', cap.buf + 1);
 		strbuf_release(&cap);
 	} else {
-		packet_write_fmt(proc.in, "version=1\n");
+		code = packet_write_fmt_gently(proc.in, "version=1\n");
 	}
-	packet_flush(proc.in);
+	if (!code)
+		code = packet_flush_gently(proc.in);
 
-	for (;;) {
-		int linelen;
+	if (!code)
+		for (;;) {
+			int linelen;
+			enum packet_read_status status;
 
-		if (packet_reader_read(&reader) != PACKET_READ_NORMAL)
-			break;
+			status = packet_reader_read(&reader);
+			if (status != PACKET_READ_NORMAL) {
+				/* Check whether proc-receive exited abnormally */
+				if (status == PACKET_READ_EOF)
+					code = -1;
+				break;
+			}
 
-		if (reader.pktlen > 8 && starts_with(reader.line, "version=")) {
-			version = atoi(reader.line + 8);
-			linelen = strlen(reader.line);
-			if (linelen < reader.pktlen) {
-				const char *feature_list = reader.line + linelen + 1;
-				if (parse_feature_request(feature_list, "push-options"))
-					hook_use_push_options = 1;
+			if (reader.pktlen > 8 && starts_with(reader.line, "version=")) {
+				version = atoi(reader.line + 8);
+				linelen = strlen(reader.line);
+				if (linelen < reader.pktlen) {
+					const char *feature_list = reader.line + linelen + 1;
+					if (parse_feature_request(feature_list, "push-options"))
+						hook_use_push_options = 1;
+				}
 			}
 		}
+
+	if (code) {
+		strbuf_addstr(&errmsg, "fail to negotiate version with proc-receive hook");
+		goto cleanup;
 	}
 
 	if (version != 1) {
@@ -1180,20 +1203,36 @@ static int run_proc_receive_hook(struct command *commands,
 	for (cmd = commands; cmd; cmd = cmd->next) {
 		if (!cmd->run_proc_receive || cmd->skip_update || cmd->error_string)
 			continue;
-		packet_write_fmt(proc.in, "%s %s %s",
-				 oid_to_hex(&cmd->old_oid),
-				 oid_to_hex(&cmd->new_oid),
-				 cmd->ref_name);
+		code = packet_write_fmt_gently(proc.in, "%s %s %s",
+					       oid_to_hex(&cmd->old_oid),
+					       oid_to_hex(&cmd->new_oid),
+					       cmd->ref_name);
+		if (code)
+			break;
+	}
+	if (!code)
+		code = packet_flush_gently(proc.in);
+	if (code) {
+		strbuf_addstr(&errmsg, "fail to write commands to proc-receive hook");
+		goto cleanup;
 	}
-	packet_flush(proc.in);
 
 	/* Send push options */
 	if (hook_use_push_options) {
 		struct string_list_item *item;
 
-		for_each_string_list_item(item, push_options)
-			packet_write_fmt(proc.in, "%s", item->string);
-		packet_flush(proc.in);
+		for_each_string_list_item(item, push_options) {
+			code = packet_write_fmt_gently(proc.in, "%s", item->string);
+			if (code)
+				break;
+		}
+		if (!code)
+			code = packet_flush_gently(proc.in);
+		if (code) {
+			strbuf_addstr(&errmsg,
+				      "fail to write push-options to proc-receive hook");
+			goto cleanup;
+		}
 	}
 
 	/* Read result from proc-receive */
t/helper/test-proc-receive.c +32 -10

95 lines not on this page · raw message

t/t5411/test-0013-bad-protocol.sh +125 -13

205 lines not on this page · raw message

t/t5411/test-0014-bad-protocol--porcelain.sh +172 -1

203 lines not on this page · raw message

Signature · 1 line
2.29.0.dirty
author
#167 lore raw

PATCH v4 3/3 receive-pack: use default version 0 for proc-receive

In reply to Jiang Xin

In the verison negotiation phase between "receive-pack" and "proc-receive", "proc-receive" can send an empty flush-pkt to end the negotiation and use default version 0. Capabilities (such as "push-options") are not supported in version 0.

---
 builtin/receive-pack.c                       |  7 ++-
 t/helper/test-proc-receive.c                 | 16 +++--
 t/t5411/test-0026-push-options.sh            | 60 +++++++++++++++++++
 t/t5411/test-0027-push-options--porcelain.sh | 62 ++++++++++++++++++++
 4 files changed, 138 insertions(+), 7 deletions(-)
builtin/receive-pack.c +6 -1
index 2bd736525f..f1f0f7bef6 100644
@@ -1192,7 +1192,12 @@ static int run_proc_receive_hook(struct command *commands,
 		goto cleanup;
 	}
 
-	if (version != 1) {
+	switch (version) {
+	case 0:
+		/* fallthrough */
+	case 1:
+		break;
+	default:
 		strbuf_addf(&errmsg, "proc-receive version '%d' is not supported",
 			    version);
 		code = -1;
t/helper/test-proc-receive.c +10 -6
index 6652cedcee..cc08506cf0 100644
@@ -45,8 +45,14 @@ static void proc_receive_verison(struct packet_reader *reader) {
 		if (packet_reader_read(reader) != PACKET_READ_NORMAL)
 			break;
 
+		/* Ignore version negotiation for version 0 */
+		if (version == 0)
+			continue;
+
 		if (reader->pktlen > 8 && starts_with(reader->line, "version=")) {
 			server_version = atoi(reader->line+8);
+			if (server_version != 1)
+				die("bad protocol version: %d", server_version);
 			linelen = strlen(reader->line);
 			if (linelen < reader->pktlen) {
 				const char *feature_list = reader->line + linelen + 1;
@@ -58,15 +64,13 @@ static void proc_receive_verison(struct packet_reader *reader) {
 		}
 	}
 
-	if (server_version != 1)
-		die("bad protocol version: %d", server_version);
-
 	if (die_write_version)
 		die("die with the --die-write-version option");
 
-	packet_write_fmt(1, "version=%d%c%s\n",
-			 version, '\0',
-			 use_push_options && !no_push_options ? "push-options": "");
+	if (version != 0)
+		packet_write_fmt(1, "version=%d%c%s\n",
+				 version, '\0',
+				 use_push_options && !no_push_options ? "push-options": "");
 	packet_flush(1);
 }
 
t/t5411/test-0026-push-options.sh +60 -0

66 lines not on this page · raw message

t/t5411/test-0027-push-options--porcelain.sh +62 -0

68 lines not on this page · raw message

Signature · 1 line
2.29.0.dirty
author
#168 lore raw

Re: [PATCH v2] t5411: consistent result for proc-receive broken test

In reply to Junio C Hamano
Quoted 11 lines · Junio C Hamano <[email protected]> 于2020年11月10日周二 上午4:59写道:

Review int cmd__proc_receive(int argc, const char **argv) · line 181

Quoted 7 lines
(quoted diff) +2 -0
@@ -166,6 +177,8 @@ int cmd__proc_receive(int argc, const char **argv)
                              fprintf(stderr, "proc-receive> %s\n", item->string);
      }
 
+     if (die_report)
+             die("die with the --die-report option");

And at this point we have already read everything the other end said (if so, there is no need for the artificial "read everything before we die")?

In patch v3, will use "gently" forms of packet_write_fmt() and packet_flush(), and it is no necessary to read everything before die. And will add more "--die-*" option in test helper.

Quoted 11 lines

t/t5411/test-0013-bad-protocol.sh test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" · line 57

Quoted 8 lines
t/t5411/test-0013-bad-protocol.sh +0 -0
index c5fe4cb37b..5c5241bc95 100644
@@ -55,19 +55,16 @@ test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)"
      test_must_fail git -C workbench push origin \
              HEAD:refs/for/master/topic \
              >out 2>&1 &&

Are these expected to conflict with Dscho's changes to move 'master' around?

See topic "gitster/js/default-branch-name-adjust-t5411" has been merge to master branch already. Will rebase on it.

Quoted 37 lines

t/t5411/test-0013-bad-protocol.sh test_expect_success "proc-receive: bad protocol (hook --die-version, $PROTOCOL)" · line 62

Quoted 7 lines
t/t5411/test-0013-bad-protocol.sh +5 -2
-     make_user_friendly_and_stable_output <out >actual &&
-
+     make_user_friendly_and_stable_output <out |
+             sed -n \
+                     -e "/^To / { s/   */ /g; p; }" \
+                     -e "/^ ! / { s/   */ /g; p; }" \
+                     >actual &&

It's the same thing but I somehow find "s/ */ /g" easier to read. The comparison is between "there may be two things or more---squish them down to one" and "After one thing, there may be any number of things---remove all the extra ones".

Makes me wonder if make_user_friendly should optionally have an option to do something like this for us. I doubt it that it is worth to do something like the attached patch.

 t/t5411/common-functions.sh | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)
t/t5411/common-functions.sh +3 -1
index 6580bebd8e..6919639c60 100644
@@ -40,7 +40,9 @@ create_commits_in () {
 # `GIT_TEST_GETTEXT_POISON=true` in order to test unintentional translations
 # on plumbing commands.
 make_user_friendly_and_stable_output () {
-       sed \
+       local en=
+       case "$#" in 0) ;; *) en=-n ;; esac
+       sed $en \
                -e "s/  *\$//" \
                -e "s/   */ /g" \
                -e "s/'/\"/g" \

t/t5411/common-functions.sh make_user_friendly_and_stable_output () { · line 59

Quoted 7 lines
t/t5411/common-functions.sh +2 -1
@@ -52,5 +54,6 @@ make_user_friendly_and_stable_output () {
                -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \
                -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \
                -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
-               -e "/^error: / d"
+               -e "/^error: / d" \
+               ${1+"$@"}
 }

If we call make_user_friendly_and_stable_output like this:

    make_user_friendly_and_stable_output \
         -e "/^To / { p; n; p; n; p; }

Text lines next to "^To " will not be formatted by the built-in sed's arguments. So will write like this:

-- snip --

t/t5411/common-functions.sh +8 -2
index 521a347710..b7cca2d8fb 100644
@@ -42,7 +42,7 @@ create_commits_in () {
 make_user_friendly_and_stable_output () {
        sed \
                -e "s/  *\$//" \
-               -e "s/   */ /g" \
+               -e "s/  */ /g" \
                -e "s/'/\"/g" \
                -e "s/  /    /g" \
                -e "s/$A/<COMMIT-A>/g" \
@@ -52,5 +52,11 @@ make_user_friendly_and_stable_output () {
                -e "s/$(echo $A | cut -c1-7)[0-9a-f]*/<OID-A>/g" \
                -e "s/$(echo $B | cut -c1-7)[0-9a-f]*/<OID-B>/g" \
                -e "s#To $URL_PREFIX/upstream.git#To <URL/of/upstream.git>#" \
-               -e "/^error: / d"
+               -e "/^error: / d" | \
+       if test $# -eq 0
+       then
+               cat
+       else
+               sed ${1+"$@"}
+       fi
 }

-- snap --

#169 lore raw

Re: [PATCH v19 03/10] receive-pack: add new proc-receive hook

In reply to Jiang Xin
Quoted 2 lines · Jiang Xin

I think this is the right way to fix this issue, even though I cannot reproduce this issue in my laptop.

Perhaps it depends on the size of the pipe buffer and timing of the processes getting scheduled?

This is a tangent but I very much like the way comments on a set of changes below is given interspersed, explaining why the change in each hunk is done next to it.

Quoted 57 lines

1. In the run_proc_receive_hook() function of "receive-pack", should close the input (proc.in) before reading result from "proc-receive":

-- snip --

(quoted diff) +2 -1
@@ -1196,11 +1197,12 @@ static int run_proc_receive_hook(struct
 command *commands,
                packet_flush(proc.in);
        }
 
+       close(proc.in);
+
        /* Read result from proc-receive */
        code = read_proc_receive_report(&reader, commands, &errmsg);
 
 cleanup:
-       close(proc.in);
        close(proc.out);
        if (use_sideband)
                finish_async(&muxer);

-- snap --

2. test helper for proc-receive should consume the input stream before die earlier:

-- snip --

(quoted diff) +5 -4
@@ -79,9 +79,11 @@ static void proc_receive_read_commands(struct
 packet_reader *reader,
                    *p++ != ' ' ||
                    parse_oid_hex(p, &new_oid, &p) ||
                    *p++ != ' ' ||
-                   die_readline)
+                   die_readline) {
+                       while (packet_reader_read(reader) != PACKET_READ_EOF);
                        die("protocol error: expected 'old new ref', got '%s'",
-                           reader->line);
+                               die_readline? "<call with
--die-readline>": reader->line);
+               }
                refname = p;
                FLEX_ALLOC_STR(cmd, ref_name, refname);
                oidcpy(&cmd->old_oid, &old_oid);
@@ -136,7 +138,7 @@ int cmd__proc_receive(int argc, const char **argv)
                usage_msg_opt("Too many arguments.",
 proc_receive_usage, options);
        packet_reader_init(&reader, 0, NULL, 0,
                           PACKET_READ_CHOMP_NEWLINE |
-                          PACKET_READ_DIE_ON_ERR_PACKET);
+                          PACKET_READ_GENTLE_ON_EOF);
 
        sigchain_push(SIGPIPE, SIG_IGN);
        proc_receive_verison(&reader);

-- snap --

I will send a standalone patch using git-send-email command line later.

--
Jiang Xin

#170 lore raw

Re: [PATCH v19 03/10] receive-pack: add new proc-receive hook

In reply to Jiang Xin

This patch added a whole lot of test cases, and two of them '86 -
proc-receive: not support push options (builtin protocol)' and '95 -
proc-receive: not support push options (builtin protocol/porcelain)' are prone to rare failures.

Quoted 6 lines · Jiang Xin
t/t5411/test-0026-push-options.sh new file +0 -0
new file mode 100644
index 0000000000..d0c4da8b23
 

t/t5411/test-0026-push-options.sh

Quoted 10 lines
t/t5411/test-0026-push-options.sh new file +10 -0
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push -o ...  :                       refs/for/master/topic
+test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
+	test_must_fail git -C workbench push \
+		-o issue=123 \
+		-o reviewer=user1 \
+		origin \
+		HEAD:refs/for/master/topic \
+		>out 2>&1 &&

Three relevant things are happening here:

- 'git push' is executed with its standard output and error redirected to the file 'out'.

- 'git push' executes 'git receive-pack' internally, which inherits the open file descriptors, so its output and error goes into that same 'out' file.

- 'git push' is expected to fail when it finds out that the other side doesn't support push options, but it does so with a simple die() right away, without waiting for its child 'git receive-pack' process to finish.

t/t5411/test-0026-push-options.sh

Quoted 4 lines
t/t5411/test-0026-push-options.sh new file +4 -0
+	make_user_friendly_and_stable_output <out >actual &&
+	test_i18ngrep "fatal: the receiving end does not support push options" \
+		actual &&
+	git -C "$upstream" show-ref >out &&

Here the shell opens and truncates the file 'out' to write 'git show-ref's output, i.e. it is still the same 'out' file that was used earlier.

Consequently, it is possible that 'git receive-pack' is still running, its open file descriptors to 'out' are still valid, and its "fatal:
the remote end hung up unexpectedly" error message about the suddenly disappeared 'git push' can partially overwrite the output from 'git show-ref'.

t/t5411/test-0026-push-options.sh

Quoted 6 lines
t/t5411/test-0026-push-options.sh new file +6 -0
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'

The supposedly stable output can then unexpectedly include that error message, and the test fails with something like this:

+ test_cmp expect actual
--- expect 2021-01-17 21:55:23.430750004 +0000
+++ actual 2021-01-17 21:55:23.430750004 +0000
@@ -1 +1 @@
-<COMMIT-A> refs/heads/main
+<COMMIT-A> refs/heads/maifatal: the remote end hung up unexpectedly
error: last command exited with $?=1
not ok 86 - proc-receive: not support push options (builtin protocol)

Quoted 14 lines
t/t5411/test-0027-push-options--porcelain.sh new file +8 -0
new file mode 100644
index 0000000000..c89a1e7c57
 
+test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain)" '
+	test_must_fail git -C workbench push \
+		--porcelain \
+		-o issue=123 \
+		-o reviewer=user1 \
+		origin \
+		HEAD:refs/for/master/topic \
+		>out 2>&1 &&

t/t5411/test-0027-push-options--porcelain.sh

Quoted 10 lines
t/t5411/test-0027-push-options--porcelain.sh new file +10 -0
+	make_user_friendly_and_stable_output <out >actual &&
+	test_i18ngrep "fatal: the receiving end does not support push options" \
+		actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'

This test is almost identical to the one above, and the same sequence of events leads to a similar failure.

I saw these tests fail in Travis CI's s390x environment a couple of times, and, alas, that is the only environment where I was able to reproduce the failure with '--stress' with an unmodified Git.

The diff below adds a couple of strategically-placed delays to reliably demonstrate these failures:

--- >8 ---

pkt-line.c +1 -0
index d633005ef7..3b26631948 100644
@@ -307,6 +307,7 @@ static int get_packet_data(int fd, char **src_buf, size_t *src_size,
 		if (options & PACKET_READ_GENTLE_ON_EOF)
 			return -1;
 
+		sleep(1);
 		die(_("the remote end hung up unexpectedly"));
 	}
 
t/t5411/test-0026-push-options.sh +1 -0
index e88edb16a4..a1e896f404 100644
@@ -21,6 +21,7 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
 	git -C "$upstream" show-ref >out &&
+	sleep 2 &&
 	make_user_friendly_and_stable_output <out >actual &&
 	cat >expect <<-EOF &&
 	<COMMIT-A> refs/heads/main
t/t5411/test-0027-push-options--porcelain.sh +1 -0
index 3a6561b5ea..f97cef440f 100644
@@ -22,6 +22,7 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
 	git -C "$upstream" show-ref >out &&
+	sleep 2 &&
 	make_user_friendly_and_stable_output <out >actual &&
 	cat >expect <<-EOF &&
 	<COMMIT-A> refs/heads/main

--- 8< ---

I think these are the only two tests that can cause this racy
behavior: by instrumenting finish_command() I found that in all other tests where 'git push' is expected to fail it errors out gracefully and waits for its 'git receive-pack' child process.

author
#171 lore raw

Re: [PATCH v19 03/10] receive-pack: add new proc-receive hook

Quoted 48 lines · SZEDER Gábor <[email protected]> 于2021年1月18日周一 上午6:21写道:

This patch added a whole lot of test cases, and two of them '86 -
proc-receive: not support push options (builtin protocol)' and '95 -
proc-receive: not support push options (builtin protocol/porcelain)' are prone to rare failures.

Quoted 6 lines · Jiang Xin
t/t5411/test-0026-push-options.sh new file +0 -0
new file mode 100644
index 0000000000..d0c4da8b23
 

t/t5411/test-0026-push-options.sh

Quoted 10 lines
t/t5411/test-0026-push-options.sh new file +10 -0
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push -o ...  :                       refs/for/master/topic
+test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
+     test_must_fail git -C workbench push \
+             -o issue=123 \
+             -o reviewer=user1 \
+             origin \
+             HEAD:refs/for/master/topic \
+             >out 2>&1 &&

Three relevant things are happening here:

- 'git push' is executed with its standard output and error redirected to the file 'out'.

- 'git push' executes 'git receive-pack' internally, which inherits the open file descriptors, so its output and error goes into that same 'out' file.

- 'git push' is expected to fail when it finds out that the other side doesn't support push options, but it does so with a simple die() right away, without waiting for its child 'git receive-pack' process to finish.

t/t5411/test-0026-push-options.sh

Quoted 4 lines
t/t5411/test-0026-push-options.sh new file +4 -0
+     make_user_friendly_and_stable_output <out >actual &&
+     test_i18ngrep "fatal: the receiving end does not support push options" \
+             actual &&
+     git -C "$upstream" show-ref >out &&

Here the shell opens and truncates the file 'out' to write 'git show-ref's output, i.e. it is still the same 'out' file that was used earlier.

Quoted 5 lines

Consequently, it is possible that 'git receive-pack' is still running, its open file descriptors to 'out' are still valid, and its "fatal:
the remote end hung up unexpectedly" error message about the suddenly disappeared 'git push' can partially overwrite the output from 'git show-ref'.

Thank you for providing the accurate analysis of the root cause of this problem.

Quoted 6 lines

I saw these tests fail in Travis CI's s390x environment a couple of times, and, alas, that is the only environment where I was able to reproduce the failure with '--stress' with an unmodified Git.

The diff below adds a couple of strategically-placed delays to reliably demonstrate these failures:

To solve this problem, instead of adding delays, we can simply remove the "out" file before creating a new one, thus the two "out" files have two different file descriptors, and the process in background won't break the new "out" file.

Quoted 40 lines

--- >8 ---

pkt-line.c +1 -0
index d633005ef7..3b26631948 100644
@@ -307,6 +307,7 @@ static int get_packet_data(int fd, char **src_buf, size_t *src_size,
                if (options & PACKET_READ_GENTLE_ON_EOF)
                        return -1;
 
+               sleep(1);
                die(_("the remote end hung up unexpectedly"));
        }
 
t/t5411/test-0026-push-options.sh +1 -0
index e88edb16a4..a1e896f404 100644
@@ -21,6 +21,7 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
        test_i18ngrep "fatal: the receiving end does not support push options" \
                actual &&
        git -C "$upstream" show-ref >out &&
+       sleep 2 &&
        make_user_friendly_and_stable_output <out >actual &&
        cat >expect <<-EOF &&
        <COMMIT-A> refs/heads/main
t/t5411/test-0027-push-options--porcelain.sh +1 -0
index 3a6561b5ea..f97cef440f 100644
@@ -22,6 +22,7 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain
        test_i18ngrep "fatal: the receiving end does not support push options" \
                actual &&
        git -C "$upstream" show-ref >out &&
+       sleep 2 &&
        make_user_friendly_and_stable_output <out >actual &&
        cat >expect <<-EOF &&
        <COMMIT-A> refs/heads/main
Quoted 6 lines

--- 8< ---

I think these are the only two tests that can cause this racy
behavior: by instrumenting finish_command() I found that in all other tests where 'git push' is expected to fail it errors out gracefully and waits for its 'git receive-pack' child process.

Atomic push may have the same problem.

#172 lore raw

Re: [PATCH v19 03/10] receive-pack: add new proc-receive hook

Quoted 56 lines · Jiang Xin
Quoted 53 lines · SZEDER Gábor <[email protected]> 于2021年1月18日周一 上午6:21写道:

This patch added a whole lot of test cases, and two of them '86 -
proc-receive: not support push options (builtin protocol)' and '95 -
proc-receive: not support push options (builtin protocol/porcelain)' are prone to rare failures.

Quoted 6 lines · Jiang Xin
t/t5411/test-0026-push-options.sh new file +0 -0
new file mode 100644
index 0000000000..d0c4da8b23
 

t/t5411/test-0026-push-options.sh

Quoted 10 lines
t/t5411/test-0026-push-options.sh new file +10 -0
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push -o ...  :                       refs/for/master/topic
+test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
+     test_must_fail git -C workbench push \
+             -o issue=123 \
+             -o reviewer=user1 \
+             origin \
+             HEAD:refs/for/master/topic \
+             >out 2>&1 &&

Three relevant things are happening here:

- 'git push' is executed with its standard output and error redirected to the file 'out'.

- 'git push' executes 'git receive-pack' internally, which inherits the open file descriptors, so its output and error goes into that same 'out' file.

- 'git push' is expected to fail when it finds out that the other side doesn't support push options, but it does so with a simple die() right away, without waiting for its child 'git receive-pack' process to finish.

t/t5411/test-0026-push-options.sh

Quoted 4 lines
t/t5411/test-0026-push-options.sh new file +4 -0
+     make_user_friendly_and_stable_output <out >actual &&
+     test_i18ngrep "fatal: the receiving end does not support push options" \
+             actual &&
+     git -C "$upstream" show-ref >out &&

Here the shell opens and truncates the file 'out' to write 'git show-ref's output, i.e. it is still the same 'out' file that was used earlier.

Consequently, it is possible that 'git receive-pack' is still running, its open file descriptors to 'out' are still valid, and its "fatal:
the remote end hung up unexpectedly" error message about the suddenly disappeared 'git push' can partially overwrite the output from 'git show-ref'.

Quoted 6 lines
Quoted 4 lines

I think these are the only two tests that can cause this racy
behavior: by instrumenting finish_command() I found that in all other tests where 'git push' is expected to fail it errors out gracefully and waits for its 'git receive-pack' child process.

Atomic push may have the same problem.

I don't think so, because send_pack() doesn't die() when a ref is rejected in an atomic push, but returns, and lets its caller terminate in an usual way, including waiting for 'git receive-pack'.

author
#173 lore raw

Re: [PATCH v19 03/10] receive-pack: add new proc-receive hook

Quoted 63 lines · SZEDER Gábor <[email protected]> 于2021年1月20日周三 下午8:29写道:
Quoted 61 lines · Jiang Xin
Quoted 59 lines · SZEDER Gábor <[email protected]> 于2021年1月18日周一 上午6:21写道:

This patch added a whole lot of test cases, and two of them '86 -
proc-receive: not support push options (builtin protocol)' and '95 -
proc-receive: not support push options (builtin protocol/porcelain)' are prone to rare failures.

Quoted 6 lines · Jiang Xin
t/t5411/test-0026-push-options.sh new file +0 -0
new file mode 100644
index 0000000000..d0c4da8b23
 

t/t5411/test-0026-push-options.sh

Quoted 10 lines
t/t5411/test-0026-push-options.sh new file +10 -0
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push -o ...  :                       refs/for/master/topic
+test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
+     test_must_fail git -C workbench push \
+             -o issue=123 \
+             -o reviewer=user1 \
+             origin \
+             HEAD:refs/for/master/topic \
+             >out 2>&1 &&

Three relevant things are happening here:

- 'git push' is executed with its standard output and error redirected to the file 'out'.

- 'git push' executes 'git receive-pack' internally, which inherits the open file descriptors, so its output and error goes into that same 'out' file.

- 'git push' is expected to fail when it finds out that the other side doesn't support push options, but it does so with a simple die() right away, without waiting for its child 'git receive-pack' process to finish.

t/t5411/test-0026-push-options.sh

Quoted 4 lines
t/t5411/test-0026-push-options.sh new file +4 -0
+     make_user_friendly_and_stable_output <out >actual &&
+     test_i18ngrep "fatal: the receiving end does not support push options" \
+             actual &&
+     git -C "$upstream" show-ref >out &&

Here the shell opens and truncates the file 'out' to write 'git show-ref's output, i.e. it is still the same 'out' file that was used earlier.

Consequently, it is possible that 'git receive-pack' is still running, its open file descriptors to 'out' are still valid, and its "fatal:
the remote end hung up unexpectedly" error message about the suddenly disappeared 'git push' can partially overwrite the output from 'git show-ref'.

I think these are the only two tests that can cause this racy
behavior: by instrumenting finish_command() I found that in all other tests where 'git push' is expected to fail it errors out gracefully and waits for its 'git receive-pack' child process.

Quoted 5 lines
Quoted 1 line

Atomic push may have the same problem.

I don't think so, because send_pack() doesn't die() when a ref is rejected in an atomic push, but returns, and lets its caller terminate in an usual way, including waiting for 'git receive-pack'.

I find many places where the client side will die() before closing the service side gracefully:

+ In transport_push(), if fail to push a submodule, will die().
+ In git_transport_push(), will die() for an unimplemented v2 protocol.
+ In send_pack(), will die() if
the server side has an incompatible hash algorithm, or
the receiving end does not support --signed push, or
the receiving end does not support --atomic push, or
the receiving end does not support push options

#174 lore raw

Re: [PATCH v19 03/10] receive-pack: add new proc-receive hook

Quoted 73 lines · Jiang Xin
Quoted 63 lines · SZEDER Gábor <[email protected]> 于2021年1月20日周三 下午8:29写道:
Quoted 61 lines · Jiang Xin
Quoted 59 lines · SZEDER Gábor <[email protected]> 于2021年1月18日周一 上午6:21写道:

This patch added a whole lot of test cases, and two of them '86 -
proc-receive: not support push options (builtin protocol)' and '95 -
proc-receive: not support push options (builtin protocol/porcelain)' are prone to rare failures.

Quoted 6 lines · Jiang Xin
t/t5411/test-0026-push-options.sh new file +0 -0
new file mode 100644
index 0000000000..d0c4da8b23
 

t/t5411/test-0026-push-options.sh

Quoted 10 lines
t/t5411/test-0026-push-options.sh new file +10 -0
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push -o ...  :                       refs/for/master/topic
+test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
+     test_must_fail git -C workbench push \
+             -o issue=123 \
+             -o reviewer=user1 \
+             origin \
+             HEAD:refs/for/master/topic \
+             >out 2>&1 &&

Three relevant things are happening here:

- 'git push' is executed with its standard output and error redirected to the file 'out'.

- 'git push' executes 'git receive-pack' internally, which inherits the open file descriptors, so its output and error goes into that same 'out' file.

- 'git push' is expected to fail when it finds out that the other side doesn't support push options, but it does so with a simple die() right away, without waiting for its child 'git receive-pack' process to finish.

t/t5411/test-0026-push-options.sh

Quoted 4 lines
t/t5411/test-0026-push-options.sh new file +4 -0
+     make_user_friendly_and_stable_output <out >actual &&
+     test_i18ngrep "fatal: the receiving end does not support push options" \
+             actual &&
+     git -C "$upstream" show-ref >out &&

Here the shell opens and truncates the file 'out' to write 'git show-ref's output, i.e. it is still the same 'out' file that was used earlier.

Consequently, it is possible that 'git receive-pack' is still running, its open file descriptors to 'out' are still valid, and its "fatal:
the remote end hung up unexpectedly" error message about the suddenly disappeared 'git push' can partially overwrite the output from 'git show-ref'.

I think these are the only two tests that can cause this racy
behavior: by instrumenting finish_command() I found that in all other tests where 'git push' is expected to fail it errors out gracefully and waits for its 'git receive-pack' child process.

Quoted 5 lines
Quoted 1 line

Atomic push may have the same problem.

I don't think so, because send_pack() doesn't die() when a ref is rejected in an atomic push, but returns, and lets its caller terminate in an usual way, including waiting for 'git receive-pack'.

I find many places where the client side will die() before closing the service side gracefully:

Quoted 7 lines

+ In transport_push(), if fail to push a submodule, will die().
+ In git_transport_push(), will die() for an unimplemented v2 protocol.
+ In send_pack(), will die() if
the server side has an incompatible hash algorithm, or
the receiving end does not support --signed push, or
the receiving end does not support --atomic push, or
the receiving end does not support push options

Sure, but it seems that those are not covered in thet 5411.

You can build Git with the patch below, run t5411 with '-V -x', and then look through all the cases to see where 'git push' waited or did not wait for its 'git receive-pack' child process.

run-command.c +1 -0
index ea4d0fb4b1..4accdb343e 100644
@@ -988,6 +988,7 @@ int start_command(struct child_process *cmd)
 int finish_command(struct child_process *cmd)
 {
 	int ret = wait_or_whine(cmd->pid, cmd->argv[0], 0);
+	dprintf(3, "finish_command(): '%s'\n", cmd->argv[0]);
 	trace2_child_exit(cmd, ret);
 	child_process_clear(cmd);
 	return ret;
author
#175 lore raw

PATCH v2 1/2 t5411: remove file after use to prevent overwriting

In reply to SZEDER Gábor

From: Jiang Xin <[email protected]>

SZEDER reported that t5411 failed in Travis CI's s390x environment a couple of times, and could be reproduced with '--stress' test on this specific environment. The test failure messages might look like this:

+ test_cmp expect actual
--- expect 2021-01-17 21:55:23.430750004 +0000
+++ actual 2021-01-17 21:55:23.430750004 +0000
@@ -1 +1 @@
-<COMMIT-A> refs/heads/main
+<COMMIT-A> refs/heads/maifatal: the remote end hung up unexpectedly
error: last command exited with $?=1
not ok 86 - proc-receive: not support push options (builtin protocol)

The file 'actual' is filtered from the file 'out' which contains result of 'git show-ref' command. Due to the error messages from other process is written into the file 'out' accidentally, t5411 failed. SZEDER finds the root cause of this issue:

- 'git push' is executed with its standard output and error redirected to the file 'out'.

- 'git push' executes 'git receive-pack' internally, which inherits the open file descriptors, so its output and error goes into that same 'out' file.

- 'git push' ends without waiting for the close of 'git-receive-pack' for some cases, and the file 'out' is reused for test of 'git show-ref' afterwards.

- A mixture of the output of 'git show-ref' abd 'git receive-pack' leads to this issue.

To resolve this issue, we can remove the file 'out' after use. The long-running 'git receive-pack' will not redirect its output to the new created 'out' file which has a different file descriptor.

---
 t/t5411/test-0000-standard-git-push.sh         |  4 ++++
 .../test-0001-standard-git-push--porcelain.sh  |  4 ++++
 t/t5411/test-0002-pre-receive-declined.sh      |  2 ++
 ...est-0003-pre-receive-declined--porcelain.sh |  2 ++
 t/t5411/test-0011-no-hook-error.sh             |  4 ++++
 t/t5411/test-0012-no-hook-error--porcelain.sh  |  4 ++++
 t/t5411/test-0013-bad-protocol.sh              | 18 ++++++++++++++++++
 t/t5411/test-0014-bad-protocol--porcelain.sh   | 18 ++++++++++++++++++
 t/t5411/test-0020-report-ng.sh                 |  4 ++++
 t/t5411/test-0021-report-ng--porcelain.sh      |  4 ++++
 t/t5411/test-0022-report-unexpect-ref.sh       |  2 ++
 ...test-0023-report-unexpect-ref--porcelain.sh |  2 ++
 t/t5411/test-0024-report-unknown-ref.sh        |  2 ++
 .../test-0025-report-unknown-ref--porcelain.sh |  2 ++
 t/t5411/test-0026-push-options.sh              |  2 ++
 t/t5411/test-0027-push-options--porcelain.sh   |  2 ++
 t/t5411/test-0032-report-with-options.sh       |  2 ++
 ...test-0033-report-with-options--porcelain.sh |  2 ++
 t/t5411/test-0038-report-mixed-refs.sh         |  2 ++
 .../test-0039-report-mixed-refs--porcelain.sh  |  2 ++
 20 files changed, 84 insertions(+)
t/t5411/test-0000-standard-git-push.sh +4 -0
index 47b058af7e..694d8e8dc2 100644
@@ -40,6 +40,8 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
 		-e "/^To / { p; }" \
 		-e "/^ ! / { p; }" \
 		<out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	 ! [rejected] main -> main (non-fast-forward)
@@ -67,6 +69,8 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL)" '
 		$B:refs/heads/next \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/next
t/t5411/test-0001-standard-git-push--porcelain.sh +4 -0
index bbead12bbb..6cf0bc7034 100644
@@ -42,6 +42,8 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
 		-e "/^To / { p; }" \
 		-e "/^! / { p; }" \
 		<out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	!    refs/heads/main:refs/heads/main    [rejected] (non-fast-forward)
@@ -69,6 +71,8 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL/porcelain)" '
 		$B:refs/heads/next \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/next
t/t5411/test-0002-pre-receive-declined.sh +2 -0
index e7d113a158..61c3ee1b7f 100644
@@ -14,6 +14,8 @@ test_expect_success "git-push is declined ($PROTOCOL)" '
 		HEAD:refs/heads/next \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	 ! [remote rejected] <COMMIT-B> -> main (pre-receive hook declined)
t/t5411/test-0003-pre-receive-declined--porcelain.sh +2 -0
index cc0cca6a47..0a9cc2d44a 100644
@@ -14,6 +14,8 @@ test_expect_success "git-push is declined ($PROTOCOL/porcelain)" '
 		HEAD:refs/heads/next \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	!    <COMMIT-B>:refs/heads/main    [remote rejected] (pre-receive hook declined)
t/t5411/test-0011-no-hook-error.sh +4 -0
index c50830982f..fd2bd20b76 100644
@@ -7,6 +7,8 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL)
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
@@ -43,6 +45,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
 		HEAD:next \
 		HEAD:refs/for/main/topic >out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0012-no-hook-error--porcelain.sh +4 -0
index 14ea433481..025a9c7186 100644
@@ -7,6 +7,8 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL/
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
@@ -44,6 +46,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
 		HEAD:next \
 		HEAD:refs/for/main/topic >out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0013-bad-protocol.sh +18 -0
index b9be12be77..d20a4e6681 100644
@@ -13,6 +13,8 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL)" '
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 
 	# Check status report for git-push
 	sed -n \
@@ -67,6 +69,8 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTO
 	test_cmp expect actual &&
 	grep "remote: fatal: die with the --die-read-version option" out &&
 	grep "remote: error: fail to negotiate version with proc-receive hook" out &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 
 	git -C "$upstream" show-ref >out &&
 	make_user_friendly_and_stable_output <out >actual &&
@@ -101,6 +105,8 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROT
 	test_cmp expect actual &&
 	grep "remote: fatal: die with the --die-write-version option" out &&
 	grep "remote: error: fail to negotiate version with proc-receive hook" out &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 
 	git -C "$upstream" show-ref >out &&
 	make_user_friendly_and_stable_output <out >actual &&
@@ -134,6 +140,8 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROT
 	EOF
 	test_cmp expect actual &&
 	grep "remote: fatal: die with the --die-read-commands option" out &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 
 	git -C "$upstream" show-ref >out &&
 	make_user_friendly_and_stable_output <out >actual &&
@@ -169,6 +177,8 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $
 	EOF
 	test_cmp expect actual &&
 	grep "remote: fatal: die with the --die-read-push-options option" out &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 
 	git -C "$upstream" show-ref >out &&
 	make_user_friendly_and_stable_output <out >actual &&
@@ -202,6 +212,8 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTO
 	EOF
 	test_cmp expect actual &&
 	grep "remote: fatal: die with the --die-write-report option" out &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 
 	git -C "$upstream" show-ref >out &&
 	make_user_friendly_and_stable_output <out >actual &&
@@ -226,6 +238,8 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL)" '
 		HEAD:refs/heads/next \
 		HEAD:refs/for/main/topic >out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
@@ -272,6 +286,8 @@ test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL)" '
 		HEAD:refs/for/main/topic\
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
@@ -308,6 +324,8 @@ test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL)" '
 			HEAD:refs/for/main/topic \
 			>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0014-bad-protocol--porcelain.sh +18 -0
index fdb4569109..a286030f3e 100644
@@ -13,6 +13,8 @@ test_expect_success "proc-receive: bad protocol (unknown version, $PROTOCOL/porc
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 
 	# Check status report for git-push
 	sed -n \
@@ -67,6 +69,8 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-version, $PROTO
 	test_cmp expect actual &&
 	grep "remote: fatal: die with the --die-read-version option" out &&
 	grep "remote: error: fail to negotiate version with proc-receive hook" out &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 
 	git -C "$upstream" show-ref >out &&
 	make_user_friendly_and_stable_output <out >actual &&
@@ -101,6 +105,8 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-version, $PROT
 	test_cmp expect actual &&
 	grep "remote: fatal: die with the --die-write-version option" out &&
 	grep "remote: error: fail to negotiate version with proc-receive hook" out &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 
 	git -C "$upstream" show-ref >out &&
 	make_user_friendly_and_stable_output <out >actual &&
@@ -134,6 +140,8 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-commands, $PROT
 	EOF
 	test_cmp expect actual &&
 	grep "remote: fatal: die with the --die-read-commands option" out &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 
 	git -C "$upstream" show-ref >out &&
 	make_user_friendly_and_stable_output <out >actual &&
@@ -169,6 +177,8 @@ test_expect_success "proc-receive: bad protocol (hook --die-read-push-options, $
 	EOF
 	test_cmp expect actual &&
 	grep "remote: fatal: die with the --die-read-push-options option" out &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 
 	git -C "$upstream" show-ref >out &&
 	make_user_friendly_and_stable_output <out >actual &&
@@ -202,6 +212,8 @@ test_expect_success "proc-receive: bad protocol (hook --die-write-report, $PROTO
 	EOF
 	test_cmp expect actual &&
 	grep "remote: fatal: die with the --die-write-report option" out &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 
 	git -C "$upstream" show-ref >out &&
 	make_user_friendly_and_stable_output <out >actual &&
@@ -226,6 +238,8 @@ test_expect_success "proc-receive: bad protocol (no report, $PROTOCOL/porcelain)
 		HEAD:refs/heads/next \
 		HEAD:refs/for/main/topic >out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
@@ -272,6 +286,8 @@ test_expect_success "proc-receive: bad protocol (no ref, $PROTOCOL/porcelain)" '
 		HEAD:refs/for/main/topic\
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
@@ -309,6 +325,8 @@ test_expect_success "proc-receive: bad protocol (unknown status, $PROTOCOL/porce
 			HEAD:refs/for/main/topic \
 			>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0020-report-ng.sh +4 -0
index 5a9e0daf2d..9f71da9fb6 100644
@@ -14,6 +14,8 @@ test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL)" '
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
@@ -48,6 +50,8 @@ test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL)"
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0021-report-ng--porcelain.sh +4 -0
index 93475a83cf..96065e3537 100644
@@ -14,6 +14,8 @@ test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL/por
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
@@ -49,6 +51,8 @@ test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL/p
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0022-report-unexpect-ref.sh +2 -0
index f8be8a0ba1..624dda7acc 100644
@@ -15,6 +15,8 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL)" '
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0023-report-unexpect-ref--porcelain.sh +2 -0
index 778150fa03..dcb804afc8 100644
@@ -15,6 +15,8 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL/porcelain)"
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0024-report-unknown-ref.sh +2 -0
index d4e74e4681..af65355862 100644
@@ -14,6 +14,8 @@ test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" '
 		HEAD:refs/for/a/b/c/my/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
t/t5411/test-0025-report-unknown-ref--porcelain.sh +2 -0
index 039e8b6163..c336ec0e98 100644
@@ -14,6 +14,8 @@ test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain
 		HEAD:refs/for/a/b/c/my/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
t/t5411/test-0026-push-options.sh +2 -0
index e88edb16a4..46b1064fe6 100644
@@ -18,6 +18,8 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
 	git -C "$upstream" show-ref >out &&
t/t5411/test-0027-push-options--porcelain.sh +2 -0
index 3a6561b5ea..79a49a638e 100644
@@ -19,6 +19,8 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
 	git -C "$upstream" show-ref >out &&
t/t5411/test-0032-report-with-options.sh +2 -0
index a0faf5c7ff..4d058cc6ff 100644
@@ -15,6 +15,8 @@ test_expect_success "proc-receive: report option without matching ok ($PROTOCOL)
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0033-report-with-options--porcelain.sh +2 -0
index 32ae26bcfb..8ab908a6b0 100644
@@ -15,6 +15,8 @@ test_expect_success "proc-receive: report option without matching ok ($PROTOCOL/
 		HEAD:refs/for/main/topic \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0038-report-mixed-refs.sh +2 -0
index 0d071ebaa6..264a5d5c6d 100644
@@ -26,6 +26,8 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
 		HEAD:refs/for/next/topic3 \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0039-report-mixed-refs--porcelain.sh +2 -0
index d8409912fd..1e9c06d2b7 100644
@@ -26,6 +26,8 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
 		HEAD:refs/for/next/topic3 \
 		>out 2>&1 &&
 	make_user_friendly_and_stable_output <out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
Signature · 1 line
2.28.0.15.gba9e81f0bd
#176 lore raw

Re: [PATCH 1/2] t5411: remove file after use to prevent overwriting

Am 18.01.21 um 14:30 schrieb Jiang Xin:

Quoted 31 lines

From: Jiang Xin <[email protected]>

SZEDER reported that t5411 failed in Travis CI's s390x environment a couple of times, and could be reproduced with '--stress' test on this specific environment. The test failure messages might look like this:

+ test_cmp expect actual
--- expect 2021-01-17 21:55:23.430750004 +0000
+++ actual 2021-01-17 21:55:23.430750004 +0000
@@ -1 +1 @@
-<COMMIT-A> refs/heads/main
+<COMMIT-A> refs/heads/maifatal: the remote end hung up unexpectedly
error: last command exited with $?=1
not ok 86 - proc-receive: not support push options (builtin protocol)

The file 'actual' is filtered from the file 'out' which contains result of 'git show-ref' command. Due to the error messages from other process is written into the file 'out' accidentally, t5411 failed. SZEDER finds the root cause of this issue:

- 'git push' is executed with its standard output and error redirected to the file 'out'.

- 'git push' executes 'git receive-pack' internally, which inherits the open file descriptors, so its output and error goes into that same 'out' file.

- 'git push' ends without waiting for the close of 'git-receive-pack' for some cases, and the file 'out' is reused for test of 'git show-ref' afterwards.

Quoted 6 lines

- A mixture of the output of 'git show-ref' abd 'git receive-pack' leads to this issue.

To resolve this issue, we can remove the file 'out' after use. The long-running 'git receive-pack' will not redirect its output to the new created 'out' file which has a different file descriptor.

On Windows, removing an open file is not possible and this...

t/t5411/test-0000-standard-git-push.sh test_expect_success "git-push --atomic ($PROTOCOL)" ' · line 44

Quoted 10 lines
t/t5411/test-0000-standard-git-push.sh +2 -0
index 47b058af7e..694d8e8dc2 100644
@@ -40,6 +40,8 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
 		-e "/^To / { p; }" \
 		-e "/^ ! / { p; }" \
 		<out >actual &&
+	# Prevent accidential changes by the internal "receive-pack" process.
+	rm out &&

... would fail.

That said, your next patch removes a lot of uses of the 'out' file against which this 'rm out' should protect. Doesn't this make this patch unnecessary?

t/t5411/test-0000-standard-git-push.sh test_expect_success "git-push --atomic ($PROTOCOL)" ' · line 47

Quoted 3 lines
t/t5411/test-0000-standard-git-push.sh +0 -0
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	 ! [rejected] main -> main (non-fast-forward)

-- Hannes

author
#177 lore raw

Re: [PATCH 1/2] t5411: remove file after use to prevent overwriting

Quoted 42 lines · Johannes Sixt <[email protected]> 于2021年1月19日周二 上午2:21写道:

Am 18.01.21 um 14:30 schrieb Jiang Xin:

Quoted 31 lines

From: Jiang Xin <[email protected]>

SZEDER reported that t5411 failed in Travis CI's s390x environment a couple of times, and could be reproduced with '--stress' test on this specific environment. The test failure messages might look like this:

+ test_cmp expect actual
--- expect 2021-01-17 21:55:23.430750004 +0000
+++ actual 2021-01-17 21:55:23.430750004 +0000
@@ -1 +1 @@
-<COMMIT-A> refs/heads/main
+<COMMIT-A> refs/heads/maifatal: the remote end hung up unexpectedly
error: last command exited with $?=1
not ok 86 - proc-receive: not support push options (builtin protocol)

The file 'actual' is filtered from the file 'out' which contains result of 'git show-ref' command. Due to the error messages from other process is written into the file 'out' accidentally, t5411 failed. SZEDER finds the root cause of this issue:

- 'git push' is executed with its standard output and error redirected to the file 'out'.

- 'git push' executes 'git receive-pack' internally, which inherits the open file descriptors, so its output and error goes into that same 'out' file.

- 'git push' ends without waiting for the close of 'git-receive-pack' for some cases, and the file 'out' is reused for test of 'git show-ref' afterwards.

Quoted 6 lines

- A mixture of the output of 'git show-ref' abd 'git receive-pack' leads to this issue.

To resolve this issue, we can remove the file 'out' after use. The long-running 'git receive-pack' will not redirect its output to the new created 'out' file which has a different file descriptor.

On Windows, removing an open file is not possible and this...

Quoted 12 lines

t/t5411/test-0000-standard-git-push.sh test_expect_success "git-push --atomic ($PROTOCOL)" ' · line 44

Quoted 10 lines
t/t5411/test-0000-standard-git-push.sh +2 -0
index 47b058af7e..694d8e8dc2 100644
@@ -40,6 +40,8 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
              -e "/^To / { p; }" \
              -e "/^ ! / { p; }" \
              <out >actual &&
+     # Prevent accidential changes by the internal "receive-pack" process.
+     rm out &&

... would fail.

Thank you for reminding. It seems that the only way is to use a different output file name.

Quoted 3 lines

That said, your next patch removes a lot of uses of the 'out' file against which this 'rm out' should protect. Doesn't this make this patch unnecessary?

The other test cases also write to the same "out" file, so the issue still needs to be fixed.

--
Jiang Xin

author
#178 lore raw

PATCH v2 1/2 t5411: use different out file to prevent overwriting

In reply to Johannes Sixt

From: Jiang Xin <[email protected]>

SZEDER reported that t5411 failed in Travis CI's s390x environment a couple of times, and could be reproduced with '--stress' test on this specific environment. The test failure messages might look like this:

+ test_cmp expect actual
--- expect 2021-01-17 21:55:23.430750004 +0000
+++ actual 2021-01-17 21:55:23.430750004 +0000
@@ -1 +1 @@
-<COMMIT-A> refs/heads/main
+<COMMIT-A> refs/heads/maifatal: the remote end hung up unexpectedly
error: last command exited with $?=1
not ok 86 - proc-receive: not support push options (builtin protocol)

The file 'actual' is filtered from the file 'out' which contains result of 'git show-ref' command. Due to the error messages from other process is written into the file 'out' accidentally, t5411 failed. SZEDER finds the root cause of this issue:

- 'git push' is executed with its standard output and error redirected to the file 'out'.

- 'git push' executes 'git receive-pack' internally, which inherits the open file descriptors, so its output and error goes into that same 'out' file.

- 'git push' ends without waiting for the close of 'git-receive-pack' for some cases, and the file 'out' is reused for test of 'git show-ref' afterwards.

- A mixture of the output of 'git show-ref' abd 'git receive-pack' leads to this issue.

The first intuitive reaction to resolve this issue is to remove the file 'out' after use, so that the newly created file 'out' will have a different file descriptor and will not be overwritten by the 'git receive-pack' process. But Johannes pointed out that removing an open file is not possible on Windows. So we use different temporary file names to store the output of 'git push' to solve this issue.

---
 t/t5411/test-0000-standard-git-push.sh        |  8 +--
 .../test-0001-standard-git-push--porcelain.sh |  8 +--
 t/t5411/test-0002-pre-receive-declined.sh     |  4 +-
 ...st-0003-pre-receive-declined--porcelain.sh |  4 +-
 t/t5411/test-0011-no-hook-error.sh            |  8 +--
 t/t5411/test-0012-no-hook-error--porcelain.sh |  8 +--
 t/t5411/test-0013-bad-protocol.sh             | 50 +++++++++----------
 t/t5411/test-0014-bad-protocol--porcelain.sh  | 50 +++++++++----------
 t/t5411/test-0020-report-ng.sh                |  8 +--
 t/t5411/test-0021-report-ng--porcelain.sh     |  8 +--
 t/t5411/test-0022-report-unexpect-ref.sh      |  4 +-
 ...est-0023-report-unexpect-ref--porcelain.sh |  4 +-
 t/t5411/test-0024-report-unknown-ref.sh       |  4 +-
 ...test-0025-report-unknown-ref--porcelain.sh |  4 +-
 t/t5411/test-0026-push-options.sh             |  4 +-
 t/t5411/test-0027-push-options--porcelain.sh  |  4 +-
 t/t5411/test-0032-report-with-options.sh      |  4 +-
 ...est-0033-report-with-options--porcelain.sh |  4 +-
 t/t5411/test-0038-report-mixed-refs.sh        |  4 +-
 .../test-0039-report-mixed-refs--porcelain.sh |  4 +-
 20 files changed, 98 insertions(+), 98 deletions(-)
t/t5411/test-0000-standard-git-push.sh +4 -4
index 47b058af7e..b074417d4b 100644
@@ -35,11 +35,11 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
 	test_must_fail git -C workbench push --atomic origin \
 		main \
 		$B:refs/heads/next \
-		>out 2>&1 &&
+		>out-0000-1 2>&1 &&
 	filter_out_user_friendly_and_stable_output \
 		-e "/^To / { p; }" \
 		-e "/^ ! / { p; }" \
-		<out >actual &&
+		<out-0000-1 >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	 ! [rejected] main -> main (non-fast-forward)
@@ -65,8 +65,8 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL)" '
 		push origin \
 		main \
 		$B:refs/heads/next \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0000-2 2>&1 &&
+	make_user_friendly_and_stable_output <out-0000-2 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/next
t/t5411/test-0001-standard-git-push--porcelain.sh +4 -4
index bbead12bbb..8a0de5cac8 100644
@@ -36,12 +36,12 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
 	test_must_fail git -C workbench push --atomic --porcelain origin \
 		main \
 		$B:refs/heads/next \
-		>out 2>&1 &&
+		>out-0001-1 2>&1 &&
 	filter_out_user_friendly_and_stable_output \
 		-e "s/^# GETTEXT POISON #//" \
 		-e "/^To / { p; }" \
 		-e "/^! / { p; }" \
-		<out >actual &&
+		<out-0001-1 >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	!    refs/heads/main:refs/heads/main    [rejected] (non-fast-forward)
@@ -67,8 +67,8 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL/porcelain)" '
 		push --porcelain origin \
 		main \
 		$B:refs/heads/next \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0001-2 2>&1 &&
+	make_user_friendly_and_stable_output <out-0001-2 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/next
t/t5411/test-0002-pre-receive-declined.sh +2 -2
index e7d113a158..83edcb037b 100644
@@ -12,8 +12,8 @@ test_expect_success "git-push is declined ($PROTOCOL)" '
 	test_must_fail git -C workbench push origin \
 		$B:refs/heads/main \
 		HEAD:refs/heads/next \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0002-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0002-1 >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	 ! [remote rejected] <COMMIT-B> -> main (pre-receive hook declined)
t/t5411/test-0003-pre-receive-declined--porcelain.sh +2 -2
index cc0cca6a47..8f3bbeccca 100644
@@ -12,8 +12,8 @@ test_expect_success "git-push is declined ($PROTOCOL/porcelain)" '
 	test_must_fail git -C workbench push --porcelain origin \
 		$B:refs/heads/main \
 		HEAD:refs/heads/next \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0003-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0003-1 >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	!    <COMMIT-B>:refs/heads/main    [remote rejected] (pre-receive hook declined)
t/t5411/test-0011-no-hook-error.sh +4 -4
index c50830982f..11c85a32d5 100644
@@ -5,8 +5,8 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL)
 	test_must_fail git -C workbench push origin \
 		HEAD:next \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0011-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0011-1 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
@@ -41,8 +41,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
 	test_must_fail git -C workbench push --atomic origin \
 		$B:main \
 		HEAD:next \
-		HEAD:refs/for/main/topic >out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		HEAD:refs/for/main/topic >out-0011-2 2>&1 &&
+	make_user_friendly_and_stable_output <out-0011-2 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0012-no-hook-error--porcelain.sh +4 -4
index 14ea433481..f89754b480 100644
@@ -5,8 +5,8 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL/
 	test_must_fail git -C workbench push --porcelain origin \
 		HEAD:next \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0012-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0012-1 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
@@ -42,8 +42,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
 	test_must_fail git -C workbench push --porcelain --atomic origin \
 		$B:main \
 		HEAD:next \
-		HEAD:refs/for/main/topic >out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		HEAD:refs/for/main/topic >out-0012-2 2>&1 &&
+	make_user_friendly_and_stable_output <out-0012-2 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0013-bad-protocol.sh +25 -25

144 lines not on this page · raw message

t/t5411/test-0014-bad-protocol--porcelain.sh +25 -25

144 lines not on this page · raw message

t/t5411/test-0020-report-ng.sh +4 -4
index 5a9e0daf2d..41efafc55e 100644
@@ -12,8 +12,8 @@ test_expect_success "setup proc-receive hook (ng, no message, $PROTOCOL)" '
 test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL)" '
 	test_must_fail git -C workbench push origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0020-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0020-1 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
@@ -46,8 +46,8 @@ test_expect_success "setup proc-receive hook (ng message, $PROTOCOL)" '
 test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL)" '
 	test_must_fail git -C workbench push origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0020-2 2>&1 &&
+	make_user_friendly_and_stable_output <out-0020-2 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0021-report-ng--porcelain.sh +4 -4
index 93475a83cf..65b22618cc 100644
@@ -12,8 +12,8 @@ test_expect_success "setup proc-receive hook (ng, no message, $PROTOCOL/porcelai
 test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL/porcelain)" '
 	test_must_fail git -C workbench push --porcelain origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0021-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0021-1 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
@@ -47,8 +47,8 @@ test_expect_success "setup proc-receive hook (ng message, $PROTOCOL/porcelain)"
 test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL/porcelain)" '
 	test_must_fail git -C workbench push --porcelain origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0021-2 2>&1 &&
+	make_user_friendly_and_stable_output <out-0021-2 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0022-report-unexpect-ref.sh +2 -2
index f8be8a0ba1..4cbd474678 100644
@@ -13,8 +13,8 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL)" '
 	test_must_fail git -C workbench push origin \
 		$B:refs/heads/main \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0022-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0022-1 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0023-report-unexpect-ref--porcelain.sh +2 -2
index 778150fa03..7804b87721 100644
@@ -13,8 +13,8 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL/porcelain)"
 	test_must_fail git -C workbench push --porcelain origin \
 		$B:refs/heads/main \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0023-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0023-1 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0024-report-unknown-ref.sh +2 -2
index d4e74e4681..a048cb0f02 100644
@@ -12,8 +12,8 @@ test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" '
 test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" '
 	test_must_fail git -C workbench push origin \
 		HEAD:refs/for/a/b/c/my/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0024-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0024-1 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
t/t5411/test-0025-report-unknown-ref--porcelain.sh +2 -2
index 039e8b6163..b3c4fe6330 100644
@@ -12,8 +12,8 @@ test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL/porcelai
 test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain)" '
 	test_must_fail git -C workbench push --porcelain origin \
 		HEAD:refs/for/a/b/c/my/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0025-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0025-1 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
t/t5411/test-0026-push-options.sh +2 -2
index e88edb16a4..7bc627cee6 100644
@@ -16,8 +16,8 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
 		-o reviewer=user1 \
 		origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0026-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0026-1 >actual &&
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
 	git -C "$upstream" show-ref >out &&
t/t5411/test-0027-push-options--porcelain.sh +2 -2
index 3a6561b5ea..5b4884a260 100644
@@ -17,8 +17,8 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain
 		-o reviewer=user1 \
 		origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0027-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0027-1 >actual &&
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
 	git -C "$upstream" show-ref >out &&
t/t5411/test-0032-report-with-options.sh +2 -2
index a0faf5c7ff..f5c67a1cc3 100644
@@ -13,8 +13,8 @@ test_expect_success "setup proc-receive hook (option without matching ok, $PROTO
 test_expect_success "proc-receive: report option without matching ok ($PROTOCOL)" '
 	test_must_fail git -C workbench push origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0032-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0032-1 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0033-report-with-options--porcelain.sh +2 -2
index 32ae26bcfb..35e785a0fb 100644
@@ -13,8 +13,8 @@ test_expect_success "setup proc-receive hook (option without matching ok, $PROTO
 test_expect_success "proc-receive: report option without matching ok ($PROTOCOL/porcelain)" '
 	test_must_fail git -C workbench push --porcelain origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0033-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0033-1 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0038-report-mixed-refs.sh +2 -2
index 0d071ebaa6..0c31447aaa 100644
@@ -24,8 +24,8 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
 		HEAD:refs/heads/foo \
 		HEAD:refs/for/main/topic \
 		HEAD:refs/for/next/topic3 \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0038-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0038-1 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0039-report-mixed-refs--porcelain.sh +2 -2
index d8409912fd..7007dd98fc 100644
@@ -24,8 +24,8 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
 		HEAD:refs/heads/foo \
 		HEAD:refs/for/main/topic \
 		HEAD:refs/for/next/topic3 \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0039-1 2>&1 &&
+	make_user_friendly_and_stable_output <out-0039-1 >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
Signature · 1 line
2.28.0.15.gba9e81f0bd
#179 lore raw

Re: [PATCH v2 1/2] t5411: use different out file to prevent overwriting

Quoted 58 lines · Jiang Xin

From: Jiang Xin <[email protected]>

SZEDER reported that t5411 failed in Travis CI's s390x environment a couple of times, and could be reproduced with '--stress' test on this specific environment. The test failure messages might look like this:

+ test_cmp expect actual
--- expect 2021-01-17 21:55:23.430750004 +0000
+++ actual 2021-01-17 21:55:23.430750004 +0000
@@ -1 +1 @@
-<COMMIT-A> refs/heads/main
+<COMMIT-A> refs/heads/maifatal: the remote end hung up unexpectedly
error: last command exited with $?=1
not ok 86 - proc-receive: not support push options (builtin protocol)

The file 'actual' is filtered from the file 'out' which contains result of 'git show-ref' command. Due to the error messages from other process is written into the file 'out' accidentally, t5411 failed. SZEDER finds the root cause of this issue:

- 'git push' is executed with its standard output and error redirected to the file 'out'.

- 'git push' executes 'git receive-pack' internally, which inherits the open file descriptors, so its output and error goes into that same 'out' file.

- 'git push' ends without waiting for the close of 'git-receive-pack' for some cases, and the file 'out' is reused for test of 'git show-ref' afterwards.

- A mixture of the output of 'git show-ref' abd 'git receive-pack' leads to this issue.

The first intuitive reaction to resolve this issue is to remove the file 'out' after use, so that the newly created file 'out' will have a different file descriptor and will not be overwritten by the 'git receive-pack' process. But Johannes pointed out that removing an open file is not possible on Windows. So we use different temporary file names to store the output of 'git push' to solve this issue.

---
 t/t5411/test-0000-standard-git-push.sh        |  8 +--
 .../test-0001-standard-git-push--porcelain.sh |  8 +--
 t/t5411/test-0002-pre-receive-declined.sh     |  4 +-
 ...st-0003-pre-receive-declined--porcelain.sh |  4 +-
 t/t5411/test-0011-no-hook-error.sh            |  8 +--
 t/t5411/test-0012-no-hook-error--porcelain.sh |  8 +--
 t/t5411/test-0013-bad-protocol.sh             | 50 +++++++++----------
 t/t5411/test-0014-bad-protocol--porcelain.sh  | 50 +++++++++----------
 t/t5411/test-0020-report-ng.sh                |  8 +--
 t/t5411/test-0021-report-ng--porcelain.sh     |  8 +--
 t/t5411/test-0022-report-unexpect-ref.sh      |  4 +-
 ...est-0023-report-unexpect-ref--porcelain.sh |  4 +-
 t/t5411/test-0024-report-unknown-ref.sh       |  4 +-
Quoted 8 lines
 ...test-0025-report-unknown-ref--porcelain.sh |  4 +-
 t/t5411/test-0026-push-options.sh             |  4 +-
 t/t5411/test-0027-push-options--porcelain.sh  |  4 +-
 t/t5411/test-0032-report-with-options.sh      |  4 +-
 ...est-0033-report-with-options--porcelain.sh |  4 +-
 t/t5411/test-0038-report-mixed-refs.sh        |  4 +-
 .../test-0039-report-mixed-refs--porcelain.sh |  4 +-
 20 files changed, 98 insertions(+), 98 deletions(-)

Wow, this is a lot of churn.

Would it be possible/desirable to die gracefully when the receiving end doesn't support push options?

Quoted 19 lines
t/t5411/test-0000-standard-git-push.sh +2 -2
index 47b058af7e..b074417d4b 100644
@@ -35,11 +35,11 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
 	test_must_fail git -C workbench push --atomic origin \
 		main \
 		$B:refs/heads/next \
-		>out 2>&1 &&
+		>out-0000-1 2>&1 &&
 	filter_out_user_friendly_and_stable_output \
 		-e "/^To / { p; }" \
 		-e "/^ ! / { p; }" \
-		<out >actual &&
+		<out-0000-1 >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	 ! [rejected] main -> main (non-fast-forward)

t/t5411/test-0000-standard-git-push.sh test_expect_success "non-fast-forward git-push ($PROTOCOL)" ' · line 69

Quoted 7 lines
t/t5411/test-0000-standard-git-push.sh +2 -2
@@ -65,8 +65,8 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL)" '
 		push origin \
 		main \
 		$B:refs/heads/next \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-0000-2 2>&1 &&
+	make_user_friendly_and_stable_output <out-0000-2 >actual &&

There will be a lot of sequential numbers this way, which might lead to additional churn in the future, if we ever were to add more tests somewhere in the middle. However, our test framework does already have a counter for test cases, so we could perhaps use that, i.e. 'out-$test_count', to make sure that each test case has its own output file.

author
#180 lore raw

PATCH v3 1/2 t5411: use different out file to prevent overwriting

From: Jiang Xin <[email protected]>

SZEDER reported that t5411 failed in Travis CI's s390x environment a couple of times, and could be reproduced with '--stress' test on this specific environment. The test failure messages might look like this:

+ test_cmp expect actual
--- expect 2021-01-17 21:55:23.430750004 +0000
+++ actual 2021-01-17 21:55:23.430750004 +0000
@@ -1 +1 @@
-<COMMIT-A> refs/heads/main
+<COMMIT-A> refs/heads/maifatal: the remote end hung up unexpectedly
error: last command exited with $?=1
not ok 86 - proc-receive: not support push options (builtin protocol)

The file 'actual' is filtered from the file 'out' which contains result of 'git show-ref' command. Due to the error messages from other process is written into the file 'out' accidentally, t5411 failed. SZEDER finds the root cause of this issue:

- 'git push' is executed with its standard output and error redirected to the file 'out'.

- 'git push' executes 'git receive-pack' internally, which inherits the open file descriptors, so its output and error goes into that same 'out' file.

- 'git push' ends without waiting for the close of 'git-receive-pack' for some cases, and the file 'out' is reused for test of 'git show-ref' afterwards.

- A mixture of the output of 'git show-ref' abd 'git receive-pack' leads to this issue.

The first intuitive reaction to resolve this issue is to remove the file 'out' after use, so that the newly created file 'out' will have a different file descriptor and will not be overwritten by the 'git receive-pack' process. But Johannes pointed out that removing an open file is not possible on Windows. So we use different temporary file names to store the output of 'git push' to solve this issue.

---
 t/t5411/test-0000-standard-git-push.sh        |  8 +--
 .../test-0001-standard-git-push--porcelain.sh |  8 +--
 t/t5411/test-0002-pre-receive-declined.sh     |  4 +-
 ...st-0003-pre-receive-declined--porcelain.sh |  4 +-
 t/t5411/test-0011-no-hook-error.sh            |  8 +--
 t/t5411/test-0012-no-hook-error--porcelain.sh |  8 +--
 t/t5411/test-0013-bad-protocol.sh             | 50 +++++++++----------
 t/t5411/test-0014-bad-protocol--porcelain.sh  | 50 +++++++++----------
 t/t5411/test-0020-report-ng.sh                |  8 +--
 t/t5411/test-0021-report-ng--porcelain.sh     |  8 +--
 t/t5411/test-0022-report-unexpect-ref.sh      |  4 +-
 ...est-0023-report-unexpect-ref--porcelain.sh |  4 +-
 t/t5411/test-0024-report-unknown-ref.sh       |  4 +-
 ...test-0025-report-unknown-ref--porcelain.sh |  4 +-
 t/t5411/test-0026-push-options.sh             |  4 +-
 t/t5411/test-0027-push-options--porcelain.sh  |  4 +-
 t/t5411/test-0032-report-with-options.sh      |  4 +-
 ...est-0033-report-with-options--porcelain.sh |  4 +-
 t/t5411/test-0038-report-mixed-refs.sh        |  4 +-
 .../test-0039-report-mixed-refs--porcelain.sh |  4 +-
 20 files changed, 98 insertions(+), 98 deletions(-)
t/t5411/test-0000-standard-git-push.sh +4 -4
index 47b058af7e..bdc4907191 100644
@@ -35,11 +35,11 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
 	test_must_fail git -C workbench push --atomic origin \
 		main \
 		$B:refs/heads/next \
-		>out 2>&1 &&
+		>out-$test_count 2>&1 &&
 	filter_out_user_friendly_and_stable_output \
 		-e "/^To / { p; }" \
 		-e "/^ ! / { p; }" \
-		<out >actual &&
+		<out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	 ! [rejected] main -> main (non-fast-forward)
@@ -65,8 +65,8 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL)" '
 		push origin \
 		main \
 		$B:refs/heads/next \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/next
t/t5411/test-0001-standard-git-push--porcelain.sh +4 -4
index bbead12bbb..59630ef7e5 100644
@@ -36,12 +36,12 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
 	test_must_fail git -C workbench push --atomic --porcelain origin \
 		main \
 		$B:refs/heads/next \
-		>out 2>&1 &&
+		>out-$test_count 2>&1 &&
 	filter_out_user_friendly_and_stable_output \
 		-e "s/^# GETTEXT POISON #//" \
 		-e "/^To / { p; }" \
 		-e "/^! / { p; }" \
-		<out >actual &&
+		<out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	!    refs/heads/main:refs/heads/main    [rejected] (non-fast-forward)
@@ -67,8 +67,8 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL/porcelain)" '
 		push --porcelain origin \
 		main \
 		$B:refs/heads/next \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/next
t/t5411/test-0002-pre-receive-declined.sh +2 -2
index e7d113a158..c5c76bfe93 100644
@@ -12,8 +12,8 @@ test_expect_success "git-push is declined ($PROTOCOL)" '
 	test_must_fail git -C workbench push origin \
 		$B:refs/heads/main \
 		HEAD:refs/heads/next \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	 ! [remote rejected] <COMMIT-B> -> main (pre-receive hook declined)
t/t5411/test-0003-pre-receive-declined--porcelain.sh +2 -2
index cc0cca6a47..45050b642a 100644
@@ -12,8 +12,8 @@ test_expect_success "git-push is declined ($PROTOCOL/porcelain)" '
 	test_must_fail git -C workbench push --porcelain origin \
 		$B:refs/heads/main \
 		HEAD:refs/heads/next \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	To <URL/of/upstream.git>
 	!    <COMMIT-B>:refs/heads/main    [remote rejected] (pre-receive hook declined)
t/t5411/test-0011-no-hook-error.sh +4 -4
index c50830982f..77b45b0cbd 100644
@@ -5,8 +5,8 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL)
 	test_must_fail git -C workbench push origin \
 		HEAD:next \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
@@ -41,8 +41,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
 	test_must_fail git -C workbench push --atomic origin \
 		$B:main \
 		HEAD:next \
-		HEAD:refs/for/main/topic >out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		HEAD:refs/for/main/topic >out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0012-no-hook-error--porcelain.sh +4 -4
index 14ea433481..142f4835e4 100644
@@ -5,8 +5,8 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL/
 	test_must_fail git -C workbench push --porcelain origin \
 		HEAD:next \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/heads/next
@@ -42,8 +42,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
 	test_must_fail git -C workbench push --porcelain --atomic origin \
 		$B:main \
 		HEAD:next \
-		HEAD:refs/for/main/topic >out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		HEAD:refs/for/main/topic >out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0013-bad-protocol.sh +25 -25

144 lines not on this page · raw message

t/t5411/test-0014-bad-protocol--porcelain.sh +25 -25

144 lines not on this page · raw message

t/t5411/test-0020-report-ng.sh +4 -4
index 5a9e0daf2d..6618c91841 100644
@@ -12,8 +12,8 @@ test_expect_success "setup proc-receive hook (ng, no message, $PROTOCOL)" '
 test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL)" '
 	test_must_fail git -C workbench push origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
@@ -46,8 +46,8 @@ test_expect_success "setup proc-receive hook (ng message, $PROTOCOL)" '
 test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL)" '
 	test_must_fail git -C workbench push origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0021-report-ng--porcelain.sh +4 -4
index 93475a83cf..44ad1c7de4 100644
@@ -12,8 +12,8 @@ test_expect_success "setup proc-receive hook (ng, no message, $PROTOCOL/porcelai
 test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL/porcelain)" '
 	test_must_fail git -C workbench push --porcelain origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
@@ -47,8 +47,8 @@ test_expect_success "setup proc-receive hook (ng message, $PROTOCOL/porcelain)"
 test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL/porcelain)" '
 	test_must_fail git -C workbench push --porcelain origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0022-report-unexpect-ref.sh +2 -2
index f8be8a0ba1..b0c5a6e168 100644
@@ -13,8 +13,8 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL)" '
 	test_must_fail git -C workbench push origin \
 		$B:refs/heads/main \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0023-report-unexpect-ref--porcelain.sh +2 -2
index 778150fa03..212927b8dc 100644
@@ -13,8 +13,8 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL/porcelain)"
 	test_must_fail git -C workbench push --porcelain origin \
 		$B:refs/heads/main \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0024-report-unknown-ref.sh +2 -2
index d4e74e4681..94ffad55f2 100644
@@ -12,8 +12,8 @@ test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" '
 test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" '
 	test_must_fail git -C workbench push origin \
 		HEAD:refs/for/a/b/c/my/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
t/t5411/test-0025-report-unknown-ref--porcelain.sh +2 -2
index 039e8b6163..8ee7e66472 100644
@@ -12,8 +12,8 @@ test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL/porcelai
 test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain)" '
 	test_must_fail git -C workbench push --porcelain origin \
 		HEAD:refs/for/a/b/c/my/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
t/t5411/test-0026-push-options.sh +2 -2
index e88edb16a4..bb2cf59bdc 100644
@@ -16,8 +16,8 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
 		-o reviewer=user1 \
 		origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
 	git -C "$upstream" show-ref >out &&
t/t5411/test-0027-push-options--porcelain.sh +2 -2
index 3a6561b5ea..54e4f8f1d2 100644
@@ -17,8 +17,8 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain
 		-o reviewer=user1 \
 		origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
 	git -C "$upstream" show-ref >out &&
t/t5411/test-0032-report-with-options.sh +2 -2
index a0faf5c7ff..e6aa0f7018 100644
@@ -13,8 +13,8 @@ test_expect_success "setup proc-receive hook (option without matching ok, $PROTO
 test_expect_success "proc-receive: report option without matching ok ($PROTOCOL)" '
 	test_must_fail git -C workbench push origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0033-report-with-options--porcelain.sh +2 -2
index 32ae26bcfb..a8ca5dd0dd 100644
@@ -13,8 +13,8 @@ test_expect_success "setup proc-receive hook (option without matching ok, $PROTO
 test_expect_success "proc-receive: report option without matching ok ($PROTOCOL/porcelain)" '
 	test_must_fail git -C workbench push --porcelain origin \
 		HEAD:refs/for/main/topic \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/main/topic
t/t5411/test-0038-report-mixed-refs.sh +2 -2
index 0d071ebaa6..286f80d423 100644
@@ -24,8 +24,8 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
 		HEAD:refs/heads/foo \
 		HEAD:refs/for/main/topic \
 		HEAD:refs/for/next/topic3 \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
t/t5411/test-0039-report-mixed-refs--porcelain.sh +2 -2
index d8409912fd..939b8a3b4f 100644
@@ -24,8 +24,8 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
 		HEAD:refs/heads/foo \
 		HEAD:refs/for/main/topic \
 		HEAD:refs/for/next/topic3 \
-		>out 2>&1 &&
-	make_user_friendly_and_stable_output <out >actual &&
+		>out-$test_count 2>&1 &&
+	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	cat >expect <<-EOF &&
 	remote: # pre-receive hook
 	remote: pre-receive< <COMMIT-A> <COMMIT-B> refs/heads/main
Signature · 1 line
2.28.0.15.gba9e81f0bd
author
#181 lore raw

PATCH v3 2/2 t5411: refactor check of refs using test_cmp_refs

In reply to SZEDER Gábor

From: Jiang Xin <[email protected]>

Add new helper 'test_cmp_refs' to check references in a repository.

---
 t/t5411/common-functions.sh                   | 15 +++++++
 t/t5411/once-0010-report-status-v1.sh         |  5 +--
 t/t5411/test-0000-standard-git-push.sh        | 24 ++++------
 .../test-0001-standard-git-push--porcelain.sh | 24 ++++------
 t/t5411/test-0002-pre-receive-declined.sh     |  6 +--
 ...st-0003-pre-receive-declined--porcelain.sh |  6 +--
 t/t5411/test-0011-no-hook-error.sh            | 12 ++---
 t/t5411/test-0012-no-hook-error--porcelain.sh | 12 ++---
 t/t5411/test-0013-bad-protocol.sh             | 45 ++++---------------
 t/t5411/test-0014-bad-protocol--porcelain.sh  | 45 ++++---------------
 t/t5411/test-0020-report-ng.sh                | 12 ++---
 t/t5411/test-0021-report-ng--porcelain.sh     | 12 ++---
 t/t5411/test-0022-report-unexpect-ref.sh      |  6 +--
 ...est-0023-report-unexpect-ref--porcelain.sh |  6 +--
 t/t5411/test-0024-report-unknown-ref.sh       |  6 +--
 ...test-0025-report-unknown-ref--porcelain.sh |  6 +--
 t/t5411/test-0026-push-options.sh             | 18 +++-----
 t/t5411/test-0027-push-options--porcelain.sh  | 18 +++-----
 t/t5411/test-0030-report-ok.sh                |  6 +--
 t/t5411/test-0031-report-ok--porcelain.sh     |  6 +--
 t/t5411/test-0032-report-with-options.sh      |  5 +--
 ...est-0033-report-with-options--porcelain.sh |  5 +--
 t/t5411/test-0034-report-ft.sh                |  6 +--
 t/t5411/test-0035-report-ft--porcelain.sh     |  6 +--
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 18 +++-----
 ...rt-multi-rewrite-for-one-ref--porcelain.sh | 18 +++-----
 t/t5411/test-0038-report-mixed-refs.sh        |  6 +--
 .../test-0039-report-mixed-refs--porcelain.sh |  6 +--
 t/t5411/test-0040-process-all-refs.sh         |  6 +--
 .../test-0041-process-all-refs--porcelain.sh  |  6 +--
 ...t-0050-proc-receive-refs-with-modifiers.sh | 18 +++-----
 31 files changed, 126 insertions(+), 264 deletions(-)
t/t5411/common-functions.sh +15 -0
index 344d13f61a..4835dd5182 100644
@@ -59,3 +59,18 @@ filter_out_user_friendly_and_stable_output () {
 	make_user_friendly_and_stable_output |
 		sed -n ${1+"$@"}
 }
+
+test_cmp_refs () {
+	indir=
+	if test "$1" = "-C"
+	then
+		shift
+		indir="$1"
+		shift
+	fi
+	indir=${indir:+"$indir"/}
+	cat >show-ref.expect &&
+	git ${indir:+ -C "$indir"} show-ref >show-ref.pristine &&
+	make_user_friendly_and_stable_output <show-ref.pristine >show-ref.filtered &&
+	test_cmp show-ref.expect show-ref.filtered
+}
t/t5411/once-0010-report-status-v1.sh +1 -4
index cb431a9c91..1233a46eac 100644
@@ -83,12 +83,9 @@ test_expect_success "proc-receive: report status v1" '
 	EOF
 	test_cmp expect actual &&
 
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/for/main/topic1
 	<COMMIT-A> refs/heads/foo
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0000-standard-git-push.sh +8 -16
index bdc4907191..e1e0175c12 100644
@@ -19,13 +19,11 @@ test_expect_success "git-push ($PROTOCOL)" '
 	 * [new branch] HEAD -> next
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(A)
@@ -46,13 +44,11 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
 	 ! [rejected] <COMMIT-B> -> next (atomic push failed)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(A)
@@ -77,13 +73,11 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL)" '
 	 ! [rejected] main -> main (non-fast-forward)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-B> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(B)
@@ -119,15 +113,13 @@ test_expect_success "git-push -f ($PROTOCOL)" '
 	 * [new branch] HEAD -> a/b/c
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/a/b/c
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/review/main/topic
 	<TAG-v123> refs/tags/v123
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)  tags/v123  refs/review/main/topic(A)  a/b/c(A)
t/t5411/test-0001-standard-git-push--porcelain.sh +8 -16
index 59630ef7e5..bcbda72341 100644
@@ -20,13 +20,11 @@ test_expect_success "git-push ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(A)
@@ -48,13 +46,11 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
 	!    <COMMIT-B>:refs/heads/next    [rejected] (atomic push failed)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(A)
@@ -80,13 +76,11 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-B> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(B)
@@ -123,15 +117,13 @@ test_expect_success "git-push -f ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/a/b/c
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/review/main/topic
 	<TAG-v123> refs/tags/v123
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)  tags/v123  refs/review/main/topic(A)  a/b/c(A)
t/t5411/test-0002-pre-receive-declined.sh +2 -4
index c5c76bfe93..0c3490c9b1 100644
@@ -20,12 +20,10 @@ test_expect_success "git-push is declined ($PROTOCOL)" '
 	 ! [remote rejected] HEAD -> next (pre-receive hook declined)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "cleanup ($PROTOCOL)" '
t/t5411/test-0003-pre-receive-declined--porcelain.sh +2 -4
index 45050b642a..e9c9db5d1f 100644
@@ -21,12 +21,10 @@ test_expect_success "git-push is declined ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "cleanup ($PROTOCOL/porcelain)" '
t/t5411/test-0011-no-hook-error.sh +4 -8
index 77b45b0cbd..3ef136e6ef 100644
@@ -19,13 +19,11 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL)
 	 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             next(A)
@@ -55,10 +53,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
 	 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0012-no-hook-error--porcelain.sh +4 -8
index 142f4835e4..19f66fbd7d 100644
@@ -20,13 +20,11 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL/
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             next(A)
@@ -57,10 +55,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0013-bad-protocol.sh +9 -36

116 lines not on this page · raw message

t/t5411/test-0014-bad-protocol--porcelain.sh +9 -36

116 lines not on this page · raw message

t/t5411/test-0020-report-ng.sh +4 -8
index 6618c91841..ad2c8f6535 100644
@@ -24,12 +24,10 @@ test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL)" '
 	 ! [remote rejected] HEAD -> refs/for/main/topic (failed)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook (ng message, $PROTOCOL)" '
@@ -58,10 +56,8 @@ test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL)"
 	 ! [remote rejected] HEAD -> refs/for/main/topic (error msg)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0021-report-ng--porcelain.sh +4 -8
index 44ad1c7de4..d8ae9d3414 100644
@@ -25,12 +25,10 @@ test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL/por
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook (ng message, $PROTOCOL/porcelain)" '
@@ -60,10 +58,8 @@ test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL/p
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0022-report-unexpect-ref.sh +2 -4
index b0c5a6e168..dbed467186 100644
@@ -30,12 +30,10 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL)" '
 	 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)
t/t5411/test-0023-report-unexpect-ref--porcelain.sh +2 -4
index 212927b8dc..e89096fa13 100644
@@ -31,12 +31,10 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL/porcelain)"
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)
t/t5411/test-0024-report-unknown-ref.sh +2 -4
index 94ffad55f2..77204244b8 100644
@@ -25,10 +25,8 @@ test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" '
 	 ! [remote rejected] HEAD -> refs/for/a/b/c/my/topic (proc-receive failed to report status)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0025-report-unknown-ref--porcelain.sh +2 -4
index 8ee7e66472..eeb1ce6b2c 100644
@@ -26,10 +26,8 @@ test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0026-push-options.sh +6 -12
index bb2cf59bdc..1ec2cb95bc 100644
@@ -20,12 +20,10 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
 	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "enable push options ($PROTOCOL)" '
@@ -69,13 +67,11 @@ test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL)
 	 * [new reference] HEAD -> refs/for/main/topic
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "restore proc-receive hook ($PROTOCOL)" '
@@ -123,13 +119,11 @@ test_expect_success "proc-receive: push with options ($PROTOCOL)" '
 	 * [new reference] HEAD -> refs/for/main/topic
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             next(A)
t/t5411/test-0027-push-options--porcelain.sh +6 -12
index 54e4f8f1d2..447fbfec0c 100644
@@ -21,12 +21,10 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain
 	make_user_friendly_and_stable_output <out-$test_count >actual &&
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "enable push options ($PROTOCOL/porcelain)" '
@@ -72,13 +70,11 @@ test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL/
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "restore proc-receive hook ($PROTOCOL/porcelain)" '
@@ -128,13 +124,11 @@ test_expect_success "proc-receive: push with options ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             next(A)
t/t5411/test-0030-report-ok.sh +2 -4
index 5d6feef118..8acb4f204f 100644
@@ -26,10 +26,8 @@ test_expect_success "proc-receive: ok ($PROTOCOL)" '
 	 * [new reference] HEAD -> refs/for/main/topic
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0031-report-ok--porcelain.sh +2 -4
index 91666d32df..a967718046 100644
@@ -27,10 +27,8 @@ test_expect_success "proc-receive: ok ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0032-report-with-options.sh +1 -4
index e6aa0f7018..437ade012d 100644
@@ -247,10 +247,7 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
 	EOF
 	test_cmp expect actual &&
 
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0033-report-with-options--porcelain.sh +1 -4
index a8ca5dd0dd..11486720ee 100644
@@ -256,10 +256,7 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc
 	EOF
 	test_cmp expect actual &&
 
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0034-report-ft.sh +2 -4
index c355c290d2..6e0d08b327 100644
@@ -28,13 +28,11 @@ test_expect_success "proc-receive: fall throught, let receive-pack to execute ($
 	 * [new reference] <COMMIT-B> -> refs/for/main/topic
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/for/main/topic
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             refs/for/main/topic(A)
t/t5411/test-0035-report-ft--porcelain.sh +2 -4
index 8ce4e58f2a..81bae9f2ec 100644
@@ -29,13 +29,11 @@ test_expect_success "proc-receive: fall throught, let receive-pack to execute ($
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/for/main/topic
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             refs/for/main/topic(A)
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +6 -12
index fad8eea8a0..be9b18b2b6 100644
@@ -65,12 +65,10 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	 <OID-A>..<OID-B> HEAD -> refs/changes/25/125/1
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" '
@@ -142,12 +140,10 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	 + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" '
@@ -205,12 +201,10 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
 	 <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" '
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +6 -12
index dc254d57eb..95fb89c031 100644
@@ -51,12 +51,10 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL/porcelain)" '
@@ -114,12 +112,10 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL/porcelain)" '
@@ -163,10 +159,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0038-report-mixed-refs.sh +2 -4
index 286f80d423..5e005299cc 100644
@@ -65,15 +65,13 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
 	 ! [remote rejected] HEAD -> refs/for/next/topic3 (proc-receive failed to report status)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/bar
 	<COMMIT-A> refs/heads/baz
 	<COMMIT-A> refs/heads/foo
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)             foo(A)  bar(A))  baz(A)
t/t5411/test-0039-report-mixed-refs--porcelain.sh +2 -4
index 939b8a3b4f..8f891c5385 100644
@@ -66,15 +66,13 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/bar
 	<COMMIT-A> refs/heads/baz
 	<COMMIT-A> refs/heads/foo
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)             foo(A)  bar(A))  baz(A)
t/t5411/test-0040-process-all-refs.sh +2 -4
index 2565302a17..fdcdcc7c2e 100644
@@ -92,14 +92,12 @@ test_expect_success "proc-receive: process all refs ($PROTOCOL)" '
 	 + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/bar
 	<COMMIT-A> refs/heads/baz
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             bar(A)  baz(B)
t/t5411/test-0041-process-all-refs--porcelain.sh +2 -4
index e21420b60d..73b35fe0aa 100644
@@ -93,14 +93,12 @@ test_expect_success "proc-receive: process all refs ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/bar
 	<COMMIT-A> refs/heads/baz
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             bar(A)  baz(B)
t/t5411/test-0050-proc-receive-refs-with-modifiers.sh +6 -12
index 2e29518ec5..7214647ada 100644
@@ -50,12 +50,10 @@ test_expect_success "proc-receive: update branch and new tag ($PROTOCOL)" '
 	 * [new reference] v123 -> refs/pull/124/head
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)
@@ -63,14 +61,12 @@ test_expect_success "proc-receive: update branch and new tag ($PROTOCOL)" '
 test_expect_success "setup upstream: create tags/v123 ($PROTOCOL)" '
 	git -C "$upstream" update-ref refs/heads/topic $A &&
 	git -C "$upstream" update-ref refs/tags/v123 $TAG &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/topic
 	<TAG-v123> refs/tags/v123
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook ($PROTOCOL)" '
@@ -125,11 +121,9 @@ test_expect_success "proc-receive: create/delete branch, and delete tag ($PROTOC
 	 * [new reference] <COMMIT-A> -> refs/pull/124/head
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-B> refs/heads/topic
 	EOF
-	test_cmp expect actual
 '
Signature · 1 line
2.28.0.15.gba9e81f0bd
author
#182 lore raw

v3 cover use unique out file in t5411

In reply to SZEDER Gábor

From: Jiang Xin <[email protected]>

t5411 has some test cases for the behavior of failed 'git push' commands. Even the 'git push' command ended, the output file may still be updated with messages from 'git-receive-pack' command running in background. This breaks test cases which reuse the same 'out' file.

## Changes since v2

+ Use unique 'out' file by appending the '-$test_count' suffix to prevent accidental overwriting by internal 'git-receive-pack' process.

--

Jiang Xin (2):
t5411: use different out file to prevent overwriting
t5411: refactor check of refs using test_cmp_refs

 t/t5411/common-functions.sh                   | 15 +++
 t/t5411/once-0010-report-status-v1.sh         |  5 +-
 t/t5411/test-0000-standard-git-push.sh        | 32 +++----
 .../test-0001-standard-git-push--porcelain.sh | 32 +++----
 t/t5411/test-0002-pre-receive-declined.sh     | 10 +-
 ...st-0003-pre-receive-declined--porcelain.sh | 10 +-
 t/t5411/test-0011-no-hook-error.sh            | 20 ++--
 t/t5411/test-0012-no-hook-error--porcelain.sh | 20 ++--
 t/t5411/test-0013-bad-protocol.sh             | 95 +++++++------------
 t/t5411/test-0014-bad-protocol--porcelain.sh  | 95 +++++++------------
 t/t5411/test-0020-report-ng.sh                | 20 ++--
 t/t5411/test-0021-report-ng--porcelain.sh     | 20 ++--
 t/t5411/test-0022-report-unexpect-ref.sh      | 10 +-
 ...est-0023-report-unexpect-ref--porcelain.sh | 10 +-
 t/t5411/test-0024-report-unknown-ref.sh       | 10 +-
 ...test-0025-report-unknown-ref--porcelain.sh | 10 +-
 t/t5411/test-0026-push-options.sh             | 22 ++---
 t/t5411/test-0027-push-options--porcelain.sh  | 22 ++---
 t/t5411/test-0030-report-ok.sh                |  6 +-
 t/t5411/test-0031-report-ok--porcelain.sh     |  6 +-
 t/t5411/test-0032-report-with-options.sh      |  9 +-
 ...est-0033-report-with-options--porcelain.sh |  9 +-
 t/t5411/test-0034-report-ft.sh                |  6 +-
 t/t5411/test-0035-report-ft--porcelain.sh     |  6 +-
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 18 ++--
 ...rt-multi-rewrite-for-one-ref--porcelain.sh | 18 ++--
 t/t5411/test-0038-report-mixed-refs.sh        | 10 +-
 .../test-0039-report-mixed-refs--porcelain.sh | 10 +-
 t/t5411/test-0040-process-all-refs.sh         |  6 +-
 .../test-0041-process-all-refs--porcelain.sh  |  6 +-
 ...t-0050-proc-receive-refs-with-modifiers.sh | 18 ++--
 31 files changed, 224 insertions(+), 362 deletions(-)
Signature · 1 line
2.28.0.15.gba9e81f0bd
#183 lore raw

Re: [PATCH v3 0/2] use unique out file in t5411

Quoted 7 lines · Jiang Xin

From: Jiang Xin <[email protected]>

t5411 has some test cases for the behavior of failed 'git push' commands. Even the 'git push' command ended, the output file may still be updated with messages from 'git-receive-pack' command running in background. This breaks test cases which reuse the same 'out' file.

I do not recall hearing from SZEDER who raised concerns about "a lot of churn that can be avoided by a change in the code to die more gracefully" in his previous round's review. This has been in 'seen' for a long time, so let's move it down to 'next'.

Thanks.

author
#184 lore raw

Re: [PATCH v3 0/2] use unique out file in t5411

Quoted 11 lines · Junio C Hamano <[email protected]> 于2021年2月12日周五 上午5:52写道:
Quoted 7 lines · Jiang Xin

From: Jiang Xin <[email protected]>

t5411 has some test cases for the behavior of failed 'git push' commands. Even the 'git push' command ended, the output file may still be updated with messages from 'git-receive-pack' command running in background. This breaks test cases which reuse the same 'out' file.

Quoted 5 lines

I do not recall hearing from SZEDER who raised concerns about "a lot of churn that can be avoided by a change in the code to die more gracefully" in his previous round's review. This has been in 'seen' for a long time, so let's move it down to 'next'.

SZEDER's concerns about "a lot of churn that can be avoided ..." is in this post:

    https://public-inbox.org/git/[email protected]/

I think current implementation of the client side of git-push is OK. It's no necessary to add more code and more roundtrips for git-push client side to complete the protocol in order to wait for end of the server.

--
Jiang Xin

author
#185 lore raw

Re: [PATCH v2 1/2] t5411: use different out file to prevent overwriting

In reply to SZEDER Gábor
Quoted 3 lines · SZEDER Gábor <[email protected]> 于2021年1月20日周三 下午8:49写道:

Would it be possible/desirable to die gracefully when the receiving end doesn't support push options?

If want to die gracefully, we need to end the pack protocol by sending a flush packet, close the connection. However, since we can easily fix this test case, I think changes for git protocol is unnecessary.

Quoted 25 lines
Quoted 25 lines
t/t5411/test-0000-standard-git-push.sh +3 -4
index 47b058af7e..b074417d4b 100644
@@ -35,11 +35,11 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
      test_must_fail git -C workbench push --atomic origin \
              main \
              $B:refs/heads/next \
-             >out 2>&1 &&
+             >out-0000-1 2>&1 &&
      filter_out_user_friendly_and_stable_output \
              -e "/^To / { p; }" \
              -e "/^ ! / { p; }" \
-             <out >actual &&
+             <out-0000-1 >actual &&
      cat >expect <<-EOF &&
      To <URL/of/upstream.git>
       ! [rejected] main -> main (non-fast-forward)
@@ -65,8 +65,8 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL)" '
              push origin \
              main \
              $B:refs/heads/next \
-             >out 2>&1 &&
-     make_user_friendly_and_stable_output <out >actual &&
+             >out-0000-2 2>&1 &&
Quoted 8 lines

t/t5411/test-0000-standard-git-push.sh test_expect_success "non-fast-forward git-push ($PROTOCOL)" ' · line 69

Quoted 1 line
t/t5411/test-0000-standard-git-push.sh +1 -0
+     make_user_friendly_and_stable_output <out-0000-2 >actual &&

There will be a lot of sequential numbers this way, which might lead to additional churn in the future, if we ever were to add more tests somewhere in the middle. However, our test framework does already have a counter for test cases, so we could perhaps use that, i.e. 'out-$test_count', to make sure that each test case has its own output file.

Using $test_count is better, and will do.

Thanks.
--
Jiang Xin

author
#186 lore raw

PATCH v2 2/2 t5411: refactor check of refs using test_cmp_refs

In reply to Johannes Sixt

From: Jiang Xin <[email protected]>

Add new helper 'test_cmp_refs' to check references in a repository.

---
 t/t5411/common-functions.sh                   | 15 +++++++
 t/t5411/once-0010-report-status-v1.sh         |  5 +--
 t/t5411/test-0000-standard-git-push.sh        | 24 ++++------
 .../test-0001-standard-git-push--porcelain.sh | 24 ++++------
 t/t5411/test-0002-pre-receive-declined.sh     |  6 +--
 ...st-0003-pre-receive-declined--porcelain.sh |  6 +--
 t/t5411/test-0011-no-hook-error.sh            | 12 ++---
 t/t5411/test-0012-no-hook-error--porcelain.sh | 12 ++---
 t/t5411/test-0013-bad-protocol.sh             | 45 ++++---------------
 t/t5411/test-0014-bad-protocol--porcelain.sh  | 45 ++++---------------
 t/t5411/test-0020-report-ng.sh                | 12 ++---
 t/t5411/test-0021-report-ng--porcelain.sh     | 12 ++---
 t/t5411/test-0022-report-unexpect-ref.sh      |  6 +--
 ...est-0023-report-unexpect-ref--porcelain.sh |  6 +--
 t/t5411/test-0024-report-unknown-ref.sh       |  6 +--
 ...test-0025-report-unknown-ref--porcelain.sh |  6 +--
 t/t5411/test-0026-push-options.sh             | 18 +++-----
 t/t5411/test-0027-push-options--porcelain.sh  | 18 +++-----
 t/t5411/test-0030-report-ok.sh                |  6 +--
 t/t5411/test-0031-report-ok--porcelain.sh     |  6 +--
 t/t5411/test-0032-report-with-options.sh      |  5 +--
 ...est-0033-report-with-options--porcelain.sh |  5 +--
 t/t5411/test-0034-report-ft.sh                |  6 +--
 t/t5411/test-0035-report-ft--porcelain.sh     |  6 +--
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 18 +++-----
 ...rt-multi-rewrite-for-one-ref--porcelain.sh | 18 +++-----
 t/t5411/test-0038-report-mixed-refs.sh        |  6 +--
 .../test-0039-report-mixed-refs--porcelain.sh |  6 +--
 t/t5411/test-0040-process-all-refs.sh         |  6 +--
 .../test-0041-process-all-refs--porcelain.sh  |  6 +--
 ...t-0050-proc-receive-refs-with-modifiers.sh | 18 +++-----
 31 files changed, 126 insertions(+), 264 deletions(-)
t/t5411/common-functions.sh +15 -0
index 344d13f61a..4835dd5182 100644
@@ -59,3 +59,18 @@ filter_out_user_friendly_and_stable_output () {
 	make_user_friendly_and_stable_output |
 		sed -n ${1+"$@"}
 }
+
+test_cmp_refs () {
+	indir=
+	if test "$1" = "-C"
+	then
+		shift
+		indir="$1"
+		shift
+	fi
+	indir=${indir:+"$indir"/}
+	cat >show-ref.expect &&
+	git ${indir:+ -C "$indir"} show-ref >show-ref.pristine &&
+	make_user_friendly_and_stable_output <show-ref.pristine >show-ref.filtered &&
+	test_cmp show-ref.expect show-ref.filtered
+}
t/t5411/once-0010-report-status-v1.sh +1 -4
index cb431a9c91..1233a46eac 100644
@@ -83,12 +83,9 @@ test_expect_success "proc-receive: report status v1" '
 	EOF
 	test_cmp expect actual &&
 
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/for/main/topic1
 	<COMMIT-A> refs/heads/foo
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0000-standard-git-push.sh +8 -16
index b074417d4b..63e0536727 100644
@@ -19,13 +19,11 @@ test_expect_success "git-push ($PROTOCOL)" '
 	 * [new branch] HEAD -> next
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(A)
@@ -46,13 +44,11 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
 	 ! [rejected] <COMMIT-B> -> next (atomic push failed)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(A)
@@ -77,13 +73,11 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL)" '
 	 ! [rejected] main -> main (non-fast-forward)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-B> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(B)
@@ -119,15 +113,13 @@ test_expect_success "git-push -f ($PROTOCOL)" '
 	 * [new branch] HEAD -> a/b/c
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/a/b/c
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/review/main/topic
 	<TAG-v123> refs/tags/v123
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)  tags/v123  refs/review/main/topic(A)  a/b/c(A)
t/t5411/test-0001-standard-git-push--porcelain.sh +8 -16
index 8a0de5cac8..4b872eb0a6 100644
@@ -20,13 +20,11 @@ test_expect_success "git-push ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(A)
@@ -48,13 +46,11 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
 	!    <COMMIT-B>:refs/heads/next    [rejected] (atomic push failed)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(A)
@@ -80,13 +76,11 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-B> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(B)
@@ -123,15 +117,13 @@ test_expect_success "git-push -f ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/a/b/c
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/review/main/topic
 	<TAG-v123> refs/tags/v123
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)  tags/v123  refs/review/main/topic(A)  a/b/c(A)
t/t5411/test-0002-pre-receive-declined.sh +2 -4
index 83edcb037b..ce1c18f824 100644
@@ -20,12 +20,10 @@ test_expect_success "git-push is declined ($PROTOCOL)" '
 	 ! [remote rejected] HEAD -> next (pre-receive hook declined)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "cleanup ($PROTOCOL)" '
t/t5411/test-0003-pre-receive-declined--porcelain.sh +2 -4
index 8f3bbeccca..7f882d9c12 100644
@@ -21,12 +21,10 @@ test_expect_success "git-push is declined ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "cleanup ($PROTOCOL/porcelain)" '
t/t5411/test-0011-no-hook-error.sh +4 -8
index 11c85a32d5..3c42995019 100644
@@ -19,13 +19,11 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL)
 	 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             next(A)
@@ -55,10 +53,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
 	 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0012-no-hook-error--porcelain.sh +4 -8
index f89754b480..b8603607fe 100644
@@ -20,13 +20,11 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL/
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             next(A)
@@ -57,10 +55,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0013-bad-protocol.sh +9 -36

116 lines not on this page · raw message

t/t5411/test-0014-bad-protocol--porcelain.sh +9 -36

116 lines not on this page · raw message

t/t5411/test-0020-report-ng.sh +4 -8
index 41efafc55e..d3aa071a21 100644
@@ -24,12 +24,10 @@ test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL)" '
 	 ! [remote rejected] HEAD -> refs/for/main/topic (failed)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook (ng message, $PROTOCOL)" '
@@ -58,10 +56,8 @@ test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL)"
 	 ! [remote rejected] HEAD -> refs/for/main/topic (error msg)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0021-report-ng--porcelain.sh +4 -8
index 65b22618cc..9bb82c2a30 100644
@@ -25,12 +25,10 @@ test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL/por
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook (ng message, $PROTOCOL/porcelain)" '
@@ -60,10 +58,8 @@ test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL/p
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0022-report-unexpect-ref.sh +2 -4
index 4cbd474678..405c6b3372 100644
@@ -30,12 +30,10 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL)" '
 	 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)
t/t5411/test-0023-report-unexpect-ref--porcelain.sh +2 -4
index 7804b87721..1fe3120741 100644
@@ -31,12 +31,10 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL/porcelain)"
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)
t/t5411/test-0024-report-unknown-ref.sh +2 -4
index a048cb0f02..b868d0bd7c 100644
@@ -25,10 +25,8 @@ test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" '
 	 ! [remote rejected] HEAD -> refs/for/a/b/c/my/topic (proc-receive failed to report status)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0025-report-unknown-ref--porcelain.sh +2 -4
index b3c4fe6330..813b005797 100644
@@ -26,10 +26,8 @@ test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0026-push-options.sh +6 -12
index 7bc627cee6..c8e453f993 100644
@@ -20,12 +20,10 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
 	make_user_friendly_and_stable_output <out-0026-1 >actual &&
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "enable push options ($PROTOCOL)" '
@@ -69,13 +67,11 @@ test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL)
 	 * [new reference] HEAD -> refs/for/main/topic
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "restore proc-receive hook ($PROTOCOL)" '
@@ -123,13 +119,11 @@ test_expect_success "proc-receive: push with options ($PROTOCOL)" '
 	 * [new reference] HEAD -> refs/for/main/topic
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             next(A)
t/t5411/test-0027-push-options--porcelain.sh +6 -12
index 5b4884a260..804d666875 100644
@@ -21,12 +21,10 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain
 	make_user_friendly_and_stable_output <out-0027-1 >actual &&
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "enable push options ($PROTOCOL/porcelain)" '
@@ -72,13 +70,11 @@ test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL/
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "restore proc-receive hook ($PROTOCOL/porcelain)" '
@@ -128,13 +124,11 @@ test_expect_success "proc-receive: push with options ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             next(A)
t/t5411/test-0030-report-ok.sh +2 -4
index 5d6feef118..8acb4f204f 100644
@@ -26,10 +26,8 @@ test_expect_success "proc-receive: ok ($PROTOCOL)" '
 	 * [new reference] HEAD -> refs/for/main/topic
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0031-report-ok--porcelain.sh +2 -4
index 91666d32df..a967718046 100644
@@ -27,10 +27,8 @@ test_expect_success "proc-receive: ok ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0032-report-with-options.sh +1 -4
index f5c67a1cc3..6040ea7aa7 100644
@@ -247,10 +247,7 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
 	EOF
 	test_cmp expect actual &&
 
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0033-report-with-options--porcelain.sh +1 -4
index 35e785a0fb..6c9b120eaf 100644
@@ -256,10 +256,7 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc
 	EOF
 	test_cmp expect actual &&
 
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0034-report-ft.sh +2 -4
index c355c290d2..6e0d08b327 100644
@@ -28,13 +28,11 @@ test_expect_success "proc-receive: fall throught, let receive-pack to execute ($
 	 * [new reference] <COMMIT-B> -> refs/for/main/topic
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/for/main/topic
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             refs/for/main/topic(A)
t/t5411/test-0035-report-ft--porcelain.sh +2 -4
index 8ce4e58f2a..81bae9f2ec 100644
@@ -29,13 +29,11 @@ test_expect_success "proc-receive: fall throught, let receive-pack to execute ($
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/for/main/topic
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             refs/for/main/topic(A)
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +6 -12
index fad8eea8a0..be9b18b2b6 100644
@@ -65,12 +65,10 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	 <OID-A>..<OID-B> HEAD -> refs/changes/25/125/1
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" '
@@ -142,12 +140,10 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	 + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" '
@@ -205,12 +201,10 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
 	 <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" '
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +6 -12
index dc254d57eb..95fb89c031 100644
@@ -51,12 +51,10 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL/porcelain)" '
@@ -114,12 +112,10 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL/porcelain)" '
@@ -163,10 +159,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0038-report-mixed-refs.sh +2 -4
index 0c31447aaa..1fd5bfd1e2 100644
@@ -65,15 +65,13 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
 	 ! [remote rejected] HEAD -> refs/for/next/topic3 (proc-receive failed to report status)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/bar
 	<COMMIT-A> refs/heads/baz
 	<COMMIT-A> refs/heads/foo
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)             foo(A)  bar(A))  baz(A)
t/t5411/test-0039-report-mixed-refs--porcelain.sh +2 -4
index 7007dd98fc..23fb796efe 100644
@@ -66,15 +66,13 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/bar
 	<COMMIT-A> refs/heads/baz
 	<COMMIT-A> refs/heads/foo
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)             foo(A)  bar(A))  baz(A)
t/t5411/test-0040-process-all-refs.sh +2 -4
index 2565302a17..fdcdcc7c2e 100644
@@ -92,14 +92,12 @@ test_expect_success "proc-receive: process all refs ($PROTOCOL)" '
 	 + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/bar
 	<COMMIT-A> refs/heads/baz
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             bar(A)  baz(B)
t/t5411/test-0041-process-all-refs--porcelain.sh +2 -4
index e21420b60d..73b35fe0aa 100644
@@ -93,14 +93,12 @@ test_expect_success "proc-receive: process all refs ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/bar
 	<COMMIT-A> refs/heads/baz
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             bar(A)  baz(B)
t/t5411/test-0050-proc-receive-refs-with-modifiers.sh +6 -12
index 2e29518ec5..7214647ada 100644
@@ -50,12 +50,10 @@ test_expect_success "proc-receive: update branch and new tag ($PROTOCOL)" '
 	 * [new reference] v123 -> refs/pull/124/head
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)
@@ -63,14 +61,12 @@ test_expect_success "proc-receive: update branch and new tag ($PROTOCOL)" '
 test_expect_success "setup upstream: create tags/v123 ($PROTOCOL)" '
 	git -C "$upstream" update-ref refs/heads/topic $A &&
 	git -C "$upstream" update-ref refs/tags/v123 $TAG &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/topic
 	<TAG-v123> refs/tags/v123
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook ($PROTOCOL)" '
@@ -125,11 +121,9 @@ test_expect_success "proc-receive: create/delete branch, and delete tag ($PROTOC
 	 * [new reference] <COMMIT-A> -> refs/pull/124/head
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-B> refs/heads/topic
 	EOF
-	test_cmp expect actual
 '
Signature · 1 line
2.28.0.15.gba9e81f0bd
author
#187 lore raw

v2 cover t5411 out file overwrite fix

In reply to Johannes Sixt

From: Jiang Xin <[email protected]>

t5411 has some test cases on the behavior of failed 'git push' commands. Even the 'git push' command ended, the output file may still be updated with messages from 'git-receive-pack' command running in background. This breaks test cases which reuse the same 'out' file.

## Changes since v1

+ Use different 'out' file instead of removing it which does not work on Windows.

## Range-diff v1..v2

1: 037e52118d ! 1: 3ec70c1c68 t5411: remove file after use to prevent overwriting
@@ Metadata
Author: Jiang Xin <[email protected]>

## Commit message ##
- t5411: remove file after use to prevent overwriting
+ t5411: use different out file to prevent overwriting

SZEDER reported that t5411 failed in Travis CI's s390x environment a couple of times, and could be reproduced with '--stress' test on this
@@ Commit message
- A mixture of the output of 'git show-ref' abd 'git receive-pack' leads to this issue.

- To resolve this issue, we can remove the file 'out' after use. The
- long-running 'git receive-pack' will not redirect its output to the new
- created 'out' file which has a different file descriptor.
+ The first intuitive reaction to resolve this issue is to remove the
+ file 'out' after use, so that the newly created file 'out' will have a
+ different file descriptor and will not be overwritten by the
+ 'git receive-pack' process. But Johannes pointed out that removing an
+ open file is not possible on Windows. So we use different temporary
+ file names to store the output of 'git push' to solve this issue.

+ Helped-by: Johannes Sixt <[email protected]>

## t/t5411/test-0000-standard-git-push.sh ##
@@ t/t5411/test-0000-standard-git-push.sh: test_expect_success "git-push --atomic ($PROTOCOL)" '

... ...

Signature · 39 lines
Jiang Xin (2):
  t5411: use different out file to prevent overwriting
  t5411: refactor check of refs using test_cmp_refs

 t/t5411/common-functions.sh                   | 15 +++
 t/t5411/once-0010-report-status-v1.sh         |  5 +-
 t/t5411/test-0000-standard-git-push.sh        | 32 +++----
 .../test-0001-standard-git-push--porcelain.sh | 32 +++----
 t/t5411/test-0002-pre-receive-declined.sh     | 10 +-
 ...st-0003-pre-receive-declined--porcelain.sh | 10 +-
 t/t5411/test-0011-no-hook-error.sh            | 20 ++--
 t/t5411/test-0012-no-hook-error--porcelain.sh | 20 ++--
 t/t5411/test-0013-bad-protocol.sh             | 95 +++++++------------
 t/t5411/test-0014-bad-protocol--porcelain.sh  | 95 +++++++------------
 t/t5411/test-0020-report-ng.sh                | 20 ++--
 t/t5411/test-0021-report-ng--porcelain.sh     | 20 ++--
 t/t5411/test-0022-report-unexpect-ref.sh      | 10 +-
 ...est-0023-report-unexpect-ref--porcelain.sh | 10 +-
 t/t5411/test-0024-report-unknown-ref.sh       | 10 +-
 ...test-0025-report-unknown-ref--porcelain.sh | 10 +-
 t/t5411/test-0026-push-options.sh             | 22 ++---
 t/t5411/test-0027-push-options--porcelain.sh  | 22 ++---
 t/t5411/test-0030-report-ok.sh                |  6 +-
 t/t5411/test-0031-report-ok--porcelain.sh     |  6 +-
 t/t5411/test-0032-report-with-options.sh      |  9 +-
 ...est-0033-report-with-options--porcelain.sh |  9 +-
 t/t5411/test-0034-report-ft.sh                |  6 +-
 t/t5411/test-0035-report-ft--porcelain.sh     |  6 +-
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 18 ++--
 ...rt-multi-rewrite-for-one-ref--porcelain.sh | 18 ++--
 t/t5411/test-0038-report-mixed-refs.sh        | 10 +-
 .../test-0039-report-mixed-refs--porcelain.sh | 10 +-
 t/t5411/test-0040-process-all-refs.sh         |  6 +-
 .../test-0041-process-all-refs--porcelain.sh  |  6 +-
 ...t-0050-proc-receive-refs-with-modifiers.sh | 18 ++--
 31 files changed, 224 insertions(+), 362 deletions(-)

-- 
2.28.0.15.gba9e81f0bd
author
#188 lore raw

PATCH v2 2/2 t5411: refactor check of refs using test_cmp_refs

In reply to SZEDER Gábor

From: Jiang Xin <[email protected]>

Add new helper 'test_cmp_refs' to check references in a repository.

---
 t/t5411/common-functions.sh                   | 15 +++++++
 t/t5411/once-0010-report-status-v1.sh         |  5 +--
 t/t5411/test-0000-standard-git-push.sh        | 24 ++++------
 .../test-0001-standard-git-push--porcelain.sh | 24 ++++------
 t/t5411/test-0002-pre-receive-declined.sh     |  6 +--
 ...st-0003-pre-receive-declined--porcelain.sh |  6 +--
 t/t5411/test-0011-no-hook-error.sh            | 12 ++---
 t/t5411/test-0012-no-hook-error--porcelain.sh | 12 ++---
 t/t5411/test-0013-bad-protocol.sh             | 45 ++++---------------
 t/t5411/test-0014-bad-protocol--porcelain.sh  | 45 ++++---------------
 t/t5411/test-0020-report-ng.sh                | 12 ++---
 t/t5411/test-0021-report-ng--porcelain.sh     | 12 ++---
 t/t5411/test-0022-report-unexpect-ref.sh      |  6 +--
 ...est-0023-report-unexpect-ref--porcelain.sh |  6 +--
 t/t5411/test-0024-report-unknown-ref.sh       |  6 +--
 ...test-0025-report-unknown-ref--porcelain.sh |  6 +--
 t/t5411/test-0026-push-options.sh             | 18 +++-----
 t/t5411/test-0027-push-options--porcelain.sh  | 18 +++-----
 t/t5411/test-0030-report-ok.sh                |  6 +--
 t/t5411/test-0031-report-ok--porcelain.sh     |  6 +--
 t/t5411/test-0032-report-with-options.sh      |  5 +--
 ...est-0033-report-with-options--porcelain.sh |  5 +--
 t/t5411/test-0034-report-ft.sh                |  6 +--
 t/t5411/test-0035-report-ft--porcelain.sh     |  6 +--
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 18 +++-----
 ...rt-multi-rewrite-for-one-ref--porcelain.sh | 18 +++-----
 t/t5411/test-0038-report-mixed-refs.sh        |  6 +--
 .../test-0039-report-mixed-refs--porcelain.sh |  6 +--
 t/t5411/test-0040-process-all-refs.sh         |  6 +--
 .../test-0041-process-all-refs--porcelain.sh  |  6 +--
 ...t-0050-proc-receive-refs-with-modifiers.sh | 18 +++-----
 31 files changed, 126 insertions(+), 264 deletions(-)
t/t5411/common-functions.sh +15 -0
index 344d13f61a..4835dd5182 100644
@@ -59,3 +59,18 @@ filter_out_user_friendly_and_stable_output () {
 	make_user_friendly_and_stable_output |
 		sed -n ${1+"$@"}
 }
+
+test_cmp_refs () {
+	indir=
+	if test "$1" = "-C"
+	then
+		shift
+		indir="$1"
+		shift
+	fi
+	indir=${indir:+"$indir"/}
+	cat >show-ref.expect &&
+	git ${indir:+ -C "$indir"} show-ref >show-ref.pristine &&
+	make_user_friendly_and_stable_output <show-ref.pristine >show-ref.filtered &&
+	test_cmp show-ref.expect show-ref.filtered
+}
t/t5411/once-0010-report-status-v1.sh +1 -4
index cb431a9c91..1233a46eac 100644
@@ -83,12 +83,9 @@ test_expect_success "proc-receive: report status v1" '
 	EOF
 	test_cmp expect actual &&
 
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/for/main/topic1
 	<COMMIT-A> refs/heads/foo
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0000-standard-git-push.sh +8 -16
index 694d8e8dc2..7af6026749 100644
@@ -19,13 +19,11 @@ test_expect_success "git-push ($PROTOCOL)" '
 	 * [new branch] HEAD -> next
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(A)
@@ -48,13 +46,11 @@ test_expect_success "git-push --atomic ($PROTOCOL)" '
 	 ! [rejected] <COMMIT-B> -> next (atomic push failed)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(A)
@@ -81,13 +77,11 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL)" '
 	 ! [rejected] main -> main (non-fast-forward)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-B> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(B)
@@ -123,15 +117,13 @@ test_expect_success "git-push -f ($PROTOCOL)" '
 	 * [new branch] HEAD -> a/b/c
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/a/b/c
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/review/main/topic
 	<TAG-v123> refs/tags/v123
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)  tags/v123  refs/review/main/topic(A)  a/b/c(A)
t/t5411/test-0001-standard-git-push--porcelain.sh +8 -16
index 6cf0bc7034..9e5c40f39c 100644
@@ -20,13 +20,11 @@ test_expect_success "git-push ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(A)
@@ -50,13 +48,11 @@ test_expect_success "git-push --atomic ($PROTOCOL/porcelain)" '
 	!    <COMMIT-B>:refs/heads/next    [rejected] (atomic push failed)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(A)
@@ -84,13 +80,11 @@ test_expect_success "non-fast-forward git-push ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	<COMMIT-B> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)  next(B)
@@ -127,15 +121,13 @@ test_expect_success "git-push -f ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/a/b/c
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/review/main/topic
 	<TAG-v123> refs/tags/v123
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)  tags/v123  refs/review/main/topic(A)  a/b/c(A)
t/t5411/test-0002-pre-receive-declined.sh +2 -4
index 61c3ee1b7f..7c70d45057 100644
@@ -22,12 +22,10 @@ test_expect_success "git-push is declined ($PROTOCOL)" '
 	 ! [remote rejected] HEAD -> next (pre-receive hook declined)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "cleanup ($PROTOCOL)" '
t/t5411/test-0003-pre-receive-declined--porcelain.sh +2 -4
index 0a9cc2d44a..ea38248fc5 100644
@@ -23,12 +23,10 @@ test_expect_success "git-push is declined ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "cleanup ($PROTOCOL/porcelain)" '
t/t5411/test-0011-no-hook-error.sh +4 -8
index fd2bd20b76..778b833f9d 100644
@@ -21,13 +21,11 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL)
 	 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             next(A)
@@ -59,10 +57,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
 	 ! [remote rejected] HEAD -> refs/for/main/topic (fail to run proc-receive hook)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0012-no-hook-error--porcelain.sh +4 -8
index 025a9c7186..371831d170 100644
@@ -22,13 +22,11 @@ test_expect_success "proc-receive: no hook, fail to push special ref ($PROTOCOL/
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             next(A)
@@ -61,10 +59,8 @@ test_expect_success "proc-receive: no hook, all failed for atomic push ($PROTOCO
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0013-bad-protocol.sh +9 -36

116 lines not on this page · raw message

t/t5411/test-0014-bad-protocol--porcelain.sh +9 -36

116 lines not on this page · raw message

t/t5411/test-0020-report-ng.sh +4 -8
index 9f71da9fb6..37300d374b 100644
@@ -26,12 +26,10 @@ test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL)" '
 	 ! [remote rejected] HEAD -> refs/for/main/topic (failed)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook (ng message, $PROTOCOL)" '
@@ -62,10 +60,8 @@ test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL)"
 	 ! [remote rejected] HEAD -> refs/for/main/topic (error msg)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0021-report-ng--porcelain.sh +4 -8
index 96065e3537..c40eb1060b 100644
@@ -27,12 +27,10 @@ test_expect_success "proc-receive: fail to update (ng, no message, $PROTOCOL/por
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook (ng message, $PROTOCOL/porcelain)" '
@@ -64,10 +62,8 @@ test_expect_success "proc-receive: fail to update (ng, with message, $PROTOCOL/p
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0022-report-unexpect-ref.sh +2 -4
index 624dda7acc..6c1716b25a 100644
@@ -32,12 +32,10 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL)" '
 	 ! [remote rejected] HEAD -> refs/for/main/topic (proc-receive failed to report status)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)
t/t5411/test-0023-report-unexpect-ref--porcelain.sh +2 -4
index dcb804afc8..46f44cdad5 100644
@@ -33,12 +33,10 @@ test_expect_success "proc-receive: report unexpected ref ($PROTOCOL/porcelain)"
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)
t/t5411/test-0024-report-unknown-ref.sh +2 -4
index af65355862..a543c5acf7 100644
@@ -27,10 +27,8 @@ test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" '
 	 ! [remote rejected] HEAD -> refs/for/a/b/c/my/topic (proc-receive failed to report status)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0025-report-unknown-ref--porcelain.sh +2 -4
index c336ec0e98..972df50ca7 100644
@@ -28,10 +28,8 @@ test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0026-push-options.sh +6 -12
index 46b1064fe6..049a474a0c 100644
@@ -22,12 +22,10 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL)" '
 	rm out &&
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "enable push options ($PROTOCOL)" '
@@ -71,13 +69,11 @@ test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL)
 	 * [new reference] HEAD -> refs/for/main/topic
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "restore proc-receive hook ($PROTOCOL)" '
@@ -125,13 +121,11 @@ test_expect_success "proc-receive: push with options ($PROTOCOL)" '
 	 * [new reference] HEAD -> refs/for/main/topic
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             next(A)
t/t5411/test-0027-push-options--porcelain.sh +6 -12
index 79a49a638e..e0455b8b81 100644
@@ -23,12 +23,10 @@ test_expect_success "proc-receive: not support push options ($PROTOCOL/porcelain
 	rm out &&
 	test_i18ngrep "fatal: the receiving end does not support push options" \
 		actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "enable push options ($PROTOCOL/porcelain)" '
@@ -74,13 +72,11 @@ test_expect_success "proc-receive: ignore push-options for version 0 ($PROTOCOL/
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "restore proc-receive hook ($PROTOCOL/porcelain)" '
@@ -130,13 +126,11 @@ test_expect_success "proc-receive: push with options ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/next
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             next(A)
t/t5411/test-0030-report-ok.sh +2 -4
index 5d6feef118..8acb4f204f 100644
@@ -26,10 +26,8 @@ test_expect_success "proc-receive: ok ($PROTOCOL)" '
 	 * [new reference] HEAD -> refs/for/main/topic
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0031-report-ok--porcelain.sh +2 -4
index 91666d32df..a967718046 100644
@@ -27,10 +27,8 @@ test_expect_success "proc-receive: ok ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0032-report-with-options.sh +1 -4
index 4d058cc6ff..9711d69f1d 100644
@@ -249,10 +249,7 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
 	EOF
 	test_cmp expect actual &&
 
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0033-report-with-options--porcelain.sh +1 -4
index 8ab908a6b0..7e699e8088 100644
@@ -258,10 +258,7 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc
 	EOF
 	test_cmp expect actual &&
 
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0034-report-ft.sh +2 -4
index c355c290d2..6e0d08b327 100644
@@ -28,13 +28,11 @@ test_expect_success "proc-receive: fall throught, let receive-pack to execute ($
 	 * [new reference] <COMMIT-B> -> refs/for/main/topic
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/for/main/topic
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             refs/for/main/topic(A)
t/t5411/test-0035-report-ft--porcelain.sh +2 -4
index 8ce4e58f2a..81bae9f2ec 100644
@@ -29,13 +29,11 @@ test_expect_success "proc-receive: fall throught, let receive-pack to execute ($
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/for/main/topic
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             refs/for/main/topic(A)
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +6 -12
index fad8eea8a0..be9b18b2b6 100644
@@ -65,12 +65,10 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	 <OID-A>..<OID-B> HEAD -> refs/changes/25/125/1
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" '
@@ -142,12 +140,10 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	 + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" '
@@ -205,12 +201,10 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
 	 <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" '
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +6 -12
index dc254d57eb..95fb89c031 100644
@@ -51,12 +51,10 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL/porcelain)" '
@@ -114,12 +112,10 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL/porcelain)" '
@@ -163,10 +159,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
t/t5411/test-0038-report-mixed-refs.sh +2 -4
index 264a5d5c6d..88fa60e53c 100644
@@ -67,15 +67,13 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
 	 ! [remote rejected] HEAD -> refs/for/next/topic3 (proc-receive failed to report status)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/bar
 	<COMMIT-A> refs/heads/baz
 	<COMMIT-A> refs/heads/foo
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)             foo(A)  bar(A))  baz(A)
t/t5411/test-0039-report-mixed-refs--porcelain.sh +2 -4
index 1e9c06d2b7..6c36d9250f 100644
@@ -68,15 +68,13 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/bar
 	<COMMIT-A> refs/heads/baz
 	<COMMIT-A> refs/heads/foo
 	<COMMIT-B> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(B)             foo(A)  bar(A))  baz(A)
t/t5411/test-0040-process-all-refs.sh +2 -4
index 2565302a17..fdcdcc7c2e 100644
@@ -92,14 +92,12 @@ test_expect_success "proc-receive: process all refs ($PROTOCOL)" '
 	 + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update)
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/bar
 	<COMMIT-A> refs/heads/baz
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             bar(A)  baz(B)
t/t5411/test-0041-process-all-refs--porcelain.sh +2 -4
index e21420b60d..73b35fe0aa 100644
@@ -93,14 +93,12 @@ test_expect_success "proc-receive: process all refs ($PROTOCOL/porcelain)" '
 	Done
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-B> refs/heads/bar
 	<COMMIT-A> refs/heads/baz
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)             bar(A)  baz(B)
t/t5411/test-0050-proc-receive-refs-with-modifiers.sh +6 -12
index 2e29518ec5..7214647ada 100644
@@ -50,12 +50,10 @@ test_expect_success "proc-receive: update branch and new tag ($PROTOCOL)" '
 	 * [new reference] v123 -> refs/pull/124/head
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	EOF
-	test_cmp expect actual
 '
 
 # Refs of upstream : main(A)
@@ -63,14 +61,12 @@ test_expect_success "proc-receive: update branch and new tag ($PROTOCOL)" '
 test_expect_success "setup upstream: create tags/v123 ($PROTOCOL)" '
 	git -C "$upstream" update-ref refs/heads/topic $A &&
 	git -C "$upstream" update-ref refs/tags/v123 $TAG &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-A> refs/heads/topic
 	<TAG-v123> refs/tags/v123
 	EOF
-	test_cmp expect actual
 '
 
 test_expect_success "setup proc-receive hook ($PROTOCOL)" '
@@ -125,11 +121,9 @@ test_expect_success "proc-receive: create/delete branch, and delete tag ($PROTOC
 	 * [new reference] <COMMIT-A> -> refs/pull/124/head
 	EOF
 	test_cmp expect actual &&
-	git -C "$upstream" show-ref >out &&
-	make_user_friendly_and_stable_output <out >actual &&
-	cat >expect <<-EOF &&
+
+	test_cmp_refs -C "$upstream" <<-EOF
 	<COMMIT-A> refs/heads/main
 	<COMMIT-B> refs/heads/topic
 	EOF
-	test_cmp expect actual
 '
Signature · 1 line
2.28.0.15.gba9e81f0bd
author
#189 lore raw

PATCH v19 4/10 receive-pack: feed report options to post-receive

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

When commands are fed to the "post-receive" hook, report options will be parsed and the real old-oid, new-oid, reference name will feed to the "post-receive" hook.

---
 builtin/receive-pack.c                        | 30 ++++++++++++++++---
 t/t5411/test-0032-report-with-options.sh      | 14 ++++-----
 ...est-0033-report-with-options--porcelain.sh | 14 ++++-----
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 11 +++++--
 ...rt-multi-rewrite-for-one-ref--porcelain.sh | 11 +++++--
 t/t5411/test-0038-report-mixed-refs.sh        |  2 +-
 .../test-0039-report-mixed-refs--porcelain.sh |  2 +-
 7 files changed, 58 insertions(+), 26 deletions(-)
builtin/receive-pack.c +26 -4
index d4614f6f67..0390f2dc97 100644
@@ -696,6 +696,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
 
 struct receive_hook_feed_state {
 	struct command *cmd;
+	struct ref_push_report *report;
 	int skip_broken;
 	struct strbuf buf;
 	const struct string_list *push_options;
@@ -783,11 +784,31 @@ static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep)
 		cmd = cmd->next;
 	if (!cmd)
 		return -1; /* EOF */
+	if (!bufp)
+		return 0; /* OK, can feed something. */
 	strbuf_reset(&state->buf);
-	strbuf_addf(&state->buf, "%s %s %s\n",
-		    oid_to_hex(&cmd->old_oid), oid_to_hex(&cmd->new_oid),
-		    cmd->ref_name);
-	state->cmd = cmd->next;
+	if (!state->report)
+		state->report = cmd->report;
+	if (state->report) {
+		struct object_id *old_oid;
+		struct object_id *new_oid;
+		const char *ref_name;
+
+		old_oid = state->report->old_oid ? state->report->old_oid : &cmd->old_oid;
+		new_oid = state->report->new_oid ? state->report->new_oid : &cmd->new_oid;
+		ref_name = state->report->ref_name ? state->report->ref_name : cmd->ref_name;
+		strbuf_addf(&state->buf, "%s %s %s\n",
+			    oid_to_hex(old_oid), oid_to_hex(new_oid),
+			    ref_name);
+		state->report = state->report->next;
+		if (!state->report)
+			state->cmd = cmd->next;
+	} else {
+		strbuf_addf(&state->buf, "%s %s %s\n",
+			    oid_to_hex(&cmd->old_oid), oid_to_hex(&cmd->new_oid),
+			    cmd->ref_name);
+		state->cmd = cmd->next;
+	}
 	if (bufp) {
 		*bufp = state->buf.buf;
 		*sizep = state->buf.len;
@@ -806,6 +827,7 @@ static int run_receive_hook(struct command *commands,
 	strbuf_init(&state.buf, 0);
 	state.cmd = commands;
 	state.skip_broken = skip_broken;
+	state.report = NULL;
 	if (feed_receive_hook(&state, NULL, NULL))
 		return 0;
 	state.cmd = commands;
t/t5411/test-0032-report-with-options.sh +7 -7
index a743aa8018..c559c207fa 100644
@@ -54,7 +54,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL)" '
 	remote: proc-receive> ok refs/for/master/topic
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -87,7 +87,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: proc-receive> option forced-update
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -121,7 +121,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL)
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: proc-receive> option old-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -153,7 +153,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" '
 	remote: proc-receive> ok refs/for/master/topic
 	remote: proc-receive> option old-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -187,7 +187,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL)
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -237,9 +237,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
 	remote: proc-receive> option forced-update
 	remote: proc-receive> option new-oid <COMMIT-A>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/next/topic
 	 * [new reference] HEAD -> refs/for/a/b/c/topic
t/t5411/test-0033-report-with-options--porcelain.sh +7 -7
index 439b97b06e..ea9312234e 100644
@@ -55,7 +55,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)"
 	remote: proc-receive> ok refs/for/master/topic
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -90,7 +90,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: proc-receive> option forced-update
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -125,7 +125,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: proc-receive> option old-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -158,7 +158,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)"
 	remote: proc-receive> ok refs/for/master/topic
 	remote: proc-receive> option old-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -193,7 +193,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -245,9 +245,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc
 	remote: proc-receive> option forced-update
 	remote: proc-receive> option new-oid <COMMIT-A>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/next/topic    [new reference]
 	*    HEAD:refs/for/a/b/c/topic    [new reference]
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +8 -3
index 12acf9ea1f..67cc4a8a4c 100644
@@ -41,7 +41,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -99,7 +101,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	remote: proc-receive> option new-oid <COMMIT-A>
 	remote: proc-receive> option forced-update
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -145,7 +149,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +8 -3
index f4a2c56e14..1dc8551bc6 100644
@@ -41,7 +41,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -100,7 +102,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	remote: proc-receive> option new-oid <COMMIT-A>
 	remote: proc-receive> option forced-update
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -147,7 +151,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
t/t5411/test-0038-report-mixed-refs.sh +1 -1
index 1dd6a97a97..bfc8d586d6 100644
@@ -53,7 +53,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
 	 <OID-A>..<OID-B> <COMMIT-B> -> master
 	 * [new branch] HEAD -> bar
t/t5411/test-0039-report-mixed-refs--porcelain.sh +1 -1
index 32ebf63dcf..5d021a4837 100644
@@ -53,7 +53,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
 	     <COMMIT-B>:refs/heads/master    <OID-A>..<OID-B>
 	*    HEAD:refs/heads/bar    [new branch]
Signature · 1 line
2.26.2.543.g44b58e439b
author
#190 lore raw

PATCH v19 5/10 New capability "report-status-v2" for git-push

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

The new introduced "proc-receive" hook may handle a command for a pseudo-reference with a zero-old as its old-oid, while the hook may create or update a reference with different name, different new-oid, and different old-oid (the reference may exist already with a non-zero old-oid). Current "report-status" protocol cannot report the status for such reference rewrite.

Add new capability "report-status-v2" and new report protocol which is not backward compatible for report of git-push.

If a user pushes to a pseudo-reference "refs/for/master/topic", and "receive-pack" creates two new references "refs/changes/23/123/1" and "refs/changes/24/124/1", for client without the knowledge of "report-status-v2", "receive-pack" will only send "ok/ng" directives in the report, such as:

ok ref/for/master/topic

But for client which has the knowledge of "report-status-v2", "receive-pack" will use "option" directives to report more attributes for the reference given by the above "ok/ng" directive.

ok refs/for/master/topic
option refname refs/changes/23/123/1
option new-oid <new-oid>
ok refs/for/master/topic
option refname refs/changes/24/124/1
option new-oid <new-oid>

The client will report two new created references to the end user.

---
 builtin/receive-pack.c                        |  54 +++++++-
 builtin/send-pack.c                           |  19 +++
 remote.h                                      |   1 +
 send-pack.c                                   | 101 +++++++++++---
 t/t5411-proc-receive-hook.sh                  |   9 ++
 t/t5411/once-0010-report-status-v1.sh         |  90 ++++++++++++
 t/t5411/test-0032-report-with-options.sh      |  14 +-
 ...est-0033-report-with-options--porcelain.sh |  14 +-
 ...t-0036-report-multi-rewrite-for-one-ref.sh |  11 +-
 ...rt-multi-rewrite-for-one-ref--porcelain.sh |  11 +-
 t/t5411/test-0038-report-mixed-refs.sh        |   2 +-
 .../test-0039-report-mixed-refs--porcelain.sh |   2 +-
 transport-helper.c                            | 128 ++++++++++++++----
 transport.c                                   | 116 ++++++++++++----
 14 files changed, 472 insertions(+), 100 deletions(-)
 create mode 100644 t/t5411/once-0010-report-status-v1.sh
builtin/receive-pack.c +52 -2
index 0390f2dc97..e3dfb17ad4 100644
@@ -57,6 +57,7 @@ static int advertise_push_options;
 static int unpack_limit = 100;
 static off_t max_input_size;
 static int report_status;
+static int report_status_v2;
 static int use_sideband;
 static int use_atomic;
 static int use_push_options;
@@ -240,7 +241,7 @@ static void show_ref(const char *path, const struct object_id *oid)
 		struct strbuf cap = STRBUF_INIT;
 
 		strbuf_addstr(&cap,
-			      "report-status delete-refs side-band-64k quiet");
+			      "report-status report-status-v2 delete-refs side-band-64k quiet");
 		if (advertise_atomic_push)
 			strbuf_addstr(&cap, " atomic");
 		if (prefer_ofs_delta)
@@ -1941,6 +1942,8 @@ static struct command *read_head_info(struct packet_reader *reader,
 			int len = 0;
 			if (parse_feature_request(feature_list, "report-status"))
 				report_status = 1;
+			if (parse_feature_request(feature_list, "report-status-v2"))
+				report_status_v2 = 1;
 			if (parse_feature_request(feature_list, "side-band-64k"))
 				use_sideband = LARGE_PACKET_MAX;
 			if (parse_feature_request(feature_list, "quiet"))
@@ -2259,6 +2262,51 @@ static void report(struct command *commands, const char *unpack_status)
 	strbuf_release(&buf);
 }
 
+static void report_v2(struct command *commands, const char *unpack_status)
+{
+	struct command *cmd;
+	struct strbuf buf = STRBUF_INIT;
+	struct ref_push_report *report;
+
+	packet_buf_write(&buf, "unpack %s\n",
+			 unpack_status ? unpack_status : "ok");
+	for (cmd = commands; cmd; cmd = cmd->next) {
+		int count = 0;
+
+		if (cmd->error_string) {
+			packet_buf_write(&buf, "ng %s %s\n",
+					 cmd->ref_name,
+					 cmd->error_string);
+			continue;
+		}
+		packet_buf_write(&buf, "ok %s\n",
+				 cmd->ref_name);
+		for (report = cmd->report; report; report = report->next) {
+			if (count++ > 0)
+				packet_buf_write(&buf, "ok %s\n",
+						 cmd->ref_name);
+			if (report->ref_name)
+				packet_buf_write(&buf, "option refname %s\n",
+						 report->ref_name);
+			if (report->old_oid)
+				packet_buf_write(&buf, "option old-oid %s\n",
+						 oid_to_hex(report->old_oid));
+			if (report->new_oid)
+				packet_buf_write(&buf, "option new-oid %s\n",
+						 oid_to_hex(report->new_oid));
+			if (report->forced_update)
+				packet_buf_write(&buf, "option forced-update\n");
+		}
+	}
+	packet_buf_flush(&buf);
+
+	if (use_sideband)
+		send_sideband(1, 1, buf.buf, buf.len, use_sideband);
+	else
+		write_or_die(1, buf.buf, buf.len);
+	strbuf_release(&buf);
+}
+
 static int delete_only(struct command *commands)
 {
 	struct command *cmd;
@@ -2367,7 +2415,9 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
 				 &push_options);
 		if (pack_lockfile)
 			unlink_or_warn(pack_lockfile);
-		if (report_status)
+		if (report_status_v2)
+			report_v2(commands, unpack_status);
+		else if (report_status)
 			report(commands, unpack_status);
 		run_receive_hook(commands, "post-receive", 1,
 				 &push_options);
builtin/send-pack.c +19 -0
index 2b9610f121..7af148d733 100644
@@ -29,10 +29,12 @@ static struct send_pack_args args;
 static void print_helper_status(struct ref *ref)
 {
 	struct strbuf buf = STRBUF_INIT;
+	struct ref_push_report *report;
 
 	for (; ref; ref = ref->next) {
 		const char *msg = NULL;
 		const char *res;
+		int count = 0;
 
 		switch(ref->status) {
 		case REF_STATUS_NONE:
@@ -94,6 +96,23 @@ static void print_helper_status(struct ref *ref)
 		}
 		strbuf_addch(&buf, '\n');
 
+		if (ref->status == REF_STATUS_OK) {
+			for (report = ref->report; report; report = report->next) {
+				if (count++ > 0)
+					strbuf_addf(&buf, "ok %s\n", ref->name);
+				if (report->ref_name)
+					strbuf_addf(&buf, "option refname %s\n",
+						report->ref_name);
+				if (report->old_oid)
+					strbuf_addf(&buf, "option old-oid %s\n",
+						oid_to_hex(report->old_oid));
+				if (report->new_oid)
+					strbuf_addf(&buf, "option new-oid %s\n",
+						oid_to_hex(report->new_oid));
+				if (report->forced_update)
+					strbuf_addstr(&buf, "option forced-update\n");
+			}
+		}
 		write_or_die(1, buf.buf, buf.len);
 	}
 	strbuf_release(&buf);
remote.h +1 -0
index 519349333a..eb62a47044 100644
@@ -148,6 +148,7 @@ struct ref {
 		REF_STATUS_ATOMIC_PUSH_FAILED
 	} status;
 	char *remote_status;
+	struct ref_push_report *report;
 	struct ref *peer_ref; /* when renaming */
 	char name[FLEX_ARRAY]; /* more */
 };
send-pack.c +82 -19

144 lines not on this page · raw message

t/t5411-proc-receive-hook.sh +9 -0
index 3a684353a8..746487286f 100755
@@ -78,6 +78,15 @@ run_proc_receive_hook_test() {
 # Initialize the upstream repository and local workbench.
 setup_upstream_and_workbench
 
+# Load test cases that only need to be executed once.
+for t in  "$TEST_DIRECTORY"/t5411/once-*.sh
+do
+	. "$t"
+done
+
+# Initialize the upstream repository and local workbench.
+setup_upstream_and_workbench
+
 # Run test cases for 'proc-receive' hook on local file protocol.
 run_proc_receive_hook_test local
 
t/t5411/once-0010-report-status-v1.sh new file +90 -0

90 lines not on this page · raw message

t/t5411/test-0032-report-with-options.sh +7 -7
index c559c207fa..b77b78c49f 100644
@@ -56,7 +56,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL)" '
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/pull/123/head
 	EOF
 	test_cmp expect actual
 '
@@ -89,7 +89,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/pull/123/head
 	EOF
 	test_cmp expect actual
 '
@@ -123,7 +123,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL)
 	remote: # post-receive hook
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-B>..<OID-A> HEAD -> refs/pull/123/head
 	EOF
 	test_cmp expect actual
 '
@@ -155,7 +155,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" '
 	remote: # post-receive hook
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-B>..<OID-A> HEAD -> refs/for/master/topic
 	EOF
 	test_cmp expect actual
 '
@@ -189,7 +189,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL)
 	remote: # post-receive hook
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
 	EOF
 	test_cmp expect actual
 '
@@ -241,9 +241,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/next/topic
+	 * [new reference] HEAD -> refs/pull/123/head
 	 * [new reference] HEAD -> refs/for/a/b/c/topic
-	 * [new reference] HEAD -> refs/for/master/topic
+	 + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update)
 	EOF
 	test_cmp expect actual &&
 
t/t5411/test-0033-report-with-options--porcelain.sh +7 -7
index ea9312234e..1fe352b686 100644
@@ -57,7 +57,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)"
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	*    HEAD:refs/pull/123/head    [new reference]
 	Done
 	EOF
 	test_cmp expect actual
@@ -92,7 +92,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	*    HEAD:refs/pull/123/head    [new reference]
 	Done
 	EOF
 	test_cmp expect actual
@@ -127,7 +127,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/
 	remote: # post-receive hook
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/pull/123/head    <OID-B>..<OID-A>
 	Done
 	EOF
 	test_cmp expect actual
@@ -160,7 +160,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)"
 	remote: # post-receive hook
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/for/master/topic    <OID-B>..<OID-A>
 	Done
 	EOF
 	test_cmp expect actual
@@ -195,7 +195,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/
 	remote: # post-receive hook
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
 	Done
 	EOF
 	test_cmp expect actual
@@ -249,9 +249,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/next/topic    [new reference]
+	*    HEAD:refs/pull/123/head    [new reference]
 	*    HEAD:refs/for/a/b/c/topic    [new reference]
-	*    HEAD:refs/for/master/topic    [new reference]
+	+    HEAD:refs/pull/124/head    <OID-B>...<OID-A> (forced update)
 	Done
 	EOF
 	test_cmp expect actual &&
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +8 -3
index 67cc4a8a4c..27d58edd14 100644
@@ -45,7 +45,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/changes/24/124/1
+	 <OID-A>..<OID-B> HEAD -> refs/changes/25/125/1
 	EOF
 	test_cmp expect actual &&
 	git -C "$upstream" show-ref >out &&
@@ -105,7 +107,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/changes/24/124/1
+	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
+	 + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update)
 	EOF
 	test_cmp expect actual &&
 	git -C "$upstream" show-ref >out &&
@@ -152,7 +156,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/changes/23/123/1
+	 <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
 	EOF
 	test_cmp expect actual &&
 	git -C "$upstream" show-ref >out &&
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +8 -3
index 1dc8551bc6..77b5b22ed4 100644
@@ -45,7 +45,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
+	*    HEAD:refs/changes/24/124/1    [new reference]
+	     HEAD:refs/changes/25/125/1    <OID-A>..<OID-B>
 	Done
 	EOF
 	test_cmp expect actual &&
@@ -106,7 +108,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	*    HEAD:refs/changes/24/124/1    [new reference]
+	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
+	+    HEAD:refs/changes/25/125/1    <OID-B>...<OID-A> (forced update)
 	Done
 	EOF
 	test_cmp expect actual &&
@@ -154,7 +158,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	*    HEAD:refs/changes/23/123/1    [new reference]
+	     HEAD:refs/changes/24/124/2    <OID-A>..<OID-B>
 	Done
 	EOF
 	test_cmp expect actual &&
t/t5411/test-0038-report-mixed-refs.sh +1 -1
index bfc8d586d6..a74a2cb449 100644
@@ -60,7 +60,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
 	 * [new branch] HEAD -> baz
 	 * [new reference] HEAD -> refs/for/next/topic2
 	 * [new branch] HEAD -> foo
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
 	 ! [remote rejected] HEAD -> refs/for/next/topic1 (fail to call Web API)
 	 ! [remote rejected] HEAD -> refs/for/next/topic3 (proc-receive failed to report status)
 	EOF
t/t5411/test-0039-report-mixed-refs--porcelain.sh +1 -1
index 5d021a4837..e4baa13ea3 100644
@@ -60,7 +60,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
 	*    HEAD:refs/heads/baz    [new branch]
 	*    HEAD:refs/for/next/topic2    [new reference]
 	*    HEAD:refs/heads/foo    [new branch]
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
 	!    HEAD:refs/for/next/topic1    [remote rejected] (fail to call Web API)
 	!    HEAD:refs/for/next/topic3    [remote rejected] (proc-receive failed to report status)
 	Done
transport-helper.c +99 -29

174 lines not on this page · raw message

transport.c +88 -28

218 lines not on this page · raw message

Signature · 1 line
2.26.2.543.g44b58e439b
author
#191 lore raw

PATCH v19 6/10 doc: add document for capability report-status-v2

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

Add ABNF notation for capability 'report-status-v2' which extends capability 'report-status' by adding additional option lines.

---
 Documentation/technical/pack-protocol.txt     | 41 +++++++++++++++++--
 .../technical/protocol-capabilities.txt       | 17 ++++++--
 2 files changed, 52 insertions(+), 6 deletions(-)
Documentation/technical/pack-protocol.txt +38 -3
index a4573d12ce..e13a2c064d 100644
@@ -503,8 +503,8 @@ The reference discovery phase is done nearly the same way as it is in the
 fetching protocol. Each reference obj-id and name on the server is sent
 in packet-line format to the client, followed by a flush-pkt.  The only
 real difference is that the capability listing is different - the only
-possible values are 'report-status', 'delete-refs', 'ofs-delta' and
-'push-options'.
+possible values are 'report-status', 'report-status-v2', 'delete-refs',
+'ofs-delta', 'atomic' and 'push-options'.
 
 Reference Update Request and Packfile Transfer
 ----------------------------------------------
@@ -625,7 +625,7 @@ Report Status
 -------------
 
 After receiving the pack data from the sender, the receiver sends a
-report if 'report-status' capability is in effect.
+report if 'report-status' or 'report-status-v2' capability is in effect.
 It is a short listing of what happened in that update.  It will first
 list the status of the packfile unpacking as either 'unpack ok' or
 'unpack [error]'.  Then it will list the status for each of the references
@@ -647,6 +647,41 @@ update was successful, or 'ng [refname] [error]' if the update was not.
   error-msg         = 1*(OCTET) ; where not "ok"
 ----
 
+The 'report-status-v2' capability extends the protocol by adding new option
+lines in order to support reporting of reference rewritten by the
+'proc-receive' hook.  The 'proc-receive' hook may handle a command for a
+pseudo-reference which may create or update one or more references, and each
+reference may have different name, different new-oid, and different old-oid.
+
+----
+  report-status-v2  = unpack-status
+		      1*(command-status-v2)
+		      flush-pkt
+
+  unpack-status     = PKT-LINE("unpack" SP unpack-result)
+  unpack-result     = "ok" / error-msg
+
+  command-status-v2 = command-ok-v2 / command-fail
+  command-ok-v2     = command-ok
+		      *option-line
+
+  command-ok        = PKT-LINE("ok" SP refname)
+  command-fail      = PKT-LINE("ng" SP refname SP error-msg)
+
+  error-msg         = 1*(OCTET) ; where not "ok"
+
+  option-line       = *1(option-refname)
+		      *1(option-old-oid)
+		      *1(option-new-oid)
+		      *1(option-forced-update)
+
+  option-refname    = PKT-LINE("option" SP "refname" SP refname)
+  option-old-oid    = PKT-LINE("option" SP "old-oid" SP obj-id)
+  option-new-oid    = PKT-LINE("option" SP "new-oid" SP obj-id)
+  option-force      = PKT-LINE("option" SP "forced-update")
+
+----
+
 Updates can be unsuccessful for a number of reasons.  The reference can have
 changed since the reference discovery phase was originally sent, meaning
 someone pushed in the meantime.  The reference being pushed could be a
Documentation/technical/protocol-capabilities.txt +14 -3
index 124d716807..ba869a7d36 100644
@@ -22,9 +22,9 @@ was sent.  Server MUST NOT ignore capabilities that client requested
 and server advertised.  As a consequence of these rules, server MUST
 NOT advertise capabilities it does not understand.
 
-The 'atomic', 'report-status', 'delete-refs', 'quiet', and 'push-cert'
-capabilities are sent and recognized by the receive-pack (push to server)
-process.
+The 'atomic', 'report-status', 'report-status-v2', 'delete-refs', 'quiet',
+and 'push-cert' capabilities are sent and recognized by the receive-pack
+(push to server) process.
 
 The 'ofs-delta' and 'side-band-64k' capabilities are sent and recognized
 by both upload-pack and receive-pack protocols.  The 'agent' capability
@@ -284,6 +284,17 @@ each reference was updated successfully.  If any of those were not
 successful, it will send back an error message.  See pack-protocol.txt
 for example messages.
 
+report-status-v2
+----------------
+
+Capability 'report-status-v2' extends capability 'report-status' by
+adding new "option" directives in order to support reference rewritten by
+the "proc-receive" hook.  The "proc-receive" hook may handle a command
+for a pseudo-reference which may create or update a reference with
+different name, new-oid, and old-oid.  While the capability
+'report-status' cannot report for such case.  See pack-protocol.txt
+for details.
+
 delete-refs
 -----------
 
Signature · 1 line
2.26.2.543.g44b58e439b
author
#192 lore raw

PATCH v19 7/10 receive-pack: new config receive.procReceiveRefs

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

Add a new multi-valued config variable "receive.procReceiveRefs" for receive-pack command, like the follows:

    git config --system --add receive.procReceiveRefs refs/for
    git config --system --add receive.procReceiveRefs refs/drafts

If the specific prefix strings given by the config variables match the reference names of the commands which are sent from git client to receive-pack, these commands will be executed by an external hook (named "proc-receive"), instead of the internal execute_commands function.

For example, if it is set to "refs/for", pushing to a reference such as "refs/for/master" will not create or update reference "refs/for/master", but may create or update a pull request directly by running the hook "proc-receive".

Optional modifiers can be provided in the beginning of the value to filter commands for specific actions: create (a), modify (m), delete (d). A ! can be included in the modifiers to negate the reference prefix entry. E.g.:

    git config --system --add receive.procReceiveRefs ad:refs/heads
    git config --system --add receive.procReceiveRefs !:refs/heads
---
 Documentation/config/receive.txt              |  22 +++
 builtin/receive-pack.c                        | 106 +++++++++++++-
 t/t5411/once-0010-report-status-v1.sh         |   4 +
 t/t5411/test-0010-proc-receive-settings.sh    |   7 +
 t/t5411/test-0040-process-all-refs.sh         | 113 +++++++++++++++
 .../test-0041-process-all-refs--porcelain.sh  | 114 +++++++++++++++
 ...t-0050-proc-receive-refs-with-modifiers.sh | 135 ++++++++++++++++++
 7 files changed, 494 insertions(+), 7 deletions(-)
 create mode 100644 t/t5411/test-0010-proc-receive-settings.sh
 create mode 100644 t/t5411/test-0040-process-all-refs.sh
 create mode 100644 t/t5411/test-0041-process-all-refs--porcelain.sh
 create mode 100644 t/t5411/test-0050-proc-receive-refs-with-modifiers.sh
Documentation/config/receive.txt +22 -0
index 65f78aac37..85d5b5a3d2 100644
@@ -114,6 +114,28 @@ receive.hideRefs::
 	An attempt to update or delete a hidden ref by `git push` is
 	rejected.
 
+receive.procReceiveRefs::
+	This is a multi-valued variable that defines reference prefixes
+	to match the commands in `receive-pack`.  Commands matching the
+	prefixes will be executed by an external hook "proc-receive",
+	instead of the internal `execute_commands` function.  If this
+	variable is not defined, the "proc-receive" hook will never be
+	used, and all commands will be executed by the internal
+	`execute_commands` function.
++
+For example, if this variable is set to "refs/for", pushing to reference
+such as "refs/for/master" will not create or update a reference named
+"refs/for/master", but may create or update a pull request directly by
+running the hook "proc-receive".
++
+Optional modifiers can be provided in the beginning of the value to filter
+commands for specific actions: create (a), modify (m), delete (d).
+A `!` can be included in the modifiers to negate the reference prefix entry.
+E.g.:
++
+	git config --system --add receive.procReceiveRefs ad:refs/heads
+	git config --system --add receive.procReceiveRefs !:refs/heads
+
 receive.updateServerInfo::
 	If set to true, git-receive-pack will run git-update-server-info
 	after receiving data from git-push and updating refs.
builtin/receive-pack.c +99 -7

131 lines not on this page · raw message

t/t5411/once-0010-report-status-v1.sh +4 -0
index bf410dc418..dc2cf4a522 100644
@@ -1,3 +1,7 @@
+test_expect_success "setup receive.procReceiveRefs" '
+	git -C "$upstream" config --add receive.procReceiveRefs refs/for
+'
+
 test_expect_success "setup proc-receive hook" '
 	write_script "$upstream/hooks/proc-receive" <<-EOF
 	printf >&2 "# proc-receive hook\n"
t/t5411/test-0010-proc-receive-settings.sh new file +7 -0
new file mode 100644
index 0000000000..a36809927b
@@ -0,0 +1,7 @@
+test_expect_success "add two receive.procReceiveRefs settings" '
+	(
+		cd "$upstream" &&
+		git config --add receive.procReceiveRefs refs/for &&
+		git config --add receive.procReceiveRefs refs/review/
+	)
+'
t/t5411/test-0040-process-all-refs.sh new file +113 -0

113 lines not on this page · raw message

t/t5411/test-0041-process-all-refs--porcelain.sh new file +114 -0

114 lines not on this page · raw message

t/t5411/test-0050-proc-receive-refs-with-modifiers.sh new file +135 -0

135 lines not on this page · raw message

Signature · 1 line
2.26.2.543.g44b58e439b
author
#193 lore raw

PATCH v19 8/10 t5411: test updates of remote-tracking branches

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

In order to test update of remote-tracking branches for special refs, add new "remote.origin.fetch" settings and test cases.

---
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +48 -0
index 27d58edd14..8eec3a1ed8 100644
@@ -1,3 +1,18 @@
+test_expect_success "setup git config for remote-tracking of special refs" '
+	(
+		cd workbench &&
+		if ! git config --get-all remote.origin.fetch | grep refs/for/
+		then
+			git config --add remote.origin.fetch \
+				"+refs/for/*:refs/t/for/*" &&
+			git config --add remote.origin.fetch \
+				"+refs/pull/*:refs/t/pull/*" &&
+			git config --add remote.origin.fetch \
+				"+refs/changes/*:refs/t/changes/*"
+		fi
+	)
+'
+
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL)" '
 	write_script "$upstream/hooks/proc-receive" <<-EOF
 	printf >&2 "# proc-receive hook\n"
@@ -58,6 +73,17 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	test_cmp expect actual
 '
 
+test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" '
+	git -C workbench show-ref |
+		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/t/for/master/topic
+	EOF
+	test_cmp expect actual &&
+	git -C workbench update-ref -d refs/t/for/master/topic
+'
+
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" '
 	write_script "$upstream/hooks/proc-receive" <<-EOF
 	printf >&2 "# proc-receive hook\n"
@@ -120,6 +146,17 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	test_cmp expect actual
 '
 
+test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" '
+	git -C workbench show-ref |
+		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/t/for/master/topic
+	EOF
+	test_cmp expect actual &&
+	git -C workbench update-ref -d refs/t/for/master/topic
+'
+
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" '
 	write_script "$upstream/hooks/proc-receive" <<-EOF
 	printf >&2 "# proc-receive hook\n"
@@ -167,3 +204,14 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
 	EOF
 	test_cmp expect actual
 '
+
+test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" '
+	git -C workbench show-ref |
+		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/t/for/master/topic
+	EOF
+	test_cmp expect actual &&
+	git -C workbench update-ref -d refs/t/for/master/topic
+'
Signature · 1 line
2.26.2.543.g44b58e439b
author
#194 lore raw

PATCH v19 9/10 transport: parse report options for tracking refs

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

When pushing a pseudo reference (such as "refs/for/master/topic"), may create or update one or more references. The real names of the references will be stored in the report options. Parse report options to create or update remote-tracking branches properly.

---
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 22 ++++++++---
 transport.c                                   | 37 +++++++++++++++----
 2 files changed, 45 insertions(+), 14 deletions(-)
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +16 -6
index 8eec3a1ed8..73283d81e8 100644
@@ -78,10 +78,14 @@ test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" '
 		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
 	make_user_friendly_and_stable_output <out >actual &&
 	cat >expect <<-EOF &&
-	<COMMIT-A> refs/t/for/master/topic
+	<COMMIT-A> refs/t/changes/24/124/1
+	<COMMIT-B> refs/t/changes/25/125/1
+	<COMMIT-B> refs/t/for/master/topic
 	EOF
 	test_cmp expect actual &&
-	git -C workbench update-ref -d refs/t/for/master/topic
+	git -C workbench update-ref -d refs/t/for/master/topic &&
+	git -C workbench update-ref -d refs/t/changes/24/124/1 &&
+	git -C workbench update-ref -d refs/t/changes/25/125/1
 '
 
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" '
@@ -151,10 +155,14 @@ test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" '
 		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
 	make_user_friendly_and_stable_output <out >actual &&
 	cat >expect <<-EOF &&
-	<COMMIT-A> refs/t/for/master/topic
+	<COMMIT-A> refs/t/changes/24/124/1
+	<COMMIT-A> refs/t/changes/25/125/1
+	<COMMIT-B> refs/t/for/master/topic
 	EOF
 	test_cmp expect actual &&
-	git -C workbench update-ref -d refs/t/for/master/topic
+	git -C workbench update-ref -d refs/t/for/master/topic &&
+	git -C workbench update-ref -d refs/t/changes/24/124/1 &&
+	git -C workbench update-ref -d refs/t/changes/25/125/1
 '
 
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" '
@@ -210,8 +218,10 @@ test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" '
 		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
 	make_user_friendly_and_stable_output <out >actual &&
 	cat >expect <<-EOF &&
-	<COMMIT-A> refs/t/for/master/topic
+	<COMMIT-A> refs/t/changes/23/123/1
+	<COMMIT-B> refs/t/changes/24/124/2
 	EOF
 	test_cmp expect actual &&
-	git -C workbench update-ref -d refs/t/for/master/topic
+	git -C workbench update-ref -d refs/t/changes/24/124/1 &&
+	git -C workbench update-ref -d refs/t/changes/25/125/2
 '
transport.c +29 -8
index 75e97a0c20..213ec69d7a 100644
@@ -436,29 +436,50 @@ int transport_refs_pushed(struct ref *ref)
 	return 0;
 }
 
-void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose)
+static void update_one_tracking_ref(struct remote *remote, char *refname,
+				    struct object_id *new_oid, int deletion,
+				    int verbose)
 {
 	struct refspec_item rs;
 
-	if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
-		return;
-
 	memset(&rs, 0, sizeof(rs));
-	rs.src = ref->name;
+	rs.src = refname;
 	rs.dst = NULL;
 
 	if (!remote_find_tracking(remote, &rs)) {
 		if (verbose)
 			fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
-		if (ref->deletion) {
+		if (deletion)
 			delete_ref(NULL, rs.dst, NULL, 0);
-		} else
-			update_ref("update by push", rs.dst, &ref->new_oid,
+		else
+			update_ref("update by push", rs.dst, new_oid,
 				   NULL, 0, 0);
 		free(rs.dst);
 	}
 }
 
+void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose)
+{
+	char *refname;
+	struct object_id *new_oid;
+	struct ref_push_report *report;
+
+	if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
+		return;
+
+	report = ref->report;
+	if (!report)
+		update_one_tracking_ref(remote, ref->name, &ref->new_oid,
+					ref->deletion, verbose);
+	else
+		for (; report; report = report->next) {
+			refname = report->ref_name ? (char *)report->ref_name : ref->name;
+			new_oid = report->new_oid ? report->new_oid : &ref->new_oid;
+			update_one_tracking_ref(remote, refname, new_oid,
+						is_null_oid(new_oid), verbose);
+		}
+}
+
 static void print_ref_status(char flag, const char *summary,
 			     struct ref *to, struct ref *from, const char *msg,
 			     struct ref_push_report *report,
Signature · 1 line
2.26.2.543.g44b58e439b
author
#195 lore raw

PATCH v19 10/10 doc: add documentation for the proc-receive hook

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

"git receive-pack" that accepts requests by "git push" learned to outsource some of the ref updates to the new "proc-receive" hook.

---
 Documentation/githooks.txt | 62 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
Documentation/githooks.txt +62 -0
index 31b601e4bc..2899e80445 100644
@@ -333,6 +333,68 @@ The default 'update' hook, when enabled--and with
 `hooks.allowunannotated` config option unset or set to false--prevents
 unannotated tags to be pushed.
 
+[[proc-receive]]
+proc-receive
+~~~~~~~~~~~~
+
+This hook is invoked by linkgit:git-receive-pack[1].  If the server has
+set the multi-valued config variable `receive.procReceiveRefs`, and the
+commands sent to 'receive-pack' have matching reference names, these
+commands will be executed by this hook, instead of by the internal
+`execute_commands()` function.  This hook is responsible for updating
+the relevant references and reporting the results back to 'receive-pack'.
+
+This hook executes once for the receive operation.  It takes no
+arguments, but uses a pkt-line format protocol to communicate with
+'receive-pack' to read commands, push-options and send results.  In the
+following example for the protocol, the letter 'S' stands for
+'receive-pack' and the letter 'H' stands for this hook.
+
+    # Version and features negotiation.
+    S: PKT-LINE(version=1\0push-options atomic...)
+    S: flush-pkt
+    H: PKT-LINE(version=1\0push-options...)
+    H: flush-pkt
+
+    # Send commands from server to the hook.
+    S: PKT-LINE(<old-oid> <new-oid> <ref>)
+    S: ... ...
+    S: flush-pkt
+    # Send push-options only if the 'push-options' feature is enabled.
+    S: PKT-LINE(push-option)
+    S: ... ...
+    S: flush-pkt
+
+    # Receive result from the hook.
+    # OK, run this command successfully.
+    H: PKT-LINE(ok <ref>)
+    # NO, I reject it.
+    H: PKT-LINE(ng <ref> <reason>)
+    # Fall through, let 'receive-pack' to execute it.
+    H: PKT-LINE(ok <ref>)
+    H: PKT-LINE(option fall-through)
+    # OK, but has an alternate reference.  The alternate reference name
+    # and other status can be given in option directives.
+    H: PKT-LINE(ok <ref>)
+    H: PKT-LINE(option refname <refname>)
+    H: PKT-LINE(option old-oid <old-oid>)
+    H: PKT-LINE(option new-oid <new-oid>)
+    H: PKT-LINE(option forced-update)
+    H: ... ...
+    H: flush-pkt
+
+Each command for the 'proc-receive' hook may point to a pseudo-reference
+and always has a zero-old as its old-oid, while the 'proc-receive' hook
+may update an alternate reference and the alternate reference may exist
+already with a non-zero old-oid.  For this case, this hook will use
+"option" directives to report extended attributes for the reference given
+by the leading "ok" directive.
+
+The report of the commands of this hook should have the same order as
+the input.  The exit status of the 'proc-receive' hook only determines
+the success or failure of the group of commands sent to it, unless
+atomic push is in use.
+
 [[post-receive]]
 post-receive
 ~~~~~~~~~~~~
Signature · 1 line
2.26.2.543.g44b58e439b
author
#196 lore raw

PATCH v18 1/10 transport: not report a non-head push as a branch

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

When pushing a new reference (not a head or tag), report it as a new reference instead of a new branch.

---
 t/t5516-fetch-push.sh | 2 +-
 transport.c           | 9 ++++++---
 2 files changed, 7 insertions(+), 4 deletions(-)
t/t5516-fetch-push.sh +1 -1
index 9c6218f568..77938db77f 100755
@@ -1039,7 +1039,7 @@ test_force_fetch_tag "annotated tag" "-f -a -m'tag message'"
 test_expect_success 'push --porcelain' '
 	mk_empty testrepo &&
 	echo >.git/foo  "To testrepo" &&
-	echo >>.git/foo "*	refs/heads/master:refs/remotes/origin/master	[new branch]"  &&
+	echo >>.git/foo "*	refs/heads/master:refs/remotes/origin/master	[new reference]"  &&
 	echo >>.git/foo "Done" &&
 	git push >.git/bar --porcelain  testrepo refs/heads/master:refs/remotes/origin/master &&
 	(
transport.c +6 -3
index 15f5ba4e8f..26fefd13c1 100644
@@ -500,9 +500,12 @@ static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_widt
 				 porcelain, summary_width);
 	else if (is_null_oid(&ref->old_oid))
 		print_ref_status('*',
-			(starts_with(ref->name, "refs/tags/") ? "[new tag]" :
-			"[new branch]"),
-			ref, ref->peer_ref, NULL, porcelain, summary_width);
+				 (starts_with(ref->name, "refs/tags/")
+				  ? "[new tag]"
+				  : (starts_with(ref->name, "refs/heads/")
+				     ? "[new branch]"
+				     : "[new reference]")),
+				 ref, ref->peer_ref, NULL, porcelain, summary_width);
 	else {
 		struct strbuf quickref = STRBUF_INIT;
 		char type;
Signature · 1 line
2.26.2.543.ge7de2a6e37
author
#197 lore raw

PATCH v18 2/10 t5411: add basic test cases for proc-receive hook

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

Topic "proc-receive-hook" will change the workflow and output of git-push. Add some basic test cases in t5411 before introducing the new topic.

---
 t/t5411-proc-receive-hook.sh                  | 108 +++++++++++++
 t/t5411/common-functions.sh                   |  56 +++++++
 t/t5411/test-0000-standard-git-push.sh        | 143 +++++++++++++++++
 .../test-0001-standard-git-push--porcelain.sh | 147 ++++++++++++++++++
 t/t5411/test-0002-pre-receive-declined.sh     |  33 ++++
 ...st-0003-pre-receive-declined--porcelain.sh |  34 ++++
 6 files changed, 521 insertions(+)
 create mode 100755 t/t5411-proc-receive-hook.sh
 create mode 100644 t/t5411/common-functions.sh
 create mode 100644 t/t5411/test-0000-standard-git-push.sh
 create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh
 create mode 100644 t/t5411/test-0002-pre-receive-declined.sh
 create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh
t/t5411-proc-receive-hook.sh new file +108 -0
new file mode 100755
index 0000000000..3a684353a8
@@ -0,0 +1,108 @@
+#!/bin/sh
+#
+# Copyright (c) 2020 Jiang Xin
+#
+
+test_description='Test proc-receive hook'
+
+. ./test-lib.sh
+
+. "$TEST_DIRECTORY"/t5411/common-functions.sh
+
+setup_upstream_and_workbench () {
+	# Refs of upstream : master(A)
+	# Refs of workbench: master(A)  tags/v123
+	test_expect_success "setup upstream and workbench" '
+		rm -rf upstream.git &&
+		rm -rf workbench &&
+		git init --bare upstream.git &&
+		git init workbench &&
+		create_commits_in workbench A B &&
+		(
+			cd workbench &&
+			# Try to make a stable fixed width for abbreviated commit ID,
+			# this fixed-width oid will be replaced with "<OID>".
+			git config core.abbrev 7 &&
+			git tag -m "v123" v123 $A &&
+			git remote add origin ../upstream.git &&
+			git push origin master &&
+			git update-ref refs/heads/master $A $B &&
+			git -C ../upstream.git update-ref \
+				refs/heads/master $A $B
+		) &&
+		TAG=$(git -C workbench rev-parse v123) &&
+
+		# setup pre-receive hook
+		write_script upstream.git/hooks/pre-receive <<-\EOF &&
+		exec >&2
+		echo "# pre-receive hook"
+		while read old new ref
+		do
+			echo "pre-receive< $old $new $ref"
+		done
+		EOF
+
+		# setup post-receive hook
+		write_script upstream.git/hooks/post-receive <<-\EOF &&
+		exec >&2
+		echo "# post-receive hook"
+		while read old new ref
+		do
+			echo "post-receive< $old $new $ref"
+		done
+		EOF
+
+		upstream=upstream.git
+	'
+}
+
+run_proc_receive_hook_test() {
+	case $1 in
+	http)
+		PROTOCOL="HTTP protocol"
+		URL_PREFIX="http://.*"
+		;;
+	local)
+		PROTOCOL="builtin protocol"
+		URL_PREFIX="\.\."
+		;;
+	esac
+
+	# Include test cases for both file and HTTP protocol
+	for t in  "$TEST_DIRECTORY"/t5411/test-*.sh
+	do
+		. "$t"
+	done
+}
+
+# Initialize the upstream repository and local workbench.
+setup_upstream_and_workbench
+
+# Run test cases for 'proc-receive' hook on local file protocol.
+run_proc_receive_hook_test local
+
+ROOT_PATH="$PWD"
+. "$TEST_DIRECTORY"/lib-gpg.sh
+. "$TEST_DIRECTORY"/lib-httpd.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
+start_httpd
+
+# Re-initialize the upstream repository and local workbench.
+setup_upstream_and_workbench
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+test_expect_success "setup for HTTP protocol" '
+	git -C upstream.git config http.receivepack true &&
+	upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" &&
+	mv upstream.git "$upstream" &&
+	git -C workbench remote set-url origin "$HTTPD_URL/auth-push/smart/upstream.git" &&
+	set_askpass user@host pass@host
+'
+
+setup_askpass_helper
+
+# Run test cases for 'proc-receive' hook on HTTP protocol.
+run_proc_receive_hook_test http
+
+test_done
t/t5411/common-functions.sh new file +56 -0

56 lines not on this page · raw message

t/t5411/test-0000-standard-git-push.sh new file +143 -0

143 lines not on this page · raw message

t/t5411/test-0001-standard-git-push--porcelain.sh new file +147 -0

147 lines not on this page · raw message

t/t5411/test-0002-pre-receive-declined.sh new file +33 -0
new file mode 100644
index 0000000000..c246f7e68e
@@ -0,0 +1,33 @@
+test_expect_success "setup pre-receive hook ($PROTOCOL)" '
+	mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" &&
+	write_script "$upstream/hooks/pre-receive" <<-EOF
+	exit 1
+	EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git-push         : master(B)             next(A)
+test_expect_success "git-push is declined ($PROTOCOL)" '
+	test_must_fail git -C workbench push origin \
+		$B:refs/heads/master \
+		HEAD:refs/heads/next \
+		>out 2>&1 &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	To <URL/of/upstream.git>
+	 ! [remote rejected] <COMMIT-B> -> master (pre-receive hook declined)
+	 ! [remote rejected] HEAD -> next (pre-receive hook declined)
+	EOF
+	test_cmp expect actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success "cleanup ($PROTOCOL)" '
+	mv "$upstream/hooks/pre-receive.ok" "$upstream/hooks/pre-receive"
+'
t/t5411/test-0003-pre-receive-declined--porcelain.sh new file +34 -0
new file mode 100644
index 0000000000..b14894de81
@@ -0,0 +1,34 @@
+test_expect_success "setup pre-receive hook ($PROTOCOL/porcelain)" '
+	mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" &&
+	write_script "$upstream/hooks/pre-receive" <<-EOF
+	exit 1
+	EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git-push         : master(B)             next(A)
+test_expect_success "git-push is declined ($PROTOCOL/porcelain)" '
+	test_must_fail git -C workbench push --porcelain origin \
+		$B:refs/heads/master \
+		HEAD:refs/heads/next \
+		>out 2>&1 &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	To <URL/of/upstream.git>
+	!    <COMMIT-B>:refs/heads/master    [remote rejected] (pre-receive hook declined)
+	!    HEAD:refs/heads/next    [remote rejected] (pre-receive hook declined)
+	Done
+	EOF
+	test_cmp expect actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success "cleanup ($PROTOCOL/porcelain)" '
+	mv "$upstream/hooks/pre-receive.ok" "$upstream/hooks/pre-receive"
+'
Signature · 1 line
2.26.2.543.ge7de2a6e37
author
#198 lore raw

PATCH v18 3/10 receive-pack: add new proc-receive hook

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

Git calls an internal execute_commands function to handle commands sent from client to git-receive-pack. Regardless of what references the user pushes, git creates or updates the corresponding references if the user has write-permission. A contributor who has no write-permission, cannot push to the repository directly. So, the contributor has to write commits to an alternate location, and sends pull request by emails or by other ways. We call this workflow as a distributed workflow.

It would be more convenient to work in a centralized workflow like what Gerrit provided for some cases. For example, a read-only user who cannot push to a branch directly can run the following git push command to push commits to a pseudo reference (has a prefix "refs/for/", not "refs/heads/") to create a code review.

    git push origin \
        HEAD:refs/for/<branch-name>/<session>

The <branch-name> in the above example can be as simple as "master", or a more complicated branch name like "foo/bar". The <session> in the above example command can be the local branch name of the client side, such as "my/topic".

We cannot implement a centralized workflow elegantly by using "pre-receive" + "post-receive", because Git will call the internal function "execute_commands" to create references (even the special pseudo reference) between these two hooks. Even though we can delete the temporarily created pseudo reference via the "post-receive" hook, having a temporary reference is not safe for concurrent pushes.

So, add a filter and a new handler to support this kind of workflow. The filter will check the prefix of the reference name, and if the command has a special reference name, the filter will turn a specific field (run_proc_receive) on for the command. Commands with this filed turned on will be executed by a new handler (an hook named "proc-receive") instead of the internal execute_commands function. We can use this "proc-receive" command to create pull requests or send emails for code review.

Suggested by Junio, this "proc-receive" hook reads the commands, push-options (optional), and send result using a protocol in pkt-line format. In the following example, The letter "S" stands for "receive-pack" and letter "H" stands for the hook.

# Version and features negotiation.
S: PKT-LINE(version=1\0push-options atomic...)
S: flush-pkt
H: PKT-LINE(version=1\0push-options...)
H: flush-pkt

# Send commands from server to the hook.
S: PKT-LINE(<old-oid> <new-oid> <ref>)
S: ... ...
S: flush-pkt
# Send push-options only if the 'push-options' feature is enabled.
S: PKT-LINE(push-option)
S: ... ...
S: flush-pkt

# Receive result from the hook.
# OK, run this command successfully.
H: PKT-LINE(ok <ref>)
# NO, I reject it.
H: PKT-LINE(ng <ref> <reason>)
# Fall through, let 'receive-pack' to execute it.
H: PKT-LINE(ok <ref>)
H: PKT-LINE(option fall-through)
# OK, but has an alternate reference. The alternate reference name # and other status can be given in options
H: PKT-LINE(ok <ref>)
H: PKT-LINE(option refname <refname>)
H: PKT-LINE(option old-oid <old-oid>)
H: PKT-LINE(option new-oid <new-oid>)
H: PKT-LINE(option forced-update)
H: ... ...
H: flush-pkt

After receiving a command, the hook will execute the command, and may create/update different reference. For example, a command for a pseudo reference "refs/for/master/topic" may create/update different reference such as "refs/pull/123/head". The alternate reference name and other status are given in option lines.

The list of commands returned from "proc-receive" will replace the relevant commands that are sent from user to "receive-pack", and "receive-pack" will continue to run the "execute_commands" function and other routines. Finally, the result of the execution of these commands will be reported to end user.

The reporting function from "receive-pack" to "send-pack" will be extended in latter commit just like what the "proc-receive" hook reports to "receive-pack".

---
 Makefile                                      |   1 +
 builtin/receive-pack.c                        | 296 +++++++++++++++++-
 remote.h                                      |   8 +
 t/helper/test-proc-receive.c                  | 176 +++++++++++
 t/helper/test-tool.c                          |   1 +
 t/helper/test-tool.h                          |   1 +
 t/t5411/test-0011-no-hook-error.sh            |  64 ++++
 t/t5411/test-0012-no-hook-error--porcelain.sh |  66 ++++
 t/t5411/test-0013-bad-protocol.sh             | 217 +++++++++++++
 t/t5411/test-0014-bad-protocol--porcelain.sh  | 160 ++++++++++
 t/t5411/test-0020-report-ng.sh                |  67 ++++
 t/t5411/test-0021-report-ng--porcelain.sh     |  69 ++++
 t/t5411/test-0022-report-unexpect-ref.sh      |  45 +++
 ...est-0023-report-unexpect-ref--porcelain.sh |  46 +++
 t/t5411/test-0024-report-unknown-ref.sh       |  34 ++
 ...test-0025-report-unknown-ref--porcelain.sh |  35 +++
 t/t5411/test-0026-push-options.sh             |  79 +++++
 t/t5411/test-0027-push-options--porcelain.sh  |  82 +++++
 t/t5411/test-0030-report-ok.sh                |  35 +++
 t/t5411/test-0031-report-ok--porcelain.sh     |  36 +++
 t/t5411/test-0032-report-with-options.sh      | 256 +++++++++++++++
 ...est-0033-report-with-options--porcelain.sh | 265 ++++++++++++++++
 t/t5411/test-0034-report-ft.sh                |  44 +++
 t/t5411/test-0035-report-ft--porcelain.sh     |  45 +++
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 159 ++++++++++
 ...rt-multi-rewrite-for-one-ref--porcelain.sh | 162 ++++++++++
 t/t5411/test-0038-report-mixed-refs.sh        |  89 ++++++
 .../test-0039-report-mixed-refs--porcelain.sh |  91 ++++++
 28 files changed, 2626 insertions(+), 3 deletions(-)
 create mode 100644 t/helper/test-proc-receive.c
 create mode 100644 t/t5411/test-0011-no-hook-error.sh
 create mode 100644 t/t5411/test-0012-no-hook-error--porcelain.sh
 create mode 100644 t/t5411/test-0013-bad-protocol.sh
 create mode 100644 t/t5411/test-0014-bad-protocol--porcelain.sh
 create mode 100644 t/t5411/test-0020-report-ng.sh
 create mode 100644 t/t5411/test-0021-report-ng--porcelain.sh
 create mode 100644 t/t5411/test-0022-report-unexpect-ref.sh
 create mode 100644 t/t5411/test-0023-report-unexpect-ref--porcelain.sh
 create mode 100644 t/t5411/test-0024-report-unknown-ref.sh
 create mode 100644 t/t5411/test-0025-report-unknown-ref--porcelain.sh
 create mode 100644 t/t5411/test-0026-push-options.sh
 create mode 100644 t/t5411/test-0027-push-options--porcelain.sh
 create mode 100644 t/t5411/test-0030-report-ok.sh
 create mode 100644 t/t5411/test-0031-report-ok--porcelain.sh
 create mode 100644 t/t5411/test-0032-report-with-options.sh
 create mode 100644 t/t5411/test-0033-report-with-options--porcelain.sh
 create mode 100644 t/t5411/test-0034-report-ft.sh
 create mode 100644 t/t5411/test-0035-report-ft--porcelain.sh
 create mode 100644 t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh
 create mode 100644 t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh
 create mode 100644 t/t5411/test-0038-report-mixed-refs.sh
 create mode 100644 t/t5411/test-0039-report-mixed-refs--porcelain.sh
Makefile +1 -0
index 3d3a39fc19..607aeabeee 100644
@@ -722,6 +722,7 @@ TEST_BUILTINS_OBJS += test-parse-pathspec-file.o
 TEST_BUILTINS_OBJS += test-path-utils.o
 TEST_BUILTINS_OBJS += test-pkt-line.o
 TEST_BUILTINS_OBJS += test-prio-queue.o
+TEST_BUILTINS_OBJS += test-proc-receive.o
 TEST_BUILTINS_OBJS += test-progress.o
 TEST_BUILTINS_OBJS += test-reach.o
 TEST_BUILTINS_OBJS += test-read-cache.o
builtin/receive-pack.c +293 -3

342 lines not on this page · raw message

remote.h +8 -0
index 11d8719b58..ca7735b441 100644
@@ -93,6 +93,14 @@ int for_each_remote(each_remote_fn fn, void *priv);
 
 int remote_has_url(struct remote *remote, const char *url);
 
+struct ref_push_report {
+	const char *ref_name;
+	struct object_id *old_oid;
+	struct object_id *new_oid;
+	unsigned int forced_update:1;
+	struct ref_push_report *next;
+};
+
 struct ref {
 	struct ref *next;
 	struct object_id old_oid;
t/helper/test-proc-receive.c new file +176 -0

176 lines not on this page · raw message

t/helper/test-tool.c +1 -0
index 590b2efca7..a0d3966b29 100644
@@ -46,6 +46,7 @@ static struct test_cmd cmds[] = {
 	{ "path-utils", cmd__path_utils },
 	{ "pkt-line", cmd__pkt_line },
 	{ "prio-queue", cmd__prio_queue },
+	{ "proc-receive", cmd__proc_receive},
 	{ "progress", cmd__progress },
 	{ "reach", cmd__reach },
 	{ "read-cache", cmd__read_cache },
t/helper/test-tool.h +1 -0
index ddc8e990e9..07034d3f38 100644
@@ -35,6 +35,7 @@ int cmd__parse_pathspec_file(int argc, const char** argv);
 int cmd__path_utils(int argc, const char **argv);
 int cmd__pkt_line(int argc, const char **argv);
 int cmd__prio_queue(int argc, const char **argv);
+int cmd__proc_receive(int argc, const char **argv);
 int cmd__progress(int argc, const char **argv);
 int cmd__reach(int argc, const char **argv);
 int cmd__read_cache(int argc, const char **argv);
t/t5411/test-0011-no-hook-error.sh new file +64 -0

64 lines not on this page · raw message

t/t5411/test-0012-no-hook-error--porcelain.sh new file +66 -0

66 lines not on this page · raw message

t/t5411/test-0013-bad-protocol.sh new file +217 -0

217 lines not on this page · raw message

t/t5411/test-0014-bad-protocol--porcelain.sh new file +160 -0

160 lines not on this page · raw message

t/t5411/test-0020-report-ng.sh new file +67 -0

67 lines not on this page · raw message

t/t5411/test-0021-report-ng--porcelain.sh new file +69 -0

69 lines not on this page · raw message

t/t5411/test-0022-report-unexpect-ref.sh new file +45 -0

45 lines not on this page · raw message

t/t5411/test-0023-report-unexpect-ref--porcelain.sh new file +46 -0

46 lines not on this page · raw message

t/t5411/test-0024-report-unknown-ref.sh new file +34 -0
new file mode 100644
index 0000000000..c3946f329a
@@ -0,0 +1,34 @@
+test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" '
+	write_script "$upstream/hooks/proc-receive" <<-EOF
+	printf >&2 "# proc-receive hook\n"
+	test-tool proc-receive -v \
+		-r "ok refs/for/master/topic"
+	EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push         :                       refs/for/a/b/c/my/topic
+test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" '
+	test_must_fail git -C workbench push origin \
+		HEAD:refs/for/a/b/c/my/topic \
+		>out 2>&1 &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	remote: # pre-receive hook
+	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
+	remote: # proc-receive hook
+	remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
+	remote: proc-receive> ok refs/for/master/topic
+	remote: error: proc-receive reported status on unknown ref: refs/for/master/topic
+	To <URL/of/upstream.git>
+	 ! [remote rejected] HEAD -> refs/for/a/b/c/my/topic (proc-receive failed to report status)
+	EOF
+	test_cmp expect actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'
t/t5411/test-0025-report-unknown-ref--porcelain.sh new file +35 -0
new file mode 100644
index 0000000000..d093b1a579
@@ -0,0 +1,35 @@
+test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL/porcelain)" '
+	write_script "$upstream/hooks/proc-receive" <<-EOF
+	printf >&2 "# proc-receive hook\n"
+	test-tool proc-receive -v \
+		-r "ok refs/for/master/topic"
+	EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push         :                       refs/for/a/b/c/my/topic
+test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain)" '
+	test_must_fail git -C workbench push --porcelain origin \
+		HEAD:refs/for/a/b/c/my/topic \
+		>out 2>&1 &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	remote: # pre-receive hook
+	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
+	remote: # proc-receive hook
+	remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
+	remote: proc-receive> ok refs/for/master/topic
+	remote: error: proc-receive reported status on unknown ref: refs/for/master/topic
+	To <URL/of/upstream.git>
+	!    HEAD:refs/for/a/b/c/my/topic    [remote rejected] (proc-receive failed to report status)
+	Done
+	EOF
+	test_cmp expect actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'
t/t5411/test-0026-push-options.sh new file +79 -0

79 lines not on this page · raw message

t/t5411/test-0027-push-options--porcelain.sh new file +82 -0

82 lines not on this page · raw message

t/t5411/test-0030-report-ok.sh new file +35 -0
new file mode 100644
index 0000000000..44c99d3831
@@ -0,0 +1,35 @@
+test_expect_success "setup proc-receive hook (ok, $PROTOCOL)" '
+	write_script "$upstream/hooks/proc-receive" <<-EOF
+	printf >&2 "# proc-receive hook\n"
+	test-tool proc-receive -v \
+		-r "ok refs/for/master/topic"
+	EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push         :                       refs/for/master/topic
+test_expect_success "proc-receive: ok ($PROTOCOL)" '
+	git -C workbench push origin \
+		HEAD:refs/for/master/topic \
+		>out 2>&1 &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	remote: # pre-receive hook
+	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: # proc-receive hook
+	remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: proc-receive> ok refs/for/master/topic
+	remote: # post-receive hook
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	To <URL/of/upstream.git>
+	 * [new reference] HEAD -> refs/for/master/topic
+	EOF
+	test_cmp expect actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'
t/t5411/test-0031-report-ok--porcelain.sh new file +36 -0
new file mode 100644
index 0000000000..3223b26184
@@ -0,0 +1,36 @@
+test_expect_success "setup proc-receive hook (ok, $PROTOCOL/porcelain)" '
+	write_script "$upstream/hooks/proc-receive" <<-EOF
+	printf >&2 "# proc-receive hook\n"
+	test-tool proc-receive -v \
+		-r "ok refs/for/master/topic"
+	EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push         :                       refs/for/master/topic
+test_expect_success "proc-receive: ok ($PROTOCOL/porcelain)" '
+	git -C workbench push --porcelain origin \
+		HEAD:refs/for/master/topic \
+		>out 2>&1 &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	remote: # pre-receive hook
+	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: # proc-receive hook
+	remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: proc-receive> ok refs/for/master/topic
+	remote: # post-receive hook
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	To <URL/of/upstream.git>
+	*    HEAD:refs/for/master/topic    [new reference]
+	Done
+	EOF
+	test_cmp expect actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'
t/t5411/test-0032-report-with-options.sh new file +256 -0

256 lines not on this page · raw message

t/t5411/test-0033-report-with-options--porcelain.sh new file +265 -0

265 lines not on this page · raw message

t/t5411/test-0034-report-ft.sh new file +44 -0

44 lines not on this page · raw message

t/t5411/test-0035-report-ft--porcelain.sh new file +45 -0

45 lines not on this page · raw message

t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh new file +159 -0

159 lines not on this page · raw message

t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh new file +162 -0

162 lines not on this page · raw message

t/t5411/test-0038-report-mixed-refs.sh new file +89 -0

89 lines not on this page · raw message

t/t5411/test-0039-report-mixed-refs--porcelain.sh new file +91 -0

91 lines not on this page · raw message

Signature · 1 line
2.26.2.543.ge7de2a6e37
author
#199 lore raw

PATCH v18 4/10 receive-pack: feed report options to post-receive

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

When commands are fed to the "post-receive" hook, report options will be parsed and the real old-oid, new-oid, reference name will feed to the "post-receive" hook.

---
 builtin/receive-pack.c                        | 30 ++++++++++++++++---
 t/t5411/test-0032-report-with-options.sh      | 14 ++++-----
 ...est-0033-report-with-options--porcelain.sh | 14 ++++-----
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 11 +++++--
 ...rt-multi-rewrite-for-one-ref--porcelain.sh | 11 +++++--
 t/t5411/test-0038-report-mixed-refs.sh        |  2 +-
 .../test-0039-report-mixed-refs--porcelain.sh |  2 +-
 7 files changed, 58 insertions(+), 26 deletions(-)
builtin/receive-pack.c +26 -4
index 2b63b92545..38f230248d 100644
@@ -694,6 +694,7 @@ static void prepare_push_cert_sha1(struct child_process *proc)
 
 struct receive_hook_feed_state {
 	struct command *cmd;
+	struct ref_push_report *report;
 	int skip_broken;
 	struct strbuf buf;
 	const struct string_list *push_options;
@@ -781,11 +782,31 @@ static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep)
 		cmd = cmd->next;
 	if (!cmd)
 		return -1; /* EOF */
+	if (!bufp)
+		return 0; /* OK, can feed something. */
 	strbuf_reset(&state->buf);
-	strbuf_addf(&state->buf, "%s %s %s\n",
-		    oid_to_hex(&cmd->old_oid), oid_to_hex(&cmd->new_oid),
-		    cmd->ref_name);
-	state->cmd = cmd->next;
+	if (!state->report)
+		state->report = cmd->report;
+	if (state->report) {
+		struct object_id *old_oid;
+		struct object_id *new_oid;
+		const char *ref_name;
+
+		old_oid = state->report->old_oid ? state->report->old_oid : &cmd->old_oid;
+		new_oid = state->report->new_oid ? state->report->new_oid : &cmd->new_oid;
+		ref_name = state->report->ref_name ? state->report->ref_name : cmd->ref_name;
+		strbuf_addf(&state->buf, "%s %s %s\n",
+			    oid_to_hex(old_oid), oid_to_hex(new_oid),
+			    ref_name);
+		state->report = state->report->next;
+		if (!state->report)
+			state->cmd = cmd->next;
+	} else {
+		strbuf_addf(&state->buf, "%s %s %s\n",
+			    oid_to_hex(&cmd->old_oid), oid_to_hex(&cmd->new_oid),
+			    cmd->ref_name);
+		state->cmd = cmd->next;
+	}
 	if (bufp) {
 		*bufp = state->buf.buf;
 		*sizep = state->buf.len;
@@ -804,6 +825,7 @@ static int run_receive_hook(struct command *commands,
 	strbuf_init(&state.buf, 0);
 	state.cmd = commands;
 	state.skip_broken = skip_broken;
+	state.report = NULL;
 	if (feed_receive_hook(&state, NULL, NULL))
 		return 0;
 	state.cmd = commands;
t/t5411/test-0032-report-with-options.sh +7 -7
index a743aa8018..c559c207fa 100644
@@ -54,7 +54,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL)" '
 	remote: proc-receive> ok refs/for/master/topic
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -87,7 +87,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: proc-receive> option forced-update
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -121,7 +121,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL)
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: proc-receive> option old-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -153,7 +153,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" '
 	remote: proc-receive> ok refs/for/master/topic
 	remote: proc-receive> option old-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -187,7 +187,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL)
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -237,9 +237,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
 	remote: proc-receive> option forced-update
 	remote: proc-receive> option new-oid <COMMIT-A>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/next/topic
 	 * [new reference] HEAD -> refs/for/a/b/c/topic
t/t5411/test-0033-report-with-options--porcelain.sh +7 -7
index 439b97b06e..ea9312234e 100644
@@ -55,7 +55,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)"
 	remote: proc-receive> ok refs/for/master/topic
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -90,7 +90,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: proc-receive> option forced-update
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -125,7 +125,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: proc-receive> option old-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -158,7 +158,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)"
 	remote: proc-receive> ok refs/for/master/topic
 	remote: proc-receive> option old-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -193,7 +193,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -245,9 +245,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc
 	remote: proc-receive> option forced-update
 	remote: proc-receive> option new-oid <COMMIT-A>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/next/topic    [new reference]
 	*    HEAD:refs/for/a/b/c/topic    [new reference]
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +8 -3
index 12acf9ea1f..67cc4a8a4c 100644
@@ -41,7 +41,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -99,7 +101,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	remote: proc-receive> option new-oid <COMMIT-A>
 	remote: proc-receive> option forced-update
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
@@ -145,7 +149,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/for/master/topic
 	EOF
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +8 -3
index f4a2c56e14..1dc8551bc6 100644
@@ -41,7 +41,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -100,7 +102,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	remote: proc-receive> option new-oid <COMMIT-A>
 	remote: proc-receive> option forced-update
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
@@ -147,7 +151,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
 	To <URL/of/upstream.git>
 	*    HEAD:refs/for/master/topic    [new reference]
 	Done
t/t5411/test-0038-report-mixed-refs.sh +1 -1
index 1dd6a97a97..bfc8d586d6 100644
@@ -53,7 +53,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
 	 <OID-A>..<OID-B> <COMMIT-B> -> master
 	 * [new branch] HEAD -> bar
t/t5411/test-0039-report-mixed-refs--porcelain.sh +1 -1
index 32ebf63dcf..5d021a4837 100644
@@ -53,7 +53,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
 	     <COMMIT-B>:refs/heads/master    <OID-A>..<OID-B>
 	*    HEAD:refs/heads/bar    [new branch]
Signature · 1 line
2.26.2.543.ge7de2a6e37
author
#200 lore raw

PATCH v18 5/10 New capability "report-status-v2" for git-push

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

The new introduced "proc-receive" hook may handle a command for a pseudo-reference with a zero-old as its old-oid, while the hook may create or update a reference with different name, different new-oid, and different old-oid (the reference may exist already with a non-zero old-oid). Current "report-status" protocol cannot report the status for such reference rewrite.

Add new capability "report-status-v2" and new report protocol which is not backward compatible for report of git-push.

If a user pushes to a pseudo-reference "refs/for/master/topic", and "receive-pack" creates two new references "refs/changes/23/123/1" and "refs/changes/24/124/1", for client without the knowledge of "report-status-v2", "receive-pack" will only send "ok/ng" directives in the report, such as:

ok ref/for/master/topic

But for client which has the knowledge of "report-status-v2", "receive-pack" will use "option" directives to report more attributes for the reference given by the above "ok/ng" directive.

ok refs/for/master/topic
option refname refs/changes/23/123/1
option new-oid <new-oid>
ok refs/for/master/topic
option refname refs/changes/24/124/1
option new-oid <new-oid>

The client will report two new created references to the end user.

---
 builtin/receive-pack.c                        |  54 +++++++-
 builtin/send-pack.c                           |  19 +++
 remote.h                                      |   1 +
 send-pack.c                                   | 101 +++++++++++---
 t/t5411-proc-receive-hook.sh                  |   9 ++
 t/t5411/once-0010-report-status-v1.sh         |  90 ++++++++++++
 t/t5411/test-0032-report-with-options.sh      |  14 +-
 ...est-0033-report-with-options--porcelain.sh |  14 +-
 ...t-0036-report-multi-rewrite-for-one-ref.sh |  11 +-
 ...rt-multi-rewrite-for-one-ref--porcelain.sh |  11 +-
 t/t5411/test-0038-report-mixed-refs.sh        |   2 +-
 .../test-0039-report-mixed-refs--porcelain.sh |   2 +-
 transport-helper.c                            | 128 ++++++++++++++----
 transport.c                                   | 116 ++++++++++++----
 14 files changed, 472 insertions(+), 100 deletions(-)
 create mode 100644 t/t5411/once-0010-report-status-v1.sh
builtin/receive-pack.c +52 -2
index 38f230248d..d6a216b2e3 100644
@@ -56,6 +56,7 @@ static int advertise_push_options;
 static int unpack_limit = 100;
 static off_t max_input_size;
 static int report_status;
+static int report_status_v2;
 static int use_sideband;
 static int use_atomic;
 static int use_push_options;
@@ -239,7 +240,7 @@ static void show_ref(const char *path, const struct object_id *oid)
 		struct strbuf cap = STRBUF_INIT;
 
 		strbuf_addstr(&cap,
-			      "report-status delete-refs side-band-64k quiet");
+			      "report-status report-status-v2 delete-refs side-band-64k quiet");
 		if (advertise_atomic_push)
 			strbuf_addstr(&cap, " atomic");
 		if (prefer_ofs_delta)
@@ -1937,6 +1938,8 @@ static struct command *read_head_info(struct packet_reader *reader,
 			const char *feature_list = reader->line + linelen + 1;
 			if (parse_feature_request(feature_list, "report-status"))
 				report_status = 1;
+			if (parse_feature_request(feature_list, "report-status-v2"))
+				report_status_v2 = 1;
 			if (parse_feature_request(feature_list, "side-band-64k"))
 				use_sideband = LARGE_PACKET_MAX;
 			if (parse_feature_request(feature_list, "quiet"))
@@ -2248,6 +2251,51 @@ static void report(struct command *commands, const char *unpack_status)
 	strbuf_release(&buf);
 }
 
+static void report_v2(struct command *commands, const char *unpack_status)
+{
+	struct command *cmd;
+	struct strbuf buf = STRBUF_INIT;
+	struct ref_push_report *report;
+
+	packet_buf_write(&buf, "unpack %s\n",
+			 unpack_status ? unpack_status : "ok");
+	for (cmd = commands; cmd; cmd = cmd->next) {
+		int count = 0;
+
+		if (cmd->error_string) {
+			packet_buf_write(&buf, "ng %s %s\n",
+					 cmd->ref_name,
+					 cmd->error_string);
+			continue;
+		}
+		packet_buf_write(&buf, "ok %s\n",
+				 cmd->ref_name);
+		for (report = cmd->report; report; report = report->next) {
+			if (count++ > 0)
+				packet_buf_write(&buf, "ok %s\n",
+						 cmd->ref_name);
+			if (report->ref_name)
+				packet_buf_write(&buf, "option refname %s\n",
+						 report->ref_name);
+			if (report->old_oid)
+				packet_buf_write(&buf, "option old-oid %s\n",
+						 oid_to_hex(report->old_oid));
+			if (report->new_oid)
+				packet_buf_write(&buf, "option new-oid %s\n",
+						 oid_to_hex(report->new_oid));
+			if (report->forced_update)
+				packet_buf_write(&buf, "option forced-update\n");
+		}
+	}
+	packet_buf_flush(&buf);
+
+	if (use_sideband)
+		send_sideband(1, 1, buf.buf, buf.len, use_sideband);
+	else
+		write_or_die(1, buf.buf, buf.len);
+	strbuf_release(&buf);
+}
+
 static int delete_only(struct command *commands)
 {
 	struct command *cmd;
@@ -2356,7 +2404,9 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
 				 &push_options);
 		if (pack_lockfile)
 			unlink_or_warn(pack_lockfile);
-		if (report_status)
+		if (report_status_v2)
+			report_v2(commands, unpack_status);
+		else if (report_status)
 			report(commands, unpack_status);
 		run_receive_hook(commands, "post-receive", 1,
 				 &push_options);
builtin/send-pack.c +19 -0
index f2c5a34402..2777cc4371 100644
@@ -29,10 +29,12 @@ static struct send_pack_args args;
 static void print_helper_status(struct ref *ref)
 {
 	struct strbuf buf = STRBUF_INIT;
+	struct ref_push_report *report;
 
 	for (; ref; ref = ref->next) {
 		const char *msg = NULL;
 		const char *res;
+		int count = 0;
 
 		switch(ref->status) {
 		case REF_STATUS_NONE:
@@ -94,6 +96,23 @@ static void print_helper_status(struct ref *ref)
 		}
 		strbuf_addch(&buf, '\n');
 
+		if (ref->status == REF_STATUS_OK) {
+			for (report = ref->report; report; report = report->next) {
+				if (count++ > 0)
+					strbuf_addf(&buf, "ok %s\n", ref->name);
+				if (report->ref_name)
+					strbuf_addf(&buf, "option refname %s\n",
+						report->ref_name);
+				if (report->old_oid)
+					strbuf_addf(&buf, "option old-oid %s\n",
+						oid_to_hex(report->old_oid));
+				if (report->new_oid)
+					strbuf_addf(&buf, "option new-oid %s\n",
+						oid_to_hex(report->new_oid));
+				if (report->forced_update)
+					strbuf_addstr(&buf, "option forced-update\n");
+			}
+		}
 		write_or_die(1, buf.buf, buf.len);
 	}
 	strbuf_release(&buf);
remote.h +1 -0
index ca7735b441..6d1e5c49f8 100644
@@ -148,6 +148,7 @@ struct ref {
 		REF_STATUS_ATOMIC_PUSH_FAILED
 	} status;
 	char *remote_status;
+	struct ref_push_report *report;
 	struct ref *peer_ref; /* when renaming */
 	char name[FLEX_ARRAY]; /* more */
 };
send-pack.c +82 -19

144 lines not on this page · raw message

t/t5411-proc-receive-hook.sh +9 -0
index 3a684353a8..746487286f 100755
@@ -78,6 +78,15 @@ run_proc_receive_hook_test() {
 # Initialize the upstream repository and local workbench.
 setup_upstream_and_workbench
 
+# Load test cases that only need to be executed once.
+for t in  "$TEST_DIRECTORY"/t5411/once-*.sh
+do
+	. "$t"
+done
+
+# Initialize the upstream repository and local workbench.
+setup_upstream_and_workbench
+
 # Run test cases for 'proc-receive' hook on local file protocol.
 run_proc_receive_hook_test local
 
t/t5411/once-0010-report-status-v1.sh new file +90 -0

90 lines not on this page · raw message

t/t5411/test-0032-report-with-options.sh +7 -7
index c559c207fa..b77b78c49f 100644
@@ -56,7 +56,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL)" '
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/pull/123/head
 	EOF
 	test_cmp expect actual
 '
@@ -89,7 +89,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/pull/123/head
 	EOF
 	test_cmp expect actual
 '
@@ -123,7 +123,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL)
 	remote: # post-receive hook
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-B>..<OID-A> HEAD -> refs/pull/123/head
 	EOF
 	test_cmp expect actual
 '
@@ -155,7 +155,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" '
 	remote: # post-receive hook
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-B>..<OID-A> HEAD -> refs/for/master/topic
 	EOF
 	test_cmp expect actual
 '
@@ -189,7 +189,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL)
 	remote: # post-receive hook
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
 	EOF
 	test_cmp expect actual
 '
@@ -241,9 +241,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/next/topic
+	 * [new reference] HEAD -> refs/pull/123/head
 	 * [new reference] HEAD -> refs/for/a/b/c/topic
-	 * [new reference] HEAD -> refs/for/master/topic
+	 + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update)
 	EOF
 	test_cmp expect actual &&
 
t/t5411/test-0033-report-with-options--porcelain.sh +7 -7
index ea9312234e..1fe352b686 100644
@@ -57,7 +57,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)"
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	*    HEAD:refs/pull/123/head    [new reference]
 	Done
 	EOF
 	test_cmp expect actual
@@ -92,7 +92,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	*    HEAD:refs/pull/123/head    [new reference]
 	Done
 	EOF
 	test_cmp expect actual
@@ -127,7 +127,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/
 	remote: # post-receive hook
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/pull/123/head    <OID-B>..<OID-A>
 	Done
 	EOF
 	test_cmp expect actual
@@ -160,7 +160,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)"
 	remote: # post-receive hook
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/for/master/topic    <OID-B>..<OID-A>
 	Done
 	EOF
 	test_cmp expect actual
@@ -195,7 +195,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/
 	remote: # post-receive hook
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
 	Done
 	EOF
 	test_cmp expect actual
@@ -249,9 +249,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/next/topic    [new reference]
+	*    HEAD:refs/pull/123/head    [new reference]
 	*    HEAD:refs/for/a/b/c/topic    [new reference]
-	*    HEAD:refs/for/master/topic    [new reference]
+	+    HEAD:refs/pull/124/head    <OID-B>...<OID-A> (forced update)
 	Done
 	EOF
 	test_cmp expect actual &&
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +8 -3
index 67cc4a8a4c..27d58edd14 100644
@@ -45,7 +45,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/changes/24/124/1
+	 <OID-A>..<OID-B> HEAD -> refs/changes/25/125/1
 	EOF
 	test_cmp expect actual &&
 	git -C "$upstream" show-ref >out &&
@@ -105,7 +107,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/changes/24/124/1
+	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
+	 + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update)
 	EOF
 	test_cmp expect actual &&
 	git -C "$upstream" show-ref >out &&
@@ -152,7 +156,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/changes/23/123/1
+	 <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
 	EOF
 	test_cmp expect actual &&
 	git -C "$upstream" show-ref >out &&
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +8 -3
index 1dc8551bc6..77b5b22ed4 100644
@@ -45,7 +45,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
+	*    HEAD:refs/changes/24/124/1    [new reference]
+	     HEAD:refs/changes/25/125/1    <OID-A>..<OID-B>
 	Done
 	EOF
 	test_cmp expect actual &&
@@ -106,7 +108,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	*    HEAD:refs/changes/24/124/1    [new reference]
+	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
+	+    HEAD:refs/changes/25/125/1    <OID-B>...<OID-A> (forced update)
 	Done
 	EOF
 	test_cmp expect actual &&
@@ -154,7 +158,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
 	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	*    HEAD:refs/changes/23/123/1    [new reference]
+	     HEAD:refs/changes/24/124/2    <OID-A>..<OID-B>
 	Done
 	EOF
 	test_cmp expect actual &&
t/t5411/test-0038-report-mixed-refs.sh +1 -1
index bfc8d586d6..a74a2cb449 100644
@@ -60,7 +60,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
 	 * [new branch] HEAD -> baz
 	 * [new reference] HEAD -> refs/for/next/topic2
 	 * [new branch] HEAD -> foo
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
 	 ! [remote rejected] HEAD -> refs/for/next/topic1 (fail to call Web API)
 	 ! [remote rejected] HEAD -> refs/for/next/topic3 (proc-receive failed to report status)
 	EOF
t/t5411/test-0039-report-mixed-refs--porcelain.sh +1 -1
index 5d021a4837..e4baa13ea3 100644
@@ -60,7 +60,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
 	*    HEAD:refs/heads/baz    [new branch]
 	*    HEAD:refs/for/next/topic2    [new reference]
 	*    HEAD:refs/heads/foo    [new branch]
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
 	!    HEAD:refs/for/next/topic1    [remote rejected] (fail to call Web API)
 	!    HEAD:refs/for/next/topic3    [remote rejected] (proc-receive failed to report status)
 	Done
transport-helper.c +99 -29

174 lines not on this page · raw message

transport.c +88 -28

218 lines not on this page · raw message

Signature · 1 line
2.26.2.543.ge7de2a6e37
author
#201 lore raw

PATCH v18 6/10 doc: add document for capability report-status-v2

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

Add ABNF notation for capability 'report-status-v2' which extends capability 'report-status' by adding additional option lines.

---
 Documentation/technical/pack-protocol.txt     | 43 +++++++++++++++++--
 .../technical/protocol-capabilities.txt       | 17 ++++++--
 2 files changed, 54 insertions(+), 6 deletions(-)
Documentation/technical/pack-protocol.txt +40 -3
index d5ce4eea8a..7547b9ca89 100644
@@ -503,8 +503,8 @@ The reference discovery phase is done nearly the same way as it is in the
 fetching protocol. Each reference obj-id and name on the server is sent
 in packet-line format to the client, followed by a flush-pkt.  The only
 real difference is that the capability listing is different - the only
-possible values are 'report-status', 'delete-refs', 'ofs-delta' and
-'push-options'.
+possible values are 'report-status', 'report-status-v2', 'delete-refs',
+'ofs-delta', 'atomic' and 'push-options'.
 
 Reference Update Request and Packfile Transfer
 ----------------------------------------------
@@ -625,7 +625,7 @@ Report Status
 -------------
 
 After receiving the pack data from the sender, the receiver sends a
-report if 'report-status' capability is in effect.
+report if 'report-status' or 'report-status-v2' capability is in effect.
 It is a short listing of what happened in that update.  It will first
 list the status of the packfile unpacking as either 'unpack ok' or
 'unpack [error]'.  Then it will list the status for each of the references
@@ -647,6 +647,43 @@ update was successful, or 'ng [refname] [error]' if the update was not.
   error-msg         = 1*(OCTET) ; where not "ok"
 ----
 
+New capability "report-status-v2" extends the protocol by adding new option
+lines in order to support reporting of reference rewritten by the
+"proc-receive" hook.  The "proc-receive" hook may handle a command for a
+pseudo-reference which may create or update one or more references, and each
+reference may have different name, different new-oid, and different old-oid.
+
+----
+  report-status-v2  = unpack-status
+		      1*(command-status-v2)
+		      flush-pkt
+
+  unpack-status     = PKT-LINE("unpack" SP unpack-result)
+  unpack-result     = "ok" / error-msg
+
+  command-status-v2 = command-ok-v2 / command-fail-v2
+  command-ok-v2     = command-ok
+		      *option-line
+  command-fail-v2   = command-fail
+		      *option-line
+
+  command-ok        = PKT-LINE("ok" SP refname)
+  command-fail      = PKT-LINE("ng" SP refname SP error-msg)
+
+  error-msg         = 1*(OCTET) ; where not "ok"
+
+  option-line       = *1(option-refname)
+		      *1(option-old-oid)
+		      *1(option-new-oid)
+		      *1(option-forced-update)
+
+  option-refname    = PKT-LINE("option" SP "refname" SP refname)
+  option-old-oid    = PKT-LINE("option" SP "old-oid" SP obj-id)
+  option-new-oid    = PKT-LINE("option" SP "new-oid" SP obj-id)
+  option-force      = PKT-LINE("option" SP "forced-update")
+
+----
+
 Updates can be unsuccessful for a number of reasons.  The reference can have
 changed since the reference discovery phase was originally sent, meaning
 someone pushed in the meantime.  The reference being pushed could be a
Documentation/technical/protocol-capabilities.txt +14 -3
index 2b267c0da6..91fd976094 100644
@@ -22,9 +22,9 @@ was sent.  Server MUST NOT ignore capabilities that client requested
 and server advertised.  As a consequence of these rules, server MUST
 NOT advertise capabilities it does not understand.
 
-The 'atomic', 'report-status', 'delete-refs', 'quiet', and 'push-cert'
-capabilities are sent and recognized by the receive-pack (push to server)
-process.
+The 'atomic', 'report-status', 'report-status-v2', 'delete-refs', 'quiet',
+and 'push-cert' capabilities are sent and recognized by the receive-pack
+(push to server) process.
 
 The 'ofs-delta' and 'side-band-64k' capabilities are sent and recognized
 by both upload-pack and receive-pack protocols.  The 'agent' capability
@@ -269,6 +269,17 @@ each reference was updated successfully.  If any of those were not
 successful, it will send back an error message.  See pack-protocol.txt
 for example messages.
 
+report-status-v2
+----------------
+
+Capability 'report-status-v2' extends capability 'report-status' by
+adding new option lines in order to support reference rewritten by
+the"proc-receive" hook.  The "proc-receive" hook may handle a command
+for a pseudo-reference which may create or update a reference with
+different name, new-oid, and old-oid.  While the capability
+"report-status" cannot report for such case.  See pack-protocol.txt
+for details.
+
 delete-refs
 -----------
 
Signature · 1 line
2.26.2.543.ge7de2a6e37
author
#202 lore raw

PATCH v18 7/10 receive-pack: new config receive.procReceiveRefs

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

Add a new multi-valued config variable "receive.procReceiveRefs" for receive-pack command, like the follows:

    git config --system --add receive.procReceiveRefs refs/for
    git config --system --add receive.procReceiveRefs refs/drafts

If the specific prefix strings given by the config variables match the reference names of the commands which are sent from git client to receive-pack, these commands will be executed by an external hook (named "proc-receive"), instead of the internal execute_commands function.

For example, if it is set to "refs/for", pushing to a reference such as "refs/for/master" will not create or update reference "refs/for/master", but may create or update a pull request directly by running the hook "proc-receive".

Optional modifiers can be provided in the beginning of the value to filter commands for specific actions: create (a), mofify (m), delete (d). A ! can be included in the modifiers to negate the reference prefix entry. E.g.:

    git config --system --add receive.procReceiveRefs ad:refs/heads
---
 Documentation/config/receive.txt              |  21 +++
 builtin/receive-pack.c                        | 106 ++++++++++++++-
 t/t5411/once-0010-report-status-v1.sh         |   4 +
 t/t5411/test-0010-proc-receive-settings.sh    |   7 +
 t/t5411/test-0040-process-all-refs.sh         | 113 ++++++++++++++++
 .../test-0041-process-all-refs--porcelain.sh  | 114 ++++++++++++++++
 t/t5411/test-0050-proc-receive-refs.sh        | 128 ++++++++++++++++++
 7 files changed, 486 insertions(+), 7 deletions(-)
 create mode 100644 t/t5411/test-0010-proc-receive-settings.sh
 create mode 100644 t/t5411/test-0040-process-all-refs.sh
 create mode 100644 t/t5411/test-0041-process-all-refs--porcelain.sh
 create mode 100644 t/t5411/test-0050-proc-receive-refs.sh
Documentation/config/receive.txt +21 -0
index 65f78aac37..86bb9adeb7 100644
@@ -114,6 +114,27 @@ receive.hideRefs::
 	An attempt to update or delete a hidden ref by `git push` is
 	rejected.
 
+receive.procReceiveRefs::
+	This is a multi-valued variable that defines reference prefixes
+	to match the commands in `receive-pack`.  Commands matching the
+	prefixes will be executed by an external hook "proc-receive",
+	instead of the internal `execute_commands` function.  If this
+	variable is not defined, the "proc-receive" hook will never be
+	used, and all commands will be executed by the internal
+	`execute_commands` function.
++
+For example, if this variable is set to "refs/for", pushing to reference
+such as "refs/for/master" will not create or update a reference named
+"refs/for/master", but may create or update a pull request directly by
+running the hook "proc-receive".
++
+Optional modifiers can be provided in the beginning of the value to filter
+commands for specific actions: create (a), mofify (m), delete (d).
+A `!` can be included in the modifiers to negate the reference prefix entry.
+E.g.:
++
+	git config --system --add receive.procReceiveRefs ad:refs/heads
+
 receive.updateServerInfo::
 	If set to true, git-receive-pack will run git-update-server-info
 	after receiving data from git-push and updating refs.
builtin/receive-pack.c +99 -7

131 lines not on this page · raw message

t/t5411/once-0010-report-status-v1.sh +4 -0
index bf410dc418..dc2cf4a522 100644
@@ -1,3 +1,7 @@
+test_expect_success "setup receive.procReceiveRefs" '
+	git -C "$upstream" config --add receive.procReceiveRefs refs/for
+'
+
 test_expect_success "setup proc-receive hook" '
 	write_script "$upstream/hooks/proc-receive" <<-EOF
 	printf >&2 "# proc-receive hook\n"
t/t5411/test-0010-proc-receive-settings.sh new file +7 -0
new file mode 100644
index 0000000000..a36809927b
@@ -0,0 +1,7 @@
+test_expect_success "add two receive.procReceiveRefs settings" '
+	(
+		cd "$upstream" &&
+		git config --add receive.procReceiveRefs refs/for &&
+		git config --add receive.procReceiveRefs refs/review/
+	)
+'
t/t5411/test-0040-process-all-refs.sh new file +113 -0

113 lines not on this page · raw message

t/t5411/test-0041-process-all-refs--porcelain.sh new file +114 -0

114 lines not on this page · raw message

t/t5411/test-0050-proc-receive-refs.sh new file +128 -0

128 lines not on this page · raw message

Signature · 1 line
2.26.2.543.ge7de2a6e37
author
#203 lore raw

PATCH v18 8/10 t5411: test updates of remote-tracking branches

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

In order to test update of remote-tracking branches for special refs, add new "remote.origin.fetch" settings and test cases.

---
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +48 -0
index 27d58edd14..8eec3a1ed8 100644
@@ -1,3 +1,18 @@
+test_expect_success "setup git config for remote-tracking of special refs" '
+	(
+		cd workbench &&
+		if ! git config --get-all remote.origin.fetch | grep refs/for/
+		then
+			git config --add remote.origin.fetch \
+				"+refs/for/*:refs/t/for/*" &&
+			git config --add remote.origin.fetch \
+				"+refs/pull/*:refs/t/pull/*" &&
+			git config --add remote.origin.fetch \
+				"+refs/changes/*:refs/t/changes/*"
+		fi
+	)
+'
+
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL)" '
 	write_script "$upstream/hooks/proc-receive" <<-EOF
 	printf >&2 "# proc-receive hook\n"
@@ -58,6 +73,17 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	test_cmp expect actual
 '
 
+test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" '
+	git -C workbench show-ref |
+		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/t/for/master/topic
+	EOF
+	test_cmp expect actual &&
+	git -C workbench update-ref -d refs/t/for/master/topic
+'
+
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" '
 	write_script "$upstream/hooks/proc-receive" <<-EOF
 	printf >&2 "# proc-receive hook\n"
@@ -120,6 +146,17 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	test_cmp expect actual
 '
 
+test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" '
+	git -C workbench show-ref |
+		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/t/for/master/topic
+	EOF
+	test_cmp expect actual &&
+	git -C workbench update-ref -d refs/t/for/master/topic
+'
+
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" '
 	write_script "$upstream/hooks/proc-receive" <<-EOF
 	printf >&2 "# proc-receive hook\n"
@@ -167,3 +204,14 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
 	EOF
 	test_cmp expect actual
 '
+
+test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" '
+	git -C workbench show-ref |
+		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/t/for/master/topic
+	EOF
+	test_cmp expect actual &&
+	git -C workbench update-ref -d refs/t/for/master/topic
+'
Signature · 1 line
2.26.2.543.ge7de2a6e37
author
#204 lore raw

PATCH v18 9/10 transport: parse report options for tracking refs

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

When pushing a pseudo reference (such as "refs/for/master/topic"), may create or update one or more references. The real names of the references will be stored in the report options. Parse report options to create or update remote-tracking branches properly.

---
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 22 +++++++---
 transport.c                                   | 40 ++++++++++++++-----
 2 files changed, 46 insertions(+), 16 deletions(-)
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +16 -6
index 8eec3a1ed8..73283d81e8 100644
@@ -78,10 +78,14 @@ test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" '
 		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
 	make_user_friendly_and_stable_output <out >actual &&
 	cat >expect <<-EOF &&
-	<COMMIT-A> refs/t/for/master/topic
+	<COMMIT-A> refs/t/changes/24/124/1
+	<COMMIT-B> refs/t/changes/25/125/1
+	<COMMIT-B> refs/t/for/master/topic
 	EOF
 	test_cmp expect actual &&
-	git -C workbench update-ref -d refs/t/for/master/topic
+	git -C workbench update-ref -d refs/t/for/master/topic &&
+	git -C workbench update-ref -d refs/t/changes/24/124/1 &&
+	git -C workbench update-ref -d refs/t/changes/25/125/1
 '
 
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" '
@@ -151,10 +155,14 @@ test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" '
 		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
 	make_user_friendly_and_stable_output <out >actual &&
 	cat >expect <<-EOF &&
-	<COMMIT-A> refs/t/for/master/topic
+	<COMMIT-A> refs/t/changes/24/124/1
+	<COMMIT-A> refs/t/changes/25/125/1
+	<COMMIT-B> refs/t/for/master/topic
 	EOF
 	test_cmp expect actual &&
-	git -C workbench update-ref -d refs/t/for/master/topic
+	git -C workbench update-ref -d refs/t/for/master/topic &&
+	git -C workbench update-ref -d refs/t/changes/24/124/1 &&
+	git -C workbench update-ref -d refs/t/changes/25/125/1
 '
 
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" '
@@ -210,8 +218,10 @@ test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" '
 		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
 	make_user_friendly_and_stable_output <out >actual &&
 	cat >expect <<-EOF &&
-	<COMMIT-A> refs/t/for/master/topic
+	<COMMIT-A> refs/t/changes/23/123/1
+	<COMMIT-B> refs/t/changes/24/124/2
 	EOF
 	test_cmp expect actual &&
-	git -C workbench update-ref -d refs/t/for/master/topic
+	git -C workbench update-ref -d refs/t/changes/24/124/1 &&
+	git -C workbench update-ref -d refs/t/changes/25/125/2
 '
transport.c +30 -10
index e146de6c4e..7d37baea64 100644
@@ -437,28 +437,48 @@ int transport_refs_pushed(struct ref *ref)
 	return 0;
 }
 
-void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose)
+static void update_tracking_ref(struct remote *remote, char *refname,
+				struct object_id *new_oid, int deletion,
+				int verbose)
 {
 	struct refspec_item rs;
 
-	if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
-		return;
-
-	rs.src = ref->name;
+	rs.src = refname;
 	rs.dst = NULL;
-
 	if (!remote_find_tracking(remote, &rs)) {
 		if (verbose)
 			fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
-		if (ref->deletion) {
+		if (deletion)
 			delete_ref(NULL, rs.dst, NULL, 0);
-		} else
-			update_ref("update by push", rs.dst, &ref->new_oid,
-				   NULL, 0, 0);
+		else
+			update_ref("update by push", rs.dst, new_oid,
+				NULL, 0, 0);
 		free(rs.dst);
 	}
 }
 
+void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose)
+{
+	char *refname;
+	struct object_id *new_oid;
+	struct ref_push_report *report;
+
+	if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
+		return;
+
+	report = ref->report;
+	if (!report)
+		update_tracking_ref(remote, ref->name, &ref->new_oid,
+				    ref->deletion, verbose);
+	else
+		for (; report; report = report->next) {
+			refname = report->ref_name ? (char *)report->ref_name : ref->name;
+			new_oid = report->new_oid ? report->new_oid : &ref->new_oid;
+			update_tracking_ref(remote, refname, new_oid,
+					    is_null_oid(new_oid), verbose);
+		}
+}
+
 static void print_ref_status(char flag, const char *summary,
 			     struct ref *to, struct ref *from, const char *msg,
 			     struct ref_push_report *report,
Signature · 1 line
2.26.2.543.ge7de2a6e37
author
#205 lore raw

PATCH v18 10/10 doc: add documentation for the proc-receive hook

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

"git receive-pack" that accepts requests by "git push" learned to outsource some of the ref updates to the new "proc-receive" hook.

---
 Documentation/githooks.txt | 62 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 62 insertions(+)
Documentation/githooks.txt +62 -0
index 81f2a87e88..d66154f606 100644
@@ -333,6 +333,68 @@ The default 'update' hook, when enabled--and with
 `hooks.allowunannotated` config option unset or set to false--prevents
 unannotated tags to be pushed.
 
+[[proc-receive]]
+proc-receive
+~~~~~~~~~~~~
+
+This hook is invoked by linkgit:git-receive-pack[1].  If the server has
+set the multi-valued config variable `receive.procReceiveRefs`, and the
+commands sent to 'receive-pack' have matching reference names, these
+commands will be executed by this hook, instead of by the internal
+`execute_commands()` function.  This hook is responsible for updating
+the relevant references and reporting the results back to 'receive-pack'.
+
+This hook executes once for the receive operation.  It takes no
+arguments, but uses a pkt-line format protocol to communicate with
+'receive-pack' to read commands, push-options and send results.  In the
+following example for the protocol, the letter 'S' stands for
+'receive-pack' and the letter 'H' stands for this hook.
+
+    # Version and features negotiation.
+    S: PKT-LINE(version=1\0push-options atomic...)
+    S: flush-pkt
+    H: PKT-LINE(version=1\0push-options...)
+    H: flush-pkt
+
+    # Send commands from server to the hook.
+    S: PKT-LINE(<old-oid> <new-oid> <ref>)
+    S: ... ...
+    S: flush-pkt
+    # Send push-options only if the 'push-options' feature is enabled.
+    S: PKT-LINE(push-option)
+    S: ... ...
+    S: flush-pkt
+
+    # Receive result from the hook.
+    # OK, run this command successfully.
+    H: PKT-LINE(ok <ref>)
+    # NO, I reject it.
+    H: PKT-LINE(ng <ref> <reason>)
+    # Fall through, let 'receive-pack' to execute it.
+    H: PKT-LINE(ok <ref>)
+    H: PKT-LINE(option fall-through)
+    # OK, but has an alternate reference.  The alternate reference name
+    # and other status can be given in options
+    H: PKT-LINE(ok <ref>)
+    H: PKT-LINE(option refname <refname>)
+    H: PKT-LINE(option old-oid <old-oid>)
+    H: PKT-LINE(option new-oid <new-oid>)
+    H: PKT-LINE(option forced-update)
+    H: ... ...
+    H: flush-pkt
+
+Each command for the 'proc-receive' hook may point to a pseudo-reference
+and always has a zero-old as its old-oid, while the 'proc-receive' hook
+may update an alternate reference and the alternate reference may exist
+already with a non-zero old-oid.  For this case, this hook will use
+"option" directives to report extended attributes for the reference given
+by the above "ok/ng" directive.
+
+The report of the commands of this hook should have the same order as
+the input.  The exit status of the 'proc-receive' hook only determines
+the success or failure of the group of commands sent to it, unless
+atomic push is in use.
+
 [[post-receive]]
 post-receive
 ~~~~~~~~~~~~
Signature · 1 line
2.26.2.543.ge7de2a6e37
author
#206 lore raw

PATCH v16 1/11 transport: not report a non-head push as a branch

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

When pushing a new reference (not a head or tag), report it as a new reference instead of a new branch.

---
 t/t5516-fetch-push.sh | 2 +-
 transport.c           | 9 ++++++---
 2 files changed, 7 insertions(+), 4 deletions(-)
t/t5516-fetch-push.sh +1 -1
index 9c6218f568..77938db77f 100755
@@ -1039,7 +1039,7 @@ test_force_fetch_tag "annotated tag" "-f -a -m'tag message'"
 test_expect_success 'push --porcelain' '
 	mk_empty testrepo &&
 	echo >.git/foo  "To testrepo" &&
-	echo >>.git/foo "*	refs/heads/master:refs/remotes/origin/master	[new branch]"  &&
+	echo >>.git/foo "*	refs/heads/master:refs/remotes/origin/master	[new reference]"  &&
 	echo >>.git/foo "Done" &&
 	git push >.git/bar --porcelain  testrepo refs/heads/master:refs/remotes/origin/master &&
 	(
transport.c +6 -3
index 15f5ba4e8f..26fefd13c1 100644
@@ -500,9 +500,12 @@ static void print_ok_ref_status(struct ref *ref, int porcelain, int summary_widt
 				 porcelain, summary_width);
 	else if (is_null_oid(&ref->old_oid))
 		print_ref_status('*',
-			(starts_with(ref->name, "refs/tags/") ? "[new tag]" :
-			"[new branch]"),
-			ref, ref->peer_ref, NULL, porcelain, summary_width);
+				 (starts_with(ref->name, "refs/tags/")
+				  ? "[new tag]"
+				  : (starts_with(ref->name, "refs/heads/")
+				     ? "[new branch]"
+				     : "[new reference]")),
+				 ref, ref->peer_ref, NULL, porcelain, summary_width);
 	else {
 		struct strbuf quickref = STRBUF_INIT;
 		char type;
Signature · 1 line
2.26.1.120.g98702cf3e9
author
#207 lore raw

PATCH v16 2/11 t5411: add basic test cases for proc-receive hook

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

Topic "proc-receive-hook" will change the workflow and output of git-push. Add some basic test cases in t5411 before introducing the new topic.

---
 t/t5411-proc-receive-hook.sh                  | 108 +++++++++++++
 t/t5411/common-functions.sh                   |  56 +++++++
 t/t5411/test-0000-standard-git-push.sh        | 143 +++++++++++++++++
 .../test-0001-standard-git-push--porcelain.sh | 147 ++++++++++++++++++
 t/t5411/test-0002-pre-receive-declined.sh     |  33 ++++
 ...st-0003-pre-receive-declined--porcelain.sh |  34 ++++
 6 files changed, 521 insertions(+)
 create mode 100755 t/t5411-proc-receive-hook.sh
 create mode 100644 t/t5411/common-functions.sh
 create mode 100644 t/t5411/test-0000-standard-git-push.sh
 create mode 100644 t/t5411/test-0001-standard-git-push--porcelain.sh
 create mode 100644 t/t5411/test-0002-pre-receive-declined.sh
 create mode 100644 t/t5411/test-0003-pre-receive-declined--porcelain.sh
t/t5411-proc-receive-hook.sh new file +108 -0
new file mode 100755
index 0000000000..3a684353a8
@@ -0,0 +1,108 @@
+#!/bin/sh
+#
+# Copyright (c) 2020 Jiang Xin
+#
+
+test_description='Test proc-receive hook'
+
+. ./test-lib.sh
+
+. "$TEST_DIRECTORY"/t5411/common-functions.sh
+
+setup_upstream_and_workbench () {
+	# Refs of upstream : master(A)
+	# Refs of workbench: master(A)  tags/v123
+	test_expect_success "setup upstream and workbench" '
+		rm -rf upstream.git &&
+		rm -rf workbench &&
+		git init --bare upstream.git &&
+		git init workbench &&
+		create_commits_in workbench A B &&
+		(
+			cd workbench &&
+			# Try to make a stable fixed width for abbreviated commit ID,
+			# this fixed-width oid will be replaced with "<OID>".
+			git config core.abbrev 7 &&
+			git tag -m "v123" v123 $A &&
+			git remote add origin ../upstream.git &&
+			git push origin master &&
+			git update-ref refs/heads/master $A $B &&
+			git -C ../upstream.git update-ref \
+				refs/heads/master $A $B
+		) &&
+		TAG=$(git -C workbench rev-parse v123) &&
+
+		# setup pre-receive hook
+		write_script upstream.git/hooks/pre-receive <<-\EOF &&
+		exec >&2
+		echo "# pre-receive hook"
+		while read old new ref
+		do
+			echo "pre-receive< $old $new $ref"
+		done
+		EOF
+
+		# setup post-receive hook
+		write_script upstream.git/hooks/post-receive <<-\EOF &&
+		exec >&2
+		echo "# post-receive hook"
+		while read old new ref
+		do
+			echo "post-receive< $old $new $ref"
+		done
+		EOF
+
+		upstream=upstream.git
+	'
+}
+
+run_proc_receive_hook_test() {
+	case $1 in
+	http)
+		PROTOCOL="HTTP protocol"
+		URL_PREFIX="http://.*"
+		;;
+	local)
+		PROTOCOL="builtin protocol"
+		URL_PREFIX="\.\."
+		;;
+	esac
+
+	# Include test cases for both file and HTTP protocol
+	for t in  "$TEST_DIRECTORY"/t5411/test-*.sh
+	do
+		. "$t"
+	done
+}
+
+# Initialize the upstream repository and local workbench.
+setup_upstream_and_workbench
+
+# Run test cases for 'proc-receive' hook on local file protocol.
+run_proc_receive_hook_test local
+
+ROOT_PATH="$PWD"
+. "$TEST_DIRECTORY"/lib-gpg.sh
+. "$TEST_DIRECTORY"/lib-httpd.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
+start_httpd
+
+# Re-initialize the upstream repository and local workbench.
+setup_upstream_and_workbench
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+test_expect_success "setup for HTTP protocol" '
+	git -C upstream.git config http.receivepack true &&
+	upstream="$HTTPD_DOCUMENT_ROOT_PATH/upstream.git" &&
+	mv upstream.git "$upstream" &&
+	git -C workbench remote set-url origin "$HTTPD_URL/auth-push/smart/upstream.git" &&
+	set_askpass user@host pass@host
+'
+
+setup_askpass_helper
+
+# Run test cases for 'proc-receive' hook on HTTP protocol.
+run_proc_receive_hook_test http
+
+test_done
t/t5411/common-functions.sh new file +56 -0

56 lines not on this page · raw message

t/t5411/test-0000-standard-git-push.sh new file +143 -0

143 lines not on this page · raw message

t/t5411/test-0001-standard-git-push--porcelain.sh new file +147 -0

147 lines not on this page · raw message

t/t5411/test-0002-pre-receive-declined.sh new file +33 -0
new file mode 100644
index 0000000000..c246f7e68e
@@ -0,0 +1,33 @@
+test_expect_success "setup pre-receive hook ($PROTOCOL)" '
+	mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" &&
+	write_script "$upstream/hooks/pre-receive" <<-EOF
+	exit 1
+	EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git-push         : master(B)             next(A)
+test_expect_success "git-push is declined ($PROTOCOL)" '
+	test_must_fail git -C workbench push origin \
+		$B:refs/heads/master \
+		HEAD:refs/heads/next \
+		>out 2>&1 &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	To <URL/of/upstream.git>
+	 ! [remote rejected] <COMMIT-B> -> master (pre-receive hook declined)
+	 ! [remote rejected] HEAD -> next (pre-receive hook declined)
+	EOF
+	test_cmp expect actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success "cleanup ($PROTOCOL)" '
+	mv "$upstream/hooks/pre-receive.ok" "$upstream/hooks/pre-receive"
+'
t/t5411/test-0003-pre-receive-declined--porcelain.sh new file +34 -0
new file mode 100644
index 0000000000..b14894de81
@@ -0,0 +1,34 @@
+test_expect_success "setup pre-receive hook ($PROTOCOL/porcelain)" '
+	mv "$upstream/hooks/pre-receive" "$upstream/hooks/pre-receive.ok" &&
+	write_script "$upstream/hooks/pre-receive" <<-EOF
+	exit 1
+	EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git-push         : master(B)             next(A)
+test_expect_success "git-push is declined ($PROTOCOL/porcelain)" '
+	test_must_fail git -C workbench push --porcelain origin \
+		$B:refs/heads/master \
+		HEAD:refs/heads/next \
+		>out 2>&1 &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	To <URL/of/upstream.git>
+	!    <COMMIT-B>:refs/heads/master    [remote rejected] (pre-receive hook declined)
+	!    HEAD:refs/heads/next    [remote rejected] (pre-receive hook declined)
+	Done
+	EOF
+	test_cmp expect actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'
+
+test_expect_success "cleanup ($PROTOCOL/porcelain)" '
+	mv "$upstream/hooks/pre-receive.ok" "$upstream/hooks/pre-receive"
+'
Signature · 1 line
2.26.1.120.g98702cf3e9
author
#208 lore raw

PATCH v16 3/11 receive-pack: add new proc-receive hook

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

Git calls an internal execute_commands function to handle commands sent from client to git-receive-pack. Regardless of what references the user pushes, git creates or updates the corresponding references if the user has write-permission. A contributor who has no write-permission, cannot push to the repository directly. So, the contributor has to write commits to an alternate location, and sends pull request by emails or by other ways. We call this workflow as a distributed workflow.

It would be more convenient to work in a centralized workflow like what Gerrit provided for some cases. For example, a read-only user who cannot push to a branch directly can run the following git push command to push commits to a pseudo reference (has a prefix "refs/for/", not "refs/heads/") to create a code review.

    git push origin \
        HEAD:refs/for/<branch-name>/<session>

The <branch-name> in the above example can be as simple as "master", or a more complicated branch name like "foo/bar". The <session> in the above example command can be the local branch name of the client side, such as "my/topic".

We cannot implement a centralized workflow elegantly by using "pre-receive" + "post-receive", because Git will call the internal function "execute_commands" to create references (even the special pseudo reference) between these two hooks. Even though we can delete the temporarily created pseudo reference via the "post-receive" hook, having a temporary reference is not safe for concurrent pushes.

So, add a filter and a new handler to support this kind of workflow. The filter will check the prefix of the reference name, and if the command has a special reference name, the filter will turn a specific field (run_proc_receive) on for the command. Commands with this filed turned on will be executed by a new handler (an hook named "proc-receive") instead of the internal execute_commands function. We can use this "proc-receive" command to create pull requests or send emails for code review.

Suggested by Junio, this "proc-receive" hook reads the commands, push-options (optional), and send result using a protocol in pkt-line format. In the following example, The letter "S" stands for "receive-pack" and letter "H" stands for the hook.

# Version and features negotiation.
S: PKT-LINE(version=1\0push-options atomic...)
S: flush-pkt
H: PKT-LINE(version=1\0push-options...)
H: flush-pkt

# Send commands from server to the hook.
S: PKT-LINE(<old-oid> <new-oid> <ref>)
S: ... ...
S: flush-pkt
# Send push-options only if the 'push-options' feature is enabled.
S: PKT-LINE(push-option)
S: ... ...
S: flush-pkt

# Receive result from the hook.
# OK, run this command successfully.
H: PKT-LINE(ok <ref>)
# NO, I reject it.
H: PKT-LINE(ng <ref> <reason>)
# Fall through, let 'receive-pack' to execute it.
H: PKT-LINE(ok <ref>)
H: PKT-LINE(option fall-through)
# OK, but has an alternate reference. The alternate reference name # and other status can be given in options
H: PKT-LINE(ok <ref>)
H: PKT-LINE(option refname <refname>)
H: PKT-LINE(option old-oid <old-oid>)
H: PKT-LINE(option new-oid <new-oid>)
H: PKT-LINE(option forced-update)
H: ... ...
H: flush-pkt

After receiving a command, the hook will execute the command, and may create/update different reference. For example, a command for a pseudo reference "refs/for/master/topic" may create/update different reference such as "refs/pull/123/head". The alternate reference name and other status are given in option lines.

The list of commands returned from "proc-receive" will replace the relevant commands that are sent from user to "receive-pack", and "receive-pack" will continue to run the "execute_commands" function and other routines. Finally, the result of the execution of these commands will be reported to end user.

The reporting function from "receive-pack" to "send-pack" will be extended in latter commit just like what the "proc-receive" hook reports to "receive-pack".

---
 Makefile                                      |   1 +
 builtin/receive-pack.c                        | 351 ++++++++++++++++--
 remote.h                                      |  14 +
 t/helper/test-proc-receive.c                  | 174 +++++++++
 t/helper/test-tool.c                          |   1 +
 t/helper/test-tool.h                          |   1 +
 t/t5411/test-0011-no-hook-error.sh            |  64 ++++
 t/t5411/test-0012-no-hook-error--porcelain.sh |  66 ++++
 t/t5411/test-0013-bad-protocol.sh             | 217 +++++++++++
 t/t5411/test-0014-bad-protocol--porcelain.sh  | 160 ++++++++
 t/t5411/test-0020-report-ng.sh                |  67 ++++
 t/t5411/test-0021-report-ng--porcelain.sh     |  69 ++++
 t/t5411/test-0022-report-unexpect-ref.sh      |  45 +++
 ...est-0023-report-unexpect-ref--porcelain.sh |  46 +++
 t/t5411/test-0024-report-unknown-ref.sh       |  34 ++
 ...test-0025-report-unknown-ref--porcelain.sh |  35 ++
 t/t5411/test-0026-push-options.sh             |  79 ++++
 t/t5411/test-0027-push-options--porcelain.sh  |  82 ++++
 t/t5411/test-0030-report-ok.sh                |  35 ++
 t/t5411/test-0031-report-ok--porcelain.sh     |  36 ++
 t/t5411/test-0032-report-with-options.sh      | 256 +++++++++++++
 ...est-0033-report-with-options--porcelain.sh | 265 +++++++++++++
 t/t5411/test-0034-report-ft.sh                |  44 +++
 t/t5411/test-0035-report-ft--porcelain.sh     |  45 +++
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 159 ++++++++
 ...rt-multi-rewrite-for-one-ref--porcelain.sh | 162 ++++++++
 t/t5411/test-0038-report-mixed-refs.sh        |  89 +++++
 .../test-0039-report-mixed-refs--porcelain.sh |  91 +++++
 28 files changed, 2657 insertions(+), 31 deletions(-)
 create mode 100644 t/helper/test-proc-receive.c
 create mode 100644 t/t5411/test-0011-no-hook-error.sh
 create mode 100644 t/t5411/test-0012-no-hook-error--porcelain.sh
 create mode 100644 t/t5411/test-0013-bad-protocol.sh
 create mode 100644 t/t5411/test-0014-bad-protocol--porcelain.sh
 create mode 100644 t/t5411/test-0020-report-ng.sh
 create mode 100644 t/t5411/test-0021-report-ng--porcelain.sh
 create mode 100644 t/t5411/test-0022-report-unexpect-ref.sh
 create mode 100644 t/t5411/test-0023-report-unexpect-ref--porcelain.sh
 create mode 100644 t/t5411/test-0024-report-unknown-ref.sh
 create mode 100644 t/t5411/test-0025-report-unknown-ref--porcelain.sh
 create mode 100644 t/t5411/test-0026-push-options.sh
 create mode 100644 t/t5411/test-0027-push-options--porcelain.sh
 create mode 100644 t/t5411/test-0030-report-ok.sh
 create mode 100644 t/t5411/test-0031-report-ok--porcelain.sh
 create mode 100644 t/t5411/test-0032-report-with-options.sh
 create mode 100644 t/t5411/test-0033-report-with-options--porcelain.sh
 create mode 100644 t/t5411/test-0034-report-ft.sh
 create mode 100644 t/t5411/test-0035-report-ft--porcelain.sh
 create mode 100644 t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh
 create mode 100644 t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh
 create mode 100644 t/t5411/test-0038-report-mixed-refs.sh
 create mode 100644 t/t5411/test-0039-report-mixed-refs--porcelain.sh
Makefile +1 -0
index 3d3a39fc19..607aeabeee 100644
@@ -722,6 +722,7 @@ TEST_BUILTINS_OBJS += test-parse-pathspec-file.o
 TEST_BUILTINS_OBJS += test-path-utils.o
 TEST_BUILTINS_OBJS += test-pkt-line.o
 TEST_BUILTINS_OBJS += test-prio-queue.o
+TEST_BUILTINS_OBJS += test-proc-receive.o
 TEST_BUILTINS_OBJS += test-progress.o
 TEST_BUILTINS_OBJS += test-reach.o
 TEST_BUILTINS_OBJS += test-read-cache.o
builtin/receive-pack.c +320 -31

506 lines not on this page · raw message

remote.h +14 -0
index 11d8719b58..6dbc7e0559 100644
@@ -93,6 +93,20 @@ int for_each_remote(each_remote_fn fn, void *priv);
 
 int remote_has_url(struct remote *remote, const char *url);
 
+struct ref_push_report_options {
+	const char *ref_name;
+	struct object_id *old_oid;
+	struct object_id *new_oid;
+	unsigned int forced_update:1;
+	struct ref_push_report_options *next;
+};
+
+struct ref_push_report {
+	const char *message;
+	const char *error_message;
+	struct ref_push_report_options *options;
+};
+
 struct ref {
 	struct ref *next;
 	struct object_id old_oid;
t/helper/test-proc-receive.c new file +174 -0

174 lines not on this page · raw message

t/helper/test-tool.c +1 -0
index 590b2efca7..a0d3966b29 100644
@@ -46,6 +46,7 @@ static struct test_cmd cmds[] = {
 	{ "path-utils", cmd__path_utils },
 	{ "pkt-line", cmd__pkt_line },
 	{ "prio-queue", cmd__prio_queue },
+	{ "proc-receive", cmd__proc_receive},
 	{ "progress", cmd__progress },
 	{ "reach", cmd__reach },
 	{ "read-cache", cmd__read_cache },
t/helper/test-tool.h +1 -0
index ddc8e990e9..07034d3f38 100644
@@ -35,6 +35,7 @@ int cmd__parse_pathspec_file(int argc, const char** argv);
 int cmd__path_utils(int argc, const char **argv);
 int cmd__pkt_line(int argc, const char **argv);
 int cmd__prio_queue(int argc, const char **argv);
+int cmd__proc_receive(int argc, const char **argv);
 int cmd__progress(int argc, const char **argv);
 int cmd__reach(int argc, const char **argv);
 int cmd__read_cache(int argc, const char **argv);
t/t5411/test-0011-no-hook-error.sh new file +64 -0

64 lines not on this page · raw message

t/t5411/test-0012-no-hook-error--porcelain.sh new file +66 -0

66 lines not on this page · raw message

t/t5411/test-0013-bad-protocol.sh new file +217 -0

217 lines not on this page · raw message

t/t5411/test-0014-bad-protocol--porcelain.sh new file +160 -0

160 lines not on this page · raw message

t/t5411/test-0020-report-ng.sh new file +67 -0

67 lines not on this page · raw message

t/t5411/test-0021-report-ng--porcelain.sh new file +69 -0

69 lines not on this page · raw message

t/t5411/test-0022-report-unexpect-ref.sh new file +45 -0

45 lines not on this page · raw message

t/t5411/test-0023-report-unexpect-ref--porcelain.sh new file +46 -0

46 lines not on this page · raw message

t/t5411/test-0024-report-unknown-ref.sh new file +34 -0
new file mode 100644
index 0000000000..c3946f329a
@@ -0,0 +1,34 @@
+test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL)" '
+	write_script "$upstream/hooks/proc-receive" <<-EOF
+	printf >&2 "# proc-receive hook\n"
+	test-tool proc-receive -v \
+		-r "ok refs/for/master/topic"
+	EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push         :                       refs/for/a/b/c/my/topic
+test_expect_success "proc-receive: report unknown reference ($PROTOCOL)" '
+	test_must_fail git -C workbench push origin \
+		HEAD:refs/for/a/b/c/my/topic \
+		>out 2>&1 &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	remote: # pre-receive hook
+	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
+	remote: # proc-receive hook
+	remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
+	remote: proc-receive> ok refs/for/master/topic
+	remote: error: proc-receive reported status on unknown ref: refs/for/master/topic
+	To <URL/of/upstream.git>
+	 ! [remote rejected] HEAD -> refs/for/a/b/c/my/topic (proc-receive failed to report status)
+	EOF
+	test_cmp expect actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'
t/t5411/test-0025-report-unknown-ref--porcelain.sh new file +35 -0
new file mode 100644
index 0000000000..d093b1a579
@@ -0,0 +1,35 @@
+test_expect_success "setup proc-receive hook (unexpected ref, $PROTOCOL/porcelain)" '
+	write_script "$upstream/hooks/proc-receive" <<-EOF
+	printf >&2 "# proc-receive hook\n"
+	test-tool proc-receive -v \
+		-r "ok refs/for/master/topic"
+	EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push         :                       refs/for/a/b/c/my/topic
+test_expect_success "proc-receive: report unknown reference ($PROTOCOL/porcelain)" '
+	test_must_fail git -C workbench push --porcelain origin \
+		HEAD:refs/for/a/b/c/my/topic \
+		>out 2>&1 &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	remote: # pre-receive hook
+	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
+	remote: # proc-receive hook
+	remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/my/topic
+	remote: proc-receive> ok refs/for/master/topic
+	remote: error: proc-receive reported status on unknown ref: refs/for/master/topic
+	To <URL/of/upstream.git>
+	!    HEAD:refs/for/a/b/c/my/topic    [remote rejected] (proc-receive failed to report status)
+	Done
+	EOF
+	test_cmp expect actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'
t/t5411/test-0026-push-options.sh new file +79 -0

79 lines not on this page · raw message

t/t5411/test-0027-push-options--porcelain.sh new file +82 -0

82 lines not on this page · raw message

t/t5411/test-0030-report-ok.sh new file +35 -0
new file mode 100644
index 0000000000..44c99d3831
@@ -0,0 +1,35 @@
+test_expect_success "setup proc-receive hook (ok, $PROTOCOL)" '
+	write_script "$upstream/hooks/proc-receive" <<-EOF
+	printf >&2 "# proc-receive hook\n"
+	test-tool proc-receive -v \
+		-r "ok refs/for/master/topic"
+	EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push         :                       refs/for/master/topic
+test_expect_success "proc-receive: ok ($PROTOCOL)" '
+	git -C workbench push origin \
+		HEAD:refs/for/master/topic \
+		>out 2>&1 &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	remote: # pre-receive hook
+	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: # proc-receive hook
+	remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: proc-receive> ok refs/for/master/topic
+	remote: # post-receive hook
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	To <URL/of/upstream.git>
+	 * [new reference] HEAD -> refs/for/master/topic
+	EOF
+	test_cmp expect actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'
t/t5411/test-0031-report-ok--porcelain.sh new file +36 -0
new file mode 100644
index 0000000000..3223b26184
@@ -0,0 +1,36 @@
+test_expect_success "setup proc-receive hook (ok, $PROTOCOL/porcelain)" '
+	write_script "$upstream/hooks/proc-receive" <<-EOF
+	printf >&2 "# proc-receive hook\n"
+	test-tool proc-receive -v \
+		-r "ok refs/for/master/topic"
+	EOF
+'
+
+# Refs of upstream : master(A)
+# Refs of workbench: master(A)  tags/v123
+# git push         :                       refs/for/master/topic
+test_expect_success "proc-receive: ok ($PROTOCOL/porcelain)" '
+	git -C workbench push --porcelain origin \
+		HEAD:refs/for/master/topic \
+		>out 2>&1 &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	remote: # pre-receive hook
+	remote: pre-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: # proc-receive hook
+	remote: proc-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: proc-receive> ok refs/for/master/topic
+	remote: # post-receive hook
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	To <URL/of/upstream.git>
+	*    HEAD:refs/for/master/topic    [new reference]
+	Done
+	EOF
+	test_cmp expect actual &&
+	git -C "$upstream" show-ref >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/heads/master
+	EOF
+	test_cmp expect actual
+'
t/t5411/test-0032-report-with-options.sh new file +256 -0

256 lines not on this page · raw message

t/t5411/test-0033-report-with-options--porcelain.sh new file +265 -0

265 lines not on this page · raw message

t/t5411/test-0034-report-ft.sh new file +44 -0

44 lines not on this page · raw message

t/t5411/test-0035-report-ft--porcelain.sh new file +45 -0

45 lines not on this page · raw message

t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh new file +159 -0

159 lines not on this page · raw message

t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh new file +162 -0

162 lines not on this page · raw message

t/t5411/test-0038-report-mixed-refs.sh new file +89 -0

89 lines not on this page · raw message

t/t5411/test-0039-report-mixed-refs--porcelain.sh new file +91 -0

91 lines not on this page · raw message

Signature · 1 line
2.26.1.120.g98702cf3e9
author
#209 lore raw

PATCH v16 4/11 New capability "report-status-v2" for git-push

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

The new introduced "proc-receive" hook may handle a command for a pseudo-reference with a zero-old as its old-oid, while the hook may create or update a reference with different name, different new-oid, and different old-oid (the reference may exist already with a non-zero old-oid). Current "report-status" protocol cannot report the status for such reference rewrite.

Add new capability "report-status-v2" and new report protocol which is not backward compatible for report of git-push.

If a user pushes to a pseudo-reference "refs/for/master/topic", and "receive-pack" creates two new references "refs/changes/23/123/1" and "refs/changes/24/124/1", for client without the knowledge of "report-status-v2", "receive-pack" will only send "ok/ng" directives in the report, such as:

ok ref/for/master/topic

But for client which has the knowledge of "report-status-v2", "receive-pack" will use "option" directives to report more attributes for the reference given by the above "ok/ng" directive.

ok refs/for/master/topic
option refname refs/changes/23/123/1
option new-oid <new-oid>
ok refs/for/master/topic
option refname refs/changes/24/124/1
option new-oid <new-oid>

The client will report two new created references to the end user.

---
 builtin/receive-pack.c                        |  52 +++++++-
 builtin/send-pack.c                           |  21 +++-
 remote.c                                      |   4 +-
 remote.h                                      |   2 +-
 send-pack.c                                   |  99 ++++++++++++---
 t/t5411-proc-receive-hook.sh                  |   9 ++
 t/t5411/once-0010-report-status-v1.sh         |  83 ++++++++++++
 t/t5411/test-0032-report-with-options.sh      |  14 +--
 ...est-0033-report-with-options--porcelain.sh |  14 +--
 ...t-0036-report-multi-rewrite-for-one-ref.sh |  11 +-
 ...rt-multi-rewrite-for-one-ref--porcelain.sh |  11 +-
 t/t5411/test-0038-report-mixed-refs.sh        |   2 +-
 .../test-0039-report-mixed-refs--porcelain.sh |   2 +-
 transport-helper.c                            |  53 +++++++-
 transport.c                                   | 118 +++++++++++++-----
 15 files changed, 418 insertions(+), 77 deletions(-)
 create mode 100644 t/t5411/once-0010-report-status-v1.sh
builtin/receive-pack.c +50 -2
index 717bebd3e1..5544d03718 100644
@@ -57,6 +57,7 @@ static int advertise_push_options;
 static int unpack_limit = 100;
 static off_t max_input_size;
 static int report_status;
+static int report_status_v2;
 static int use_sideband;
 static int use_atomic;
 static int use_push_options;
@@ -240,7 +241,7 @@ static void show_ref(const char *path, const struct object_id *oid)
 		struct strbuf cap = STRBUF_INIT;
 
 		strbuf_addstr(&cap,
-			      "report-status delete-refs side-band-64k quiet");
+			      "report-status report-status-v2 delete-refs side-band-64k quiet");
 		if (advertise_atomic_push)
 			strbuf_addstr(&cap, " atomic");
 		if (prefer_ofs_delta)
@@ -1915,6 +1916,8 @@ static struct command *read_head_info(struct packet_reader *reader,
 			const char *feature_list = reader->line + linelen + 1;
 			if (parse_feature_request(feature_list, "report-status"))
 				report_status = 1;
+			if (parse_feature_request(feature_list, "report-status-v2"))
+				report_status_v2 = 1;
 			if (parse_feature_request(feature_list, "side-band-64k"))
 				use_sideband = LARGE_PACKET_MAX;
 			if (parse_feature_request(feature_list, "quiet"))
@@ -2226,6 +2229,49 @@ static void report(struct command *commands, const char *unpack_status)
 	strbuf_release(&buf);
 }
 
+static void report_v2(struct command *commands, const char *unpack_status)
+{
+	struct command *cmd;
+	struct strbuf buf = STRBUF_INIT;
+	struct ref_push_report_options *options;
+
+	packet_buf_write(&buf, "unpack %s\n",
+			 unpack_status ? unpack_status : "ok");
+	for (cmd = commands; cmd; cmd = cmd->next) {
+		int count = 0;
+
+		if (!cmd->report.error_message)
+			packet_buf_write(&buf, "ok %s\n",
+					 cmd->ref_name);
+		else
+			packet_buf_write(&buf, "ng %s %s\n",
+					 cmd->ref_name,
+					 cmd->report.error_message);
+		for (options = cmd->report.options; options; options = options->next) {
+			if (count++ > 0)
+				packet_buf_write(&buf, "ok %s\n", cmd->ref_name);
+			if (options->ref_name)
+				packet_buf_write(&buf, "option refname %s\n",
+						 options->ref_name);
+			if (options->old_oid)
+				packet_buf_write(&buf, "option old-oid %s\n",
+						 oid_to_hex(options->old_oid));
+			if (options->new_oid)
+				packet_buf_write(&buf, "option new-oid %s\n",
+						 oid_to_hex(options->new_oid));
+			if (options->forced_update)
+				packet_buf_write(&buf, "option forced-update\n");
+		}
+	}
+	packet_buf_flush(&buf);
+
+	if (use_sideband)
+		send_sideband(1, 1, buf.buf, buf.len, use_sideband);
+	else
+		write_or_die(1, buf.buf, buf.len);
+	strbuf_release(&buf);
+}
+
 static int delete_only(struct command *commands)
 {
 	struct command *cmd;
@@ -2334,7 +2380,9 @@ int cmd_receive_pack(int argc, const char **argv, const char *prefix)
 				 &push_options);
 		if (pack_lockfile)
 			unlink_or_warn(pack_lockfile);
-		if (report_status)
+		if (report_status_v2)
+			report_v2(commands, unpack_status);
+		else if (report_status)
 			report(commands, unpack_status);
 		run_receive_hook(commands, "post-receive", 1,
 				 &push_options);
builtin/send-pack.c +19 -2
index 2b9610f121..9d0df751d6 100644
@@ -29,10 +29,12 @@ static struct send_pack_args args;
 static void print_helper_status(struct ref *ref)
 {
 	struct strbuf buf = STRBUF_INIT;
+	struct ref_push_report_options *options;
 
 	for (; ref; ref = ref->next) {
 		const char *msg = NULL;
 		const char *res;
+		int count = 0;
 
 		switch(ref->status) {
 		case REF_STATUS_NONE:
@@ -86,14 +88,29 @@ static void print_helper_status(struct ref *ref)
 
 		strbuf_reset(&buf);
 		strbuf_addf(&buf, "%s %s", res, ref->name);
-		if (ref->remote_status)
-			msg = ref->remote_status;
+		if (ref->report.error_message)
+			msg = ref->report.error_message;
 		if (msg) {
 			strbuf_addch(&buf, ' ');
 			quote_two_c_style(&buf, "", msg, 0);
 		}
 		strbuf_addch(&buf, '\n');
 
+		for (options = ref->report.options; options; options = options->next) {
+			if (count++ > 0)
+				strbuf_addf(&buf, "ok %s\n", ref->name);
+			if (options->ref_name)
+				strbuf_addf(&buf, "option refname %s\n",
+					    options->ref_name);
+			if (options->old_oid)
+				strbuf_addf(&buf, "option old-oid %s\n",
+					    oid_to_hex(options->old_oid));
+			if (options->new_oid)
+				strbuf_addf(&buf, "option new-oid %s\n",
+					    oid_to_hex(options->new_oid));
+			if (options->forced_update)
+				strbuf_addstr(&buf, "option forced-update\n");
+		}
 		write_or_die(1, buf.buf, buf.len);
 	}
 	strbuf_release(&buf);
remote.c +2 -2
index 534c6426f1..cc4d542fd3 100644
@@ -789,7 +789,7 @@ struct ref *copy_ref(const struct ref *ref)
 	memcpy(cpy, ref, len);
 	cpy->next = NULL;
 	cpy->symref = xstrdup_or_null(ref->symref);
-	cpy->remote_status = xstrdup_or_null(ref->remote_status);
+	cpy->report.error_message = xstrdup_or_null(ref->report.error_message);
 	cpy->peer_ref = copy_ref(ref->peer_ref);
 	return cpy;
 }
@@ -811,7 +811,7 @@ void free_one_ref(struct ref *ref)
 	if (!ref)
 		return;
 	free_one_ref(ref->peer_ref);
-	free(ref->remote_status);
+	free((void *)ref->report.error_message);
 	free(ref->symref);
 	free(ref);
 }
remote.h +1 -1
index 6dbc7e0559..4e9a17de3c 100644
@@ -153,7 +153,7 @@ struct ref {
 		REF_STATUS_EXPECTING_REPORT,
 		REF_STATUS_ATOMIC_PUSH_FAILED
 	} status;
-	char *remote_status;
+	struct ref_push_report report;
 	struct ref *peer_ref; /* when renaming */
 	char name[FLEX_ARRAY]; /* more */
 };
send-pack.c +81 -18

140 lines not on this page · raw message

t/t5411-proc-receive-hook.sh +9 -0
index 3a684353a8..746487286f 100755
@@ -78,6 +78,15 @@ run_proc_receive_hook_test() {
 # Initialize the upstream repository and local workbench.
 setup_upstream_and_workbench
 
+# Load test cases that only need to be executed once.
+for t in  "$TEST_DIRECTORY"/t5411/once-*.sh
+do
+	. "$t"
+done
+
+# Initialize the upstream repository and local workbench.
+setup_upstream_and_workbench
+
 # Run test cases for 'proc-receive' hook on local file protocol.
 run_proc_receive_hook_test local
 
t/t5411/once-0010-report-status-v1.sh new file +83 -0

83 lines not on this page · raw message

t/t5411/test-0032-report-with-options.sh +7 -7
index a743aa8018..3742ed3c3d 100644
@@ -56,7 +56,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL)" '
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/pull/123/head
 	EOF
 	test_cmp expect actual
 '
@@ -89,7 +89,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/pull/123/head
 	EOF
 	test_cmp expect actual
 '
@@ -123,7 +123,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL)
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-B>..<OID-A> HEAD -> refs/pull/123/head
 	EOF
 	test_cmp expect actual
 '
@@ -155,7 +155,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" '
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-B>..<OID-A> HEAD -> refs/for/master/topic
 	EOF
 	test_cmp expect actual
 '
@@ -189,7 +189,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL)
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
 	EOF
 	test_cmp expect actual
 '
@@ -241,9 +241,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/next/topic
+	 * [new reference] HEAD -> refs/pull/123/head
 	 * [new reference] HEAD -> refs/for/a/b/c/topic
-	 * [new reference] HEAD -> refs/for/master/topic
+	 + <OID-B>...<OID-A> HEAD -> refs/pull/124/head (forced update)
 	EOF
 	test_cmp expect actual &&
 
t/t5411/test-0033-report-with-options--porcelain.sh +7 -7
index 439b97b06e..f18ba9f06f 100644
@@ -57,7 +57,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)"
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	*    HEAD:refs/pull/123/head    [new reference]
 	Done
 	EOF
 	test_cmp expect actual
@@ -92,7 +92,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	*    HEAD:refs/pull/123/head    [new reference]
 	Done
 	EOF
 	test_cmp expect actual
@@ -127,7 +127,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/pull/123/head    <OID-B>..<OID-A>
 	Done
 	EOF
 	test_cmp expect actual
@@ -160,7 +160,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)"
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/for/master/topic    <OID-B>..<OID-A>
 	Done
 	EOF
 	test_cmp expect actual
@@ -195,7 +195,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
 	Done
 	EOF
 	test_cmp expect actual
@@ -249,9 +249,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/next/topic    [new reference]
+	*    HEAD:refs/pull/123/head    [new reference]
 	*    HEAD:refs/for/a/b/c/topic    [new reference]
-	*    HEAD:refs/for/master/topic    [new reference]
+	+    HEAD:refs/pull/124/head    <OID-B>...<OID-A> (forced update)
 	Done
 	EOF
 	test_cmp expect actual &&
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +8 -3
index 12acf9ea1f..64662afdc6 100644
@@ -43,7 +43,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/changes/24/124/1
+	 <OID-A>..<OID-B> HEAD -> refs/changes/25/125/1
 	EOF
 	test_cmp expect actual &&
 	git -C "$upstream" show-ref >out &&
@@ -101,7 +103,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/changes/24/124/1
+	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
+	 + <OID-B>...<OID-A> HEAD -> refs/changes/25/125/1 (forced update)
 	EOF
 	test_cmp expect actual &&
 	git -C "$upstream" show-ref >out &&
@@ -147,7 +151,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	 * [new reference] HEAD -> refs/for/master/topic
+	 * [new reference] HEAD -> refs/changes/23/123/1
+	 <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
 	EOF
 	test_cmp expect actual &&
 	git -C "$upstream" show-ref >out &&
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +8 -3
index f4a2c56e14..a7e29af0c2 100644
@@ -43,7 +43,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
+	*    HEAD:refs/changes/24/124/1    [new reference]
+	     HEAD:refs/changes/25/125/1    <OID-A>..<OID-B>
 	Done
 	EOF
 	test_cmp expect actual &&
@@ -102,7 +104,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	*    HEAD:refs/changes/24/124/1    [new reference]
+	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
+	+    HEAD:refs/changes/25/125/1    <OID-B>...<OID-A> (forced update)
 	Done
 	EOF
 	test_cmp expect actual &&
@@ -149,7 +153,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc
 	remote: # post-receive hook
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
-	*    HEAD:refs/for/master/topic    [new reference]
+	*    HEAD:refs/changes/23/123/1    [new reference]
+	     HEAD:refs/changes/24/124/2    <OID-A>..<OID-B>
 	Done
 	EOF
 	test_cmp expect actual &&
t/t5411/test-0038-report-mixed-refs.sh +1 -1
index 1dd6a97a97..54bec4c026 100644
@@ -60,7 +60,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
 	 * [new branch] HEAD -> baz
 	 * [new reference] HEAD -> refs/for/next/topic2
 	 * [new branch] HEAD -> foo
-	 * [new reference] HEAD -> refs/for/master/topic
+	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
 	 ! [remote rejected] HEAD -> refs/for/next/topic1 (fail to call Web API)
 	 ! [remote rejected] HEAD -> refs/for/next/topic3 (proc-receive failed to report status)
 	EOF
t/t5411/test-0039-report-mixed-refs--porcelain.sh +1 -1
index 32ebf63dcf..605b3cb5c9 100644
@@ -60,7 +60,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
 	*    HEAD:refs/heads/baz    [new branch]
 	*    HEAD:refs/for/next/topic2    [new reference]
 	*    HEAD:refs/heads/foo    [new branch]
-	*    HEAD:refs/for/master/topic    [new reference]
+	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
 	!    HEAD:refs/for/next/topic1    [remote rejected] (fail to call Web API)
 	!    HEAD:refs/for/next/topic3    [remote rejected] (proc-receive failed to report status)
 	Done
transport-helper.c +52 -1

73 lines not on this page · raw message

transport.c +89 -29

220 lines not on this page · raw message

Signature · 1 line
2.26.1.120.g98702cf3e9
author
#210 lore raw

PATCH v16 5/11 doc: add document for capability report-status-v2

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

Add ABNF notation for capability 'report-status-v2' which extends capability 'report-status' by adding additional option lines.

---
 Documentation/technical/pack-protocol.txt     | 43 +++++++++++++++++--
 .../technical/protocol-capabilities.txt       | 17 ++++++--
 2 files changed, 54 insertions(+), 6 deletions(-)
Documentation/technical/pack-protocol.txt +40 -3
index d5ce4eea8a..7547b9ca89 100644
@@ -503,8 +503,8 @@ The reference discovery phase is done nearly the same way as it is in the
 fetching protocol. Each reference obj-id and name on the server is sent
 in packet-line format to the client, followed by a flush-pkt.  The only
 real difference is that the capability listing is different - the only
-possible values are 'report-status', 'delete-refs', 'ofs-delta' and
-'push-options'.
+possible values are 'report-status', 'report-status-v2', 'delete-refs',
+'ofs-delta', 'atomic' and 'push-options'.
 
 Reference Update Request and Packfile Transfer
 ----------------------------------------------
@@ -625,7 +625,7 @@ Report Status
 -------------
 
 After receiving the pack data from the sender, the receiver sends a
-report if 'report-status' capability is in effect.
+report if 'report-status' or 'report-status-v2' capability is in effect.
 It is a short listing of what happened in that update.  It will first
 list the status of the packfile unpacking as either 'unpack ok' or
 'unpack [error]'.  Then it will list the status for each of the references
@@ -647,6 +647,43 @@ update was successful, or 'ng [refname] [error]' if the update was not.
   error-msg         = 1*(OCTET) ; where not "ok"
 ----
 
+New capability "report-status-v2" extends the protocol by adding new option
+lines in order to support reporting of reference rewritten by the
+"proc-receive" hook.  The "proc-receive" hook may handle a command for a
+pseudo-reference which may create or update one or more references, and each
+reference may have different name, different new-oid, and different old-oid.
+
+----
+  report-status-v2  = unpack-status
+		      1*(command-status-v2)
+		      flush-pkt
+
+  unpack-status     = PKT-LINE("unpack" SP unpack-result)
+  unpack-result     = "ok" / error-msg
+
+  command-status-v2 = command-ok-v2 / command-fail-v2
+  command-ok-v2     = command-ok
+		      *option-line
+  command-fail-v2   = command-fail
+		      *option-line
+
+  command-ok        = PKT-LINE("ok" SP refname)
+  command-fail      = PKT-LINE("ng" SP refname SP error-msg)
+
+  error-msg         = 1*(OCTET) ; where not "ok"
+
+  option-line       = *1(option-refname)
+		      *1(option-old-oid)
+		      *1(option-new-oid)
+		      *1(option-forced-update)
+
+  option-refname    = PKT-LINE("option" SP "refname" SP refname)
+  option-old-oid    = PKT-LINE("option" SP "old-oid" SP obj-id)
+  option-new-oid    = PKT-LINE("option" SP "new-oid" SP obj-id)
+  option-force      = PKT-LINE("option" SP "forced-update")
+
+----
+
 Updates can be unsuccessful for a number of reasons.  The reference can have
 changed since the reference discovery phase was originally sent, meaning
 someone pushed in the meantime.  The reference being pushed could be a
Documentation/technical/protocol-capabilities.txt +14 -3
index 2b267c0da6..91fd976094 100644
@@ -22,9 +22,9 @@ was sent.  Server MUST NOT ignore capabilities that client requested
 and server advertised.  As a consequence of these rules, server MUST
 NOT advertise capabilities it does not understand.
 
-The 'atomic', 'report-status', 'delete-refs', 'quiet', and 'push-cert'
-capabilities are sent and recognized by the receive-pack (push to server)
-process.
+The 'atomic', 'report-status', 'report-status-v2', 'delete-refs', 'quiet',
+and 'push-cert' capabilities are sent and recognized by the receive-pack
+(push to server) process.
 
 The 'ofs-delta' and 'side-band-64k' capabilities are sent and recognized
 by both upload-pack and receive-pack protocols.  The 'agent' capability
@@ -269,6 +269,17 @@ each reference was updated successfully.  If any of those were not
 successful, it will send back an error message.  See pack-protocol.txt
 for example messages.
 
+report-status-v2
+----------------
+
+Capability 'report-status-v2' extends capability 'report-status' by
+adding new option lines in order to support reference rewritten by
+the"proc-receive" hook.  The "proc-receive" hook may handle a command
+for a pseudo-reference which may create or update a reference with
+different name, new-oid, and old-oid.  While the capability
+"report-status" cannot report for such case.  See pack-protocol.txt
+for details.
+
 delete-refs
 -----------
 
Signature · 1 line
2.26.1.120.g98702cf3e9
author
#211 lore raw

PATCH v16 6/11 receive-pack: feed report options to post-receive

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

When commands are fed to the "post-receive" hook, report options will be parsed and the real old-oid, new-oid, reference name will feed to the "post-receive" hook.

---
 builtin/receive-pack.c                        | 29 ++++++++++++++++---
 t/t5411/once-0010-report-status-v1.sh         |  3 +-
 t/t5411/test-0032-report-with-options.sh      | 14 ++++-----
 ...est-0033-report-with-options--porcelain.sh | 14 ++++-----
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 11 +++++--
 ...rt-multi-rewrite-for-one-ref--porcelain.sh | 11 +++++--
 t/t5411/test-0038-report-mixed-refs.sh        |  2 +-
 .../test-0039-report-mixed-refs--porcelain.sh |  2 +-
 8 files changed, 59 insertions(+), 27 deletions(-)
builtin/receive-pack.c +25 -4
index 5544d03718..e2478f34b8 100644
@@ -776,17 +776,38 @@ static int feed_receive_hook(void *state_, const char **bufp, size_t *sizep)
 {
 	struct receive_hook_feed_state *state = state_;
 	struct command *cmd = state->cmd;
+	static struct ref_push_report_options *options = NULL;
 
 	while (cmd &&
 	       state->skip_broken && (cmd->report.error_message || cmd->did_not_exist))
 		cmd = cmd->next;
 	if (!cmd)
 		return -1; /* EOF */
+	if (!bufp)
+		return 0; /* OK, can feed something. */
 	strbuf_reset(&state->buf);
-	strbuf_addf(&state->buf, "%s %s %s\n",
-		    oid_to_hex(&cmd->old_oid), oid_to_hex(&cmd->new_oid),
-		    cmd->ref_name);
-	state->cmd = cmd->next;
+	if (!options)
+		options = cmd->report.options;
+	if (options) {
+		struct object_id *old_oid;
+		struct object_id *new_oid;
+		const char *ref_name;
+
+		old_oid = options->old_oid ? options->old_oid : &cmd->old_oid;
+		new_oid = options->new_oid ? options->new_oid : &cmd->new_oid;
+		ref_name = options->ref_name ? options->ref_name : cmd->ref_name;
+		strbuf_addf(&state->buf, "%s %s %s\n",
+			    oid_to_hex(old_oid), oid_to_hex(new_oid),
+			    ref_name);
+		options = options->next;
+		if (!options)
+			state->cmd = cmd->next;
+	} else {
+		strbuf_addf(&state->buf, "%s %s %s\n",
+			    oid_to_hex(&cmd->old_oid), oid_to_hex(&cmd->new_oid),
+			    cmd->ref_name);
+		state->cmd = cmd->next;
+	}
 	if (bufp) {
 		*bufp = state->buf.buf;
 		*sizep = state->buf.len;
t/t5411/once-0010-report-status-v1.sh +2 -1
index f93d760cfd..4385628d06 100644
@@ -68,7 +68,8 @@ test_expect_success "proc-receive: report status v1" '
 	post-receive< <COMMIT-A> <COMMIT-B> refs/heads/master
 	post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic1
 	post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
-	post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic2
+	post-receive< <ZERO-OID> <COMMIT-A> refs/for/changes/23/123/1
+	post-receive< <COMMIT-B> <COMMIT-A> refs/for/changes/24/124/2
 	EOF
 	test_cmp expect actual &&
 
t/t5411/test-0032-report-with-options.sh +7 -7
index 3742ed3c3d..b77b78c49f 100644
@@ -54,7 +54,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL)" '
 	remote: proc-receive> ok refs/for/master/topic
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/pull/123/head
 	EOF
@@ -87,7 +87,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: proc-receive> option forced-update
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/pull/123/head
 	EOF
@@ -121,7 +121,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL)
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: proc-receive> option old-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	 <OID-B>..<OID-A> HEAD -> refs/pull/123/head
 	EOF
@@ -153,7 +153,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL)" '
 	remote: proc-receive> ok refs/for/master/topic
 	remote: proc-receive> option old-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
 	 <OID-B>..<OID-A> HEAD -> refs/for/master/topic
 	EOF
@@ -187,7 +187,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL)
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
 	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
 	EOF
@@ -237,9 +237,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL)" '
 	remote: proc-receive> option forced-update
 	remote: proc-receive> option new-oid <COMMIT-A>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/pull/123/head
 	 * [new reference] HEAD -> refs/for/a/b/c/topic
t/t5411/test-0033-report-with-options--porcelain.sh +7 -7
index f18ba9f06f..1fe352b686 100644
@@ -55,7 +55,7 @@ test_expect_success "proc-receive: report option refname ($PROTOCOL/porcelain)"
 	remote: proc-receive> ok refs/for/master/topic
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	*    HEAD:refs/pull/123/head    [new reference]
 	Done
@@ -90,7 +90,7 @@ test_expect_success "proc-receive: report option refname and forced-update ($PRO
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: proc-receive> option forced-update
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	*    HEAD:refs/pull/123/head    [new reference]
 	Done
@@ -125,7 +125,7 @@ test_expect_success "proc-receive: report option refname and old-oid ($PROTOCOL/
 	remote: proc-receive> option refname refs/pull/123/head
 	remote: proc-receive> option old-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/123/head
 	To <URL/of/upstream.git>
 	     HEAD:refs/pull/123/head    <OID-B>..<OID-A>
 	Done
@@ -158,7 +158,7 @@ test_expect_success "proc-receive: report option old-oid ($PROTOCOL/porcelain)"
 	remote: proc-receive> ok refs/for/master/topic
 	remote: proc-receive> option old-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/for/master/topic
 	To <URL/of/upstream.git>
 	     HEAD:refs/for/master/topic    <OID-B>..<OID-A>
 	Done
@@ -193,7 +193,7 @@ test_expect_success "proc-receive: report option old-oid and new-oid ($PROTOCOL/
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
 	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
 	Done
@@ -245,9 +245,9 @@ test_expect_success "proc-receive: report with multiple rewrites ($PROTOCOL/porc
 	remote: proc-receive> option forced-update
 	remote: proc-receive> option new-oid <COMMIT-A>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/pull/123/head
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/a/b/c/topic
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/pull/124/head
 	To <URL/of/upstream.git>
 	*    HEAD:refs/pull/123/head    [new reference]
 	*    HEAD:refs/for/a/b/c/topic    [new reference]
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +8 -3
index 64662afdc6..27d58edd14 100644
@@ -41,7 +41,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
 	To <URL/of/upstream.git>
 	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
 	 * [new reference] HEAD -> refs/changes/24/124/1
@@ -101,7 +103,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	remote: proc-receive> option new-oid <COMMIT-A>
 	remote: proc-receive> option forced-update
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/changes/24/124/1
 	 <OID-A>..<OID-B> HEAD -> refs/for/master/topic
@@ -149,7 +153,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
 	To <URL/of/upstream.git>
 	 * [new reference] HEAD -> refs/changes/23/123/1
 	 <OID-A>..<OID-B> HEAD -> refs/changes/24/124/2
t/t5411/test-0037-report-multi-rewrite-for-one-ref--porcelain.sh +8 -3
index a7e29af0c2..77b5b22ed4 100644
@@ -41,7 +41,9 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/25/125/1
 	To <URL/of/upstream.git>
 	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
 	*    HEAD:refs/changes/24/124/1    [new reference]
@@ -102,7 +104,9 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	remote: proc-receive> option new-oid <COMMIT-A>
 	remote: proc-receive> option forced-update
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/24/124/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
+	remote: post-receive< <COMMIT-B> <COMMIT-A> refs/changes/25/125/1
 	To <URL/of/upstream.git>
 	*    HEAD:refs/changes/24/124/1    [new reference]
 	     HEAD:refs/for/master/topic    <OID-A>..<OID-B>
@@ -151,7 +155,8 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL/porc
 	remote: proc-receive> option old-oid <COMMIT-A>
 	remote: proc-receive> option new-oid <COMMIT-B>
 	remote: # post-receive hook
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/changes/23/123/1
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/changes/24/124/2
 	To <URL/of/upstream.git>
 	*    HEAD:refs/changes/23/123/1    [new reference]
 	     HEAD:refs/changes/24/124/2    <OID-A>..<OID-B>
t/t5411/test-0038-report-mixed-refs.sh +1 -1
index 54bec4c026..a74a2cb449 100644
@@ -53,7 +53,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL)" '
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
 	 <OID-A>..<OID-B> <COMMIT-B> -> master
 	 * [new branch] HEAD -> bar
t/t5411/test-0039-report-mixed-refs--porcelain.sh +1 -1
index 605b3cb5c9..e4baa13ea3 100644
@@ -53,7 +53,7 @@ test_expect_success "proc-receive: report update of mixed refs ($PROTOCOL/porcel
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/baz
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/next/topic2
 	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/heads/foo
-	remote: post-receive< <ZERO-OID> <COMMIT-A> refs/for/master/topic
+	remote: post-receive< <COMMIT-A> <COMMIT-B> refs/for/master/topic
 	To <URL/of/upstream.git>
 	     <COMMIT-B>:refs/heads/master    <OID-A>..<OID-B>
 	*    HEAD:refs/heads/bar    [new branch]
Signature · 1 line
2.26.1.120.g98702cf3e9
author
#212 lore raw

PATCH v16 7/11 refs.c: refactor to reuse ref_is_hidden()

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

Add new function ref_is_matched() to reuse ref_is_hidden(). Will use this function for receive-pack to check commands with specific prefixes.

Test case t5512 covered this change.

---
 refs.c | 13 +++++++++----
 refs.h |  1 +
 2 files changed, 10 insertions(+), 4 deletions(-)
refs.c +9 -4
index 224ff66c7b..76a91ac0f6 100644
@@ -1344,14 +1344,14 @@ int parse_hide_refs_config(const char *var, const char *value, const char *secti
 	return 0;
 }
 
-int ref_is_hidden(const char *refname, const char *refname_full)
+int ref_matches(struct string_list *match_refs, const char *refname, const char *refname_full)
 {
 	int i;
 
-	if (!hide_refs)
+	if (!match_refs)
 		return 0;
-	for (i = hide_refs->nr - 1; i >= 0; i--) {
-		const char *match = hide_refs->items[i].string;
+	for (i = match_refs->nr - 1; i >= 0; i--) {
+		const char *match = match_refs->items[i].string;
 		const char *subject;
 		int neg = 0;
 		const char *p;
@@ -1377,6 +1377,11 @@ int ref_is_hidden(const char *refname, const char *refname_full)
 	return 0;
 }
 
+int ref_is_hidden(const char *refname, const char *refname_full)
+{
+	return ref_matches(hide_refs, refname, refname_full);
+}
+
 const char *find_descendant_ref(const char *dirname,
 				const struct string_list *extras,
 				const struct string_list *skip)
refs.h +1 -0
index a92d2c74c8..9907dd12b0 100644
@@ -727,6 +727,7 @@ int parse_hide_refs_config(const char *var, const char *value, const char *);
  * parameter always points to the full ref name.
  */
 int ref_is_hidden(const char *, const char *);
+int ref_matches(struct string_list *, const char *, const char *);
 
 enum ref_type {
 	REF_TYPE_PER_WORKTREE,	  /* refs inside refs/ but not shared       */
Signature · 1 line
2.26.1.120.g98702cf3e9
author
#213 lore raw

PATCH v16 8/11 receive-pack: new config receive.procReceiveRefs

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

Add a new multi-valued config variable "receive.procReceiveRefs" for receive-pack command, like the follows:

    git config --system --add receive.procReceiveRefs refs/for
    git config --system --add receive.procReceiveRefs refs/drafts

If the specific prefix strings match the reference names of the commands which are sent from git client to receive-pack, these commands will be executed by an external hook (named "proc-receive"), instead of the internal execute_commands function.

For example, if it is set to "refs/for", pushing to a reference such as "refs/for/master" will not create or update reference "refs/for/master", but may create or update a pull request directly by running the hook "proc-receive".

---
 Documentation/config/receive.txt              |  14 +++
 builtin/receive-pack.c                        |  43 +++++--
 t/t5411/once-0010-report-status-v1.sh         |   4 +
 t/t5411/test-0010-proc-receive-settings.sh    |   7 ++
 t/t5411/test-0040-process-all-refs.sh         | 113 +++++++++++++++++
 .../test-0041-process-all-refs--porcelain.sh  | 114 ++++++++++++++++++
 6 files changed, 288 insertions(+), 7 deletions(-)
 create mode 100644 t/t5411/test-0010-proc-receive-settings.sh
 create mode 100644 t/t5411/test-0040-process-all-refs.sh
 create mode 100644 t/t5411/test-0041-process-all-refs--porcelain.sh
Documentation/config/receive.txt +14 -0
index 65f78aac37..e7b967feeb 100644
@@ -114,6 +114,20 @@ receive.hideRefs::
 	An attempt to update or delete a hidden ref by `git push` is
 	rejected.
 
+receive.procReceiveRefs::
+	This is a multi-valued variable that defines reference prefixes
+	to match the commands in `receive-pack`.  Commands matching the
+	prefixes will be executed by an external hook "proc-receive",
+	instead of the internal `execute_commands` function.  If this
+	variable is not defined, the "proc-receive" hook will never be
+	used, and all commands will be executed by the internal
+	`execute_commands` function.
+
+	For example, if this variable is set to "refs/for", pushing to
+	reference such as "refs/for/master" will not create or update a
+	reference named "refs/for/master", but may create or update a
+	pull request directly by running the hook "proc-receive".
+
 receive.updateServerInfo::
 	If set to true, git-receive-pack will run git-update-server-info
 	after receiving data from git-push and updating refs.
builtin/receive-pack.c +36 -7

74 lines not on this page · raw message

t/t5411/once-0010-report-status-v1.sh +4 -0
index 4385628d06..cdafc8971f 100644
@@ -1,3 +1,7 @@
+test_expect_success "setup receive.procReceiveRefs" '
+	git -C "$upstream" config --add receive.procReceiveRefs refs/for
+'
+
 test_expect_success "setup proc-receive hook" '
 	write_script "$upstream/hooks/proc-receive" <<-EOF
 	printf >&2 "# proc-receive hook\n"
t/t5411/test-0010-proc-receive-settings.sh new file +7 -0
new file mode 100644
index 0000000000..a36809927b
@@ -0,0 +1,7 @@
+test_expect_success "add two receive.procReceiveRefs settings" '
+	(
+		cd "$upstream" &&
+		git config --add receive.procReceiveRefs refs/for &&
+		git config --add receive.procReceiveRefs refs/review/
+	)
+'
t/t5411/test-0040-process-all-refs.sh new file +113 -0

113 lines not on this page · raw message

t/t5411/test-0041-process-all-refs--porcelain.sh new file +114 -0

114 lines not on this page · raw message

Signature · 1 line
2.26.1.120.g98702cf3e9
author
#214 lore raw

PATCH v16 9/11 t5411: test updates of remote-tracking branches

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

In order to test update of remote-tracking branches for special refs, add new "remote.origin.fetch" settings and test cases.

---
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 48 +++++++++++++++++++
 1 file changed, 48 insertions(+)
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +48 -0
index 27d58edd14..8eec3a1ed8 100644
@@ -1,3 +1,18 @@
+test_expect_success "setup git config for remote-tracking of special refs" '
+	(
+		cd workbench &&
+		if ! git config --get-all remote.origin.fetch | grep refs/for/
+		then
+			git config --add remote.origin.fetch \
+				"+refs/for/*:refs/t/for/*" &&
+			git config --add remote.origin.fetch \
+				"+refs/pull/*:refs/t/pull/*" &&
+			git config --add remote.origin.fetch \
+				"+refs/changes/*:refs/t/changes/*"
+		fi
+	)
+'
+
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 1st rewrite, $PROTOCOL)" '
 	write_script "$upstream/hooks/proc-receive" <<-EOF
 	printf >&2 "# proc-receive hook\n"
@@ -58,6 +73,17 @@ test_expect_success "proc-receive: multiple rewrite for one ref, no refname for
 	test_cmp expect actual
 '
 
+test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" '
+	git -C workbench show-ref |
+		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/t/for/master/topic
+	EOF
+	test_cmp expect actual &&
+	git -C workbench update-ref -d refs/t/for/master/topic
+'
+
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" '
 	write_script "$upstream/hooks/proc-receive" <<-EOF
 	printf >&2 "# proc-receive hook\n"
@@ -120,6 +146,17 @@ test_expect_success "proc-receive: multiple rewrites for one ref, no refname for
 	test_cmp expect actual
 '
 
+test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" '
+	git -C workbench show-ref |
+		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/t/for/master/topic
+	EOF
+	test_cmp expect actual &&
+	git -C workbench update-ref -d refs/t/for/master/topic
+'
+
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" '
 	write_script "$upstream/hooks/proc-receive" <<-EOF
 	printf >&2 "# proc-receive hook\n"
@@ -167,3 +204,14 @@ test_expect_success "proc-receive: multiple rewrites for one ref ($PROTOCOL)" '
 	EOF
 	test_cmp expect actual
 '
+
+test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" '
+	git -C workbench show-ref |
+		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
+	make_user_friendly_and_stable_output <out >actual &&
+	cat >expect <<-EOF &&
+	<COMMIT-A> refs/t/for/master/topic
+	EOF
+	test_cmp expect actual &&
+	git -C workbench update-ref -d refs/t/for/master/topic
+'
Signature · 1 line
2.26.1.120.g98702cf3e9
author
#215 lore raw

PATCH v16 10/11 transport: parse report options for tracking refs

In reply to Jiang Xin

From: Jiang Xin <[email protected]>

When pushing a pseudo reference (such as "refs/for/master/topic"), may create or update one or more references. The real names of the references will be stored in the report options. Parse report options to create or update remote-tracking branches properly.

---
 ...t-0036-report-multi-rewrite-for-one-ref.sh | 22 +++++++---
 transport.c                                   | 40 ++++++++++++++-----
 2 files changed, 46 insertions(+), 16 deletions(-)
t/t5411/test-0036-report-multi-rewrite-for-one-ref.sh +16 -6
index 8eec3a1ed8..73283d81e8 100644
@@ -78,10 +78,14 @@ test_expect_success "proc-receive: check remote-tracking #1 ($PROTOCOL)" '
 		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
 	make_user_friendly_and_stable_output <out >actual &&
 	cat >expect <<-EOF &&
-	<COMMIT-A> refs/t/for/master/topic
+	<COMMIT-A> refs/t/changes/24/124/1
+	<COMMIT-B> refs/t/changes/25/125/1
+	<COMMIT-B> refs/t/for/master/topic
 	EOF
 	test_cmp expect actual &&
-	git -C workbench update-ref -d refs/t/for/master/topic
+	git -C workbench update-ref -d refs/t/for/master/topic &&
+	git -C workbench update-ref -d refs/t/changes/24/124/1 &&
+	git -C workbench update-ref -d refs/t/changes/25/125/1
 '
 
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, no refname for the 2nd rewrite, $PROTOCOL)" '
@@ -151,10 +155,14 @@ test_expect_success "proc-receive: check remote-tracking #2 ($PROTOCOL)" '
 		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
 	make_user_friendly_and_stable_output <out >actual &&
 	cat >expect <<-EOF &&
-	<COMMIT-A> refs/t/for/master/topic
+	<COMMIT-A> refs/t/changes/24/124/1
+	<COMMIT-A> refs/t/changes/25/125/1
+	<COMMIT-B> refs/t/for/master/topic
 	EOF
 	test_cmp expect actual &&
-	git -C workbench update-ref -d refs/t/for/master/topic
+	git -C workbench update-ref -d refs/t/for/master/topic &&
+	git -C workbench update-ref -d refs/t/changes/24/124/1 &&
+	git -C workbench update-ref -d refs/t/changes/25/125/1
 '
 
 test_expect_success "setup proc-receive hook (multiple rewrites for one ref, $PROTOCOL)" '
@@ -210,8 +218,10 @@ test_expect_success "proc-receive: check remote-tracking #3 ($PROTOCOL)" '
 		grep -v -e refs/remotes -e refs/heads -e refs/tags >out &&
 	make_user_friendly_and_stable_output <out >actual &&
 	cat >expect <<-EOF &&
-	<COMMIT-A> refs/t/for/master/topic
+	<COMMIT-A> refs/t/changes/23/123/1
+	<COMMIT-B> refs/t/changes/24/124/2
 	EOF
 	test_cmp expect actual &&
-	git -C workbench update-ref -d refs/t/for/master/topic
+	git -C workbench update-ref -d refs/t/changes/24/124/1 &&
+	git -C workbench update-ref -d refs/t/changes/25/125/2
 '
transport.c +30 -10
index 5baa30dd74..cd01f82f5c 100644
@@ -437,28 +437,48 @@ int transport_refs_pushed(struct ref *ref)
 	return 0;
 }
 
-void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose)
+static void update_tracking_ref(struct remote *remote, char *refname,
+				struct object_id *new_oid, int deletion,
+				int verbose)
 {
 	struct refspec_item rs;
 
-	if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
-		return;
-
-	rs.src = ref->name;
+	rs.src = refname;
 	rs.dst = NULL;
-
 	if (!remote_find_tracking(remote, &rs)) {
 		if (verbose)
 			fprintf(stderr, "updating local tracking ref '%s'\n", rs.dst);
-		if (ref->deletion) {
+		if (deletion)
 			delete_ref(NULL, rs.dst, NULL, 0);
-		} else
-			update_ref("update by push", rs.dst, &ref->new_oid,
-				   NULL, 0, 0);
+		else
+			update_ref("update by push", rs.dst, new_oid,
+				NULL, 0, 0);
 		free(rs.dst);
 	}
 }
 
+void transport_update_tracking_ref(struct remote *remote, struct ref *ref, int verbose)
+{
+	char *refname;
+	struct object_id *new_oid;
+	struct ref_push_report_options *options;
+
+	if (ref->status != REF_STATUS_OK && ref->status != REF_STATUS_UPTODATE)
+		return;
+
+	options = ref->report.options;
+	if (!options)
+		update_tracking_ref(remote, ref->name, &ref->new_oid,
+				    ref->deletion, verbose);
+	else
+		for (; options; options = options->next) {
+			refname = options->ref_name ? (char *)options->ref_name : ref->name;
+			new_oid = options->new_oid ? options->new_oid : &ref->new_oid;
+			update_tracking_ref(remote, refname, new_oid,
+					    is_null_oid(new_oid), verbose);
+		}
+}
+
 static void print_ref_status(char flag, const char *summary,
 			     struct ref *to, struct ref *from, const char *msg,
 			     struct ref_push_report_options *options,
Signature · 1 line
2.26.1.120.g98702cf3e9