git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/4] test: refactor to use "test_commit" to create commits

From
Jiang Xin <worldhello.net@gmail.com>
Date
Jun 17, 2021, 03:17 UTC
Message-ID
<20210617031727.81105-3-zhiyou.jx@alibaba-inc.com>
In-Reply-To
<20210617031727.81105-1-zhiyou.jx@alibaba-inc.com>

Refactor function "create_commits_in" to use "test_commit" to create commit.

Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
---
 t/t5411/common-functions.sh | 25 ++++++-------------------
 t/t5548-push-porcelain.sh   | 25 ++++++-------------------
 2 files changed, 12 insertions(+), 38 deletions(-)
diff --git a/t/t5411/common-functions.sh b/t/t5411/common-functions.sh
index 6c347b4caa..b9c6adecf5 100644
--- a/t/t5411/common-functions.sh
+++ b/t/t5411/common-functions.sh
@@ -6,29 +6,16 @@
 # NOTE: Never calling this function from a subshell since variable
 # assignments will disappear when subshell exits.
 create_commits_in () {
-	repo="$1" &&
-	if ! parent=$(git -C "$repo" rev-parse HEAD^{} --)
-	then
-		parent=
-	fi &&
-	T=$(git -C "$repo" write-tree) &&
+	repo="$1" && test -d "$repo" ||
+	error "Repository $repo does not exist."
 	shift &&
 	while test $# -gt 0
 	do
 		name=$1 &&
-		test_tick &&
-		if test -z "$parent"
-		then
-			oid=$(echo $name | git -C "$repo" commit-tree $T)
-		else
-			oid=$(echo $name | git -C "$repo" commit-tree -p $parent $T)
-		fi &&
-		eval $name=$oid &&
-		parent=$oid &&
-		shift ||
-		return 1
-	done &&
-	git -C "$repo" update-ref refs/heads/main $oid
+		shift &&
+		test_commit -C "$repo" --no-tag "$name" &&
+		eval $name=$(git -C "$repo" rev-parse HEAD)
+	done
 }
 
 # Format the output of git-push, git-show-ref and other commands to make a
diff --git a/t/t5548-push-porcelain.sh b/t/t5548-push-porcelain.sh
index 2ab7c3cf5a..c8f18a7a12 100755
--- a/t/t5548-push-porcelain.sh
+++ b/t/t5548-push-porcelain.sh
@@ -14,29 +14,16 @@ test_description='Test git push porcelain output'
 # NOTE: Never calling this function from a subshell since variable
 # assignments will disappear when subshell exits.
 create_commits_in () {
-	repo="$1" &&
-	if ! parent=$(git -C "$repo" rev-parse HEAD^{} --)
-	then
-		parent=
-	fi &&
-	T=$(git -C "$repo" write-tree) &&
+	repo="$1" && test -d "$repo" ||
+	error "Repository $repo does not exist."
 	shift &&
 	while test $# -gt 0
 	do
 		name=$1 &&
-		test_tick &&
-		if test -z "$parent"
-		then
-			oid=$(echo $name | git -C "$repo" commit-tree $T)
-		else
-			oid=$(echo $name | git -C "$repo" commit-tree -p $parent $T)
-		fi &&
-		eval $name=$oid &&
-		parent=$oid &&
-		shift ||
-		return 1
-	done &&
-	git -C "$repo" update-ref refs/heads/main $oid
+		shift &&
+		test_commit -C "$repo" --no-tag "$name" &&
+		eval $name=$(git -C "$repo" rev-parse HEAD)
+	done
 }
 
 # Format the output of git-push, git-show-ref and other commands to make a
-- 
2.32.0.rc0.27.g7b1e85181b
Previous: Jiang XinNext: Jiang Xin
Message 3 of 4 in “sideband: don't lose clear-to-eol at packet boundary”
  1. 1/4 sideband: don't lose clear-to-eol at packet boundaryJiang Xin, Jun 17, 2021
  2. 2/4 test: compare raw output, not mangle tabs and spacesJiang Xin, Jun 17, 2021
  3. 3/4 test: refactor to use "test_commit" to create commitsJiang Xin, Jun 17, 2021
  4. 4/4 test: refactor to use "get_abbrev_oid" to get abbrev oidJiang Xin, Jun 17, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.