test: refactor to use "test_commit" to create commits
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>
Jiang Xin committed
Jun 17, 2021 at 11:17 UTC
3c06a583398f6630c7162b463ff1acbdf0110f83
2 files changed
+12
-38
t/t5411/common-functions.sh
+6
-19
@@ -6,29 +6,16 @@
6
# NOTE: Never calling this function from a subshell since variable
7
# assignments will disappear when subshell exits.
8
create_commits_in () {
9
- repo="$1" &&
10
- if ! parent=$(git -C "$repo" rev-parse HEAD^{} --)
11
- then
12
- parent=
13
- fi &&
14
- T=$(git -C "$repo" write-tree) &&
9
+ repo="$1" && test -d "$repo" ||
10
+ error "Repository $repo does not exist."
11
shift &&
12
while test $# -gt 0
13
do
14
name=$1 &&
19
- test_tick &&
20
- if test -z "$parent"
21
- then
22
- oid=$(echo $name | git -C "$repo" commit-tree $T)
23
- else
24
- oid=$(echo $name | git -C "$repo" commit-tree -p $parent $T)
25
- fi &&
26
- eval $name=$oid &&
27
- parent=$oid &&
28
- shift ||
29
- return 1
30
- done &&
31
- git -C "$repo" update-ref refs/heads/main $oid
15
+ shift &&
16
+ test_commit -C "$repo" --no-tag "$name" &&
17
+ eval $name=$(git -C "$repo" rev-parse HEAD)
18
+ done
19
}
20
21
# Format the output of git-push, git-show-ref and other commands to make a
t/t5548-push-porcelain.sh
+6
-19
@@ -14,29 +14,16 @@ test_description='Test git push porcelain output'
14
# NOTE: Never calling this function from a subshell since variable
15
# assignments will disappear when subshell exits.
16
create_commits_in () {
17
- repo="$1" &&
18
- if ! parent=$(git -C "$repo" rev-parse HEAD^{} --)
19
- then
20
- parent=
21
- fi &&
22
- T=$(git -C "$repo" write-tree) &&
17
+ repo="$1" && test -d "$repo" ||
18
+ error "Repository $repo does not exist."
19
shift &&
20
while test $# -gt 0
21
do
22
name=$1 &&
27
- test_tick &&
28
- if test -z "$parent"
29
- then
30
- oid=$(echo $name | git -C "$repo" commit-tree $T)
31
- else
32
- oid=$(echo $name | git -C "$repo" commit-tree -p $parent $T)
33
- fi &&
34
- eval $name=$oid &&
35
- parent=$oid &&
36
- shift ||
37
- return 1
38
- done &&
39
- git -C "$repo" update-ref refs/heads/main $oid
23
+ shift &&
24
+ test_commit -C "$repo" --no-tag "$name" &&
25
+ eval $name=$(git -C "$repo" rev-parse HEAD)
26
+ done
27
}
28
29
# Format the output of git-push, git-show-ref and other commands to make a