git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Patrick Steinhardt <ps@pks.im>
To: git@vger.kernel.org
Cc: Jiang Xin <zhiyou.jx@alibaba-inc.com>,
	 Junio C Hamano <gitster@pobox.com>,
	Eric Sunshine <sunshine@sunshineco.com>
Subject: [PATCH v5 2/8] t5548: refactor to reuse setup_upstream() function
Date: Mon, 03 Feb 2025 07:29:32 +0100	[thread overview]
Message-ID: <20250203-pks-push-atomic-respect-exit-code-v5-2-d66481e36622@pks.im> (raw)
In-Reply-To: <20250203-pks-push-atomic-respect-exit-code-v5-0-d66481e36622@pks.im>

From: Jiang Xin <zhiyou.jx@alibaba-inc.com>

Refactor the function setup_upstream_and_workbench(), extracting
create_upstream_template() and setup_upstream() from it. The former is
used to create the upstream repository template, while the latter is
used to rebuild the upstream repository and will be reused in subsequent
commits.

To ensure that setup_upstream() works properly in both local and HTTP
protocols, the HTTP settings have been moved to the setup_upstream() and
setup_upstream_and_workbench() functions.

Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
 t/t5548-push-porcelain.sh | 83 ++++++++++++++++++++++++++++++-----------------
 1 file changed, 53 insertions(+), 30 deletions(-)

diff --git a/t/t5548-push-porcelain.sh b/t/t5548-push-porcelain.sh
index 6282728eaf..1bf4d48cd9 100755
--- a/t/t5548-push-porcelain.sh
+++ b/t/t5548-push-porcelain.sh
@@ -54,29 +54,65 @@ format_and_save_expect () {
 	sed -e 's/^> //' -e 's/Z$//' >expect
 }
 
+create_upstream_template () {
+	git init --bare upstream-template.git &&
+	git clone upstream-template.git tmp_work_dir &&
+	create_commits_in tmp_work_dir A B &&
+	(
+		cd tmp_work_dir &&
+		git push origin \
+			$B:refs/heads/main \
+			$A:refs/heads/foo \
+			$A:refs/heads/bar \
+			$A:refs/heads/baz
+	) &&
+	rm -rf tmp_work_dir
+}
+
+setup_upstream () {
+	if test $# -ne 1
+	then
+		BUG "location of upstream repository is not provided"
+	fi &&
+	rm -rf "$1" &&
+	if ! test -d upstream-template.git
+	then
+		create_upstream_template
+	fi &&
+	git clone --mirror upstream-template.git "$1" &&
+	# The upstream repository provides services using the HTTP protocol.
+	if ! test "$1" = "upstream.git"
+	then
+		git -C "$1" config http.receivepack true
+	fi
+}
+
 setup_upstream_and_workbench () {
+	if test $# -ne 1
+	then
+		BUG "location of upstream repository is not provided"
+	fi
+	upstream="$1"
+
 	# Upstream  after setup : main(B)  foo(A)  bar(A)  baz(A)
 	# Workbench after setup : main(A)
 	test_expect_success "setup upstream repository and workbench" '
-		rm -rf upstream.git workbench &&
-		git init --bare upstream.git &&
-		git init workbench &&
-		create_commits_in workbench A B &&
+		setup_upstream "$upstream" &&
+		rm -rf workbench &&
+		git clone "$upstream" workbench &&
 		(
 			cd workbench &&
+			git update-ref refs/heads/main $A &&
 			# 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 remote add origin ../upstream.git &&
-			git update-ref refs/heads/main $A &&
-			git push origin \
-				$B:refs/heads/main \
-				$A:refs/heads/foo \
-				$A:refs/heads/bar \
-				$A:refs/heads/baz
+			git config advice.pushUpdateRejected false
 		) &&
-		git -C "workbench" config advice.pushUpdateRejected false &&
-		upstream=upstream.git
+		# The upstream repository provides services using the HTTP protocol.
+		if ! test "$upstream" = "upstream.git"
+		then
+			git -C workbench remote set-url origin "$HTTPD_URL/smart/upstream.git"
+		fi
 	'
 }
 
@@ -88,7 +124,7 @@ run_git_push_porcelain_output_test() {
 		;;
 	file)
 		PROTOCOL="builtin protocol"
-		URL_PREFIX="\.\."
+		URL_PREFIX=".*"
 		;;
 	esac
 
@@ -247,10 +283,8 @@ run_git_push_porcelain_output_test() {
 	'
 }
 
-# Initialize the upstream repository and local workbench.
-setup_upstream_and_workbench
+setup_upstream_and_workbench upstream.git
 
-# Run git-push porcelain test on builtin protocol
 run_git_push_porcelain_output_test file
 
 ROOT_PATH="$PWD"
@@ -258,21 +292,10 @@ ROOT_PATH="$PWD"
 . "$TEST_DIRECTORY"/lib-httpd.sh
 . "$TEST_DIRECTORY"/lib-terminal.sh
 start_httpd
-
-# Re-initialize the upstream repository and local workbench.
-setup_upstream_and_workbench
-
-test_expect_success "setup for http" '
-	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/smart/upstream.git
-'
-
 setup_askpass_helper
 
-# Run git-push porcelain test on HTTP protocol
+setup_upstream_and_workbench "$HTTPD_DOCUMENT_ROOT_PATH/upstream.git"
+
 run_git_push_porcelain_output_test http
 
 test_done

-- 
2.48.1.502.g6dc24dfdaf.dirty


  parent reply	other threads:[~2025-02-03  6:29 UTC|newest]

Thread overview: 54+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-13 11:24 [PATCH 0/2] transport: don't ignore git-receive-pack(1) exit code on atomic push Patrick Steinhardt
2024-11-13 11:24 ` [PATCH 1/2] t5504: modernize test by moving heredocs into test bodies Patrick Steinhardt
2024-11-13 11:24 ` [PATCH 2/2] transport: don't ignore git-receive-pack(1) exit code on atomic push Patrick Steinhardt
2024-11-14  8:57   ` Jiang Xin
2024-11-14 17:15     ` [PATCH v2 0/6] fix behaviors of git-push --porcelain Jiang Xin
2024-11-14 17:15       ` [PATCH v2 1/6] t5548: new test cases for push --porcelain and --dry-run Jiang Xin
2024-11-25  8:26         ` Patrick Steinhardt
2024-12-03 11:52           ` Jiang Xin
2024-11-14 17:15       ` [PATCH v2 2/6] push: fix the behavior of the Done message for porcelain Jiang Xin
2024-11-25  8:26         ` Patrick Steinhardt
2024-11-14 17:15       ` [PATCH v2 3/6] t5504: modernize test by moving heredocs into test bodies Jiang Xin
2024-11-14 17:15       ` [PATCH v2 4/6] t5543: atomic push reports exit code failure Jiang Xin
2024-11-14 17:15       ` [PATCH v2 5/6] push: only ignore finish_connect() for dry-run mode Jiang Xin
2024-11-25  8:26         ` Patrick Steinhardt
2024-11-14 17:15       ` [PATCH v2 6/6] push: not send push-options to server with --dry-run Jiang Xin
2024-11-25  8:26         ` Patrick Steinhardt
2024-12-10 11:36       ` [PATCH v3 0/8] fix behaviors of git-push --porcelain Jiang Xin
2024-12-10 11:36         ` [PATCH v3 1/8] t5504: modernize test by moving heredocs into test bodies Jiang Xin
2024-12-10 11:36         ` [PATCH v3 2/8] t5548: refactor to reuse setup_upstream() function Jiang Xin
2024-12-10 11:36         ` [PATCH v3 3/8] t5548: refactor test cases by resetting upstream Jiang Xin
2024-12-10 11:36         ` [PATCH v3 4/8] t5548: add new porcelain test cases Jiang Xin
2024-12-10 11:36         ` [PATCH v3 5/8] t5548: add porcelain push test cases for dry-run mode Jiang Xin
2024-12-10 12:19           ` Jiang Xin
2024-12-10 11:36         ` [PATCH v3 6/8] send-pack: new return code "ERROR_SEND_PACK_BAD_REF_STATUS" Jiang Xin
2024-12-16  8:36           ` Patrick Steinhardt
2024-12-10 11:36         ` [PATCH v3 7/8] t5543: atomic push reports exit code failure Jiang Xin
2024-12-10 11:36         ` [PATCH v3 8/8] send-pack: gracefully close the connection for atomic push Jiang Xin
2024-12-16  8:36           ` Patrick Steinhardt
2024-11-14 23:36     ` [PATCH 2/2] transport: don't ignore git-receive-pack(1) exit code on " Junio C Hamano
2024-11-25  8:26       ` Patrick Steinhardt
2025-01-31 10:53 ` [PATCH v4 0/8] " Patrick Steinhardt
2025-01-31 10:53   ` [PATCH v4 1/8] t5504: modernize test by moving heredocs into test bodies Patrick Steinhardt
2025-01-31 14:28     ` Eric Sunshine
2025-01-31 16:26       ` Junio C Hamano
2025-02-03  6:04       ` Patrick Steinhardt
2025-01-31 10:53   ` [PATCH v4 2/8] t5548: refactor to reuse setup_upstream() function Patrick Steinhardt
2025-01-31 14:35     ` Eric Sunshine
2025-01-31 10:53   ` [PATCH v4 3/8] t5548: refactor test cases by resetting upstream Patrick Steinhardt
2025-01-31 10:53   ` [PATCH v4 4/8] t5548: add new porcelain test cases Patrick Steinhardt
2025-01-31 14:46     ` Eric Sunshine
2025-01-31 10:53   ` [PATCH v4 5/8] t5548: add porcelain push test cases for dry-run mode Patrick Steinhardt
2025-01-31 10:53   ` [PATCH v4 6/8] send-pack: new return code "ERROR_SEND_PACK_BAD_REF_STATUS" Patrick Steinhardt
2025-01-31 10:53   ` [PATCH v4 7/8] t5543: atomic push reports exit code failure Patrick Steinhardt
2025-01-31 10:53   ` [PATCH v4 8/8] send-pack: gracefully close the connection for atomic push Patrick Steinhardt
2025-02-03  6:29 ` [PATCH v5 0/8] transport: don't ignore git-receive-pack(1) exit code on " Patrick Steinhardt
2025-02-03  6:29   ` [PATCH v5 1/8] t5504: modernize test by moving heredocs into test bodies Patrick Steinhardt
2025-02-03  6:29   ` Patrick Steinhardt [this message]
2025-02-03  6:29   ` [PATCH v5 3/8] t5548: refactor test cases by resetting upstream Patrick Steinhardt
2025-02-03  6:29   ` [PATCH v5 4/8] t5548: add new porcelain test cases Patrick Steinhardt
2025-02-03  6:29   ` [PATCH v5 5/8] t5548: add porcelain push test cases for dry-run mode Patrick Steinhardt
2025-02-03  6:29   ` [PATCH v5 6/8] send-pack: new return code "ERROR_SEND_PACK_BAD_REF_STATUS" Patrick Steinhardt
2025-02-03  6:29   ` [PATCH v5 7/8] t5543: atomic push reports exit code failure Patrick Steinhardt
2025-02-03  6:29   ` [PATCH v5 8/8] send-pack: gracefully close the connection for atomic push Patrick Steinhardt
2025-02-03 23:26   ` [PATCH v5 0/8] transport: don't ignore git-receive-pack(1) exit code on " Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250203-pks-push-atomic-respect-exit-code-v5-2-d66481e36622@pks.im \
    --to=ps@pks.im \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=sunshine@sunshineco.com \
    --cc=zhiyou.jx@alibaba-inc.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).