Skip to content

Commit bbc95d1

Browse files
committed
t: add tests for refs list subcommand
Test the implemented functionality of `git refs list` and verify backward compatibility with `git show-ref` for the supported flags and patterns. Mentored-by: Patrick Steinhardt <ps@pks.im> Mentored-by: shejialuo <shejialuo@gmail.com> Mentored-by: Karthik Nayak <karthik.188@gmail.com> Signed-off-by: Meet Soni <meetsoni3017@gmail.com>
1 parent dca8186 commit bbc95d1

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

t/meson.build

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ integration_tests = [
224224
't1450-fsck.sh',
225225
't1451-fsck-buffer.sh',
226226
't1460-refs-migrate.sh',
227+
't1461-refs-list.sh',
227228
't1500-rev-parse.sh',
228229
't1501-work-tree.sh',
229230
't1502-rev-parse-parseopt.sh',

t/t1461-refs-list.sh

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
#!/bin/sh
2+
3+
test_description='Verify git refs list functionality and compatibility with git show-ref'
4+
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
5+
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
6+
7+
. ./test-lib.sh
8+
9+
test_expect_success setup '
10+
test_commit --annotate A &&
11+
git checkout -b side &&
12+
test_commit --annotate B &&
13+
git checkout main &&
14+
test_commit C &&
15+
git branch B A^0
16+
'
17+
18+
test_expect_success 'refs list --branches, --tags, --head, pattern' '
19+
for branch in B main side
20+
do
21+
echo $(git rev-parse refs/heads/$branch) refs/heads/$branch || return 1
22+
done >expect.branches &&
23+
git refs list --branches >actual &&
24+
test_cmp expect.branches actual &&
25+
26+
for tag in A B C
27+
do
28+
echo $(git rev-parse refs/tags/$tag) refs/tags/$tag || return 1
29+
done >expect.tags &&
30+
git refs list --tags >actual &&
31+
test_cmp expect.tags actual &&
32+
33+
cat expect.branches expect.tags >expect &&
34+
git refs list --branches --tags >actual &&
35+
test_cmp expect actual &&
36+
37+
{
38+
echo $(git rev-parse HEAD) HEAD &&
39+
cat expect.branches expect.tags
40+
} >expect &&
41+
git refs list --branches --tags --head >actual &&
42+
test_cmp expect actual &&
43+
44+
{
45+
echo $(git rev-parse HEAD) HEAD &&
46+
echo $(git rev-parse refs/heads/B) refs/heads/B &&
47+
echo $(git rev-parse refs/tags/B) refs/tags/B
48+
} >expect &&
49+
git refs list --head B >actual &&
50+
test_cmp expect actual &&
51+
52+
{
53+
echo $(git rev-parse refs/heads/B) refs/heads/B &&
54+
echo $(git rev-parse refs/tags/A) refs/tags/A &&
55+
echo $(git rev-parse refs/tags/B) refs/tags/B
56+
} >expect &&
57+
git refs list A B >actual &&
58+
test_cmp expect actual
59+
'
60+
61+
test_expect_success 'Backward compatibility with show-ref' '
62+
git show-ref >expect&&
63+
git refs list >actual&&
64+
test_cmp expect actual &&
65+
66+
git show-ref --branches >expect &&
67+
git refs list --branches >actual &&
68+
test_cmp expect actual &&
69+
70+
git show-ref --tags >expect &&
71+
git refs list --tags >actual &&
72+
test_cmp expect actual &&
73+
74+
git show-ref --head >expect &&
75+
git refs list --head >actual &&
76+
test_cmp expect actual &&
77+
78+
git show-ref --branches --tags --head >expect &&
79+
git refs list --branches --tags --head >actual &&
80+
test_cmp expect actual &&
81+
82+
git show-ref B >expect &&
83+
git refs list B >actual &&
84+
test_cmp expect actual &&
85+
86+
git show-ref --head B >expect &&
87+
git refs list --head B >actual &&
88+
test_cmp expect actual &&
89+
90+
git show-ref A B >expect &&
91+
git refs list A B >actual &&
92+
test_cmp expect actual
93+
'
94+
95+
test_done

0 commit comments

Comments
 (0)