]> git.ipfire.org Git - thirdparty/git.git/commitdiff
test: refactor to use "test_commit" to create commits
authorJiang Xin <worldhello.net@gmail.com>
Thu, 17 Jun 2021 03:17:26 +0000 (11:17 +0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 17 Jun 2021 05:12:22 +0000 (14:12 +0900)
Refactor function "create_commits_in" to use "test_commit" to create
commit.

Signed-off-by: Jiang Xin <zhiyou.jx@alibaba-inc.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t5411/common-functions.sh
t/t5548-push-porcelain.sh

index 6c347b4caa94db298f7beb3d19e7ec584fb5b0ab..b9c6adecf50fa4e03fac1009546097cffb76c936 100644 (file)
@@ -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
index 2ab7c3cf5a0462d4eb9b42956700b5a0a8bae385..c8f18a7a1219040b352ca9530f682e2d3a768216 100755 (executable)
@@ -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