{upload,receive}-pack tests: add --advertise-refs tests
The --advertise-refs option had no explicit tests of its own, only other http tests that would fail at a distance if it it was broken. Let's test its behavior explicitly. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Aug 5, 2021 at 03:25 UTC
760486a1f7a141b0d50b1c9c709ac1882968955c
1 file changed
+147
t/t5555-http-smart-common.sh
new
+147
@@ -0,0 +1,147 @@
1
+#!/bin/sh
2
+
3
+test_description='test functionality common to smart fetch & push'
4
+
5
+. ./test-lib.sh
6
+
7
+test_expect_success 'setup' '
8
+ test_commit --no-tag initial
9
+'
10
+
11
+test_expect_success 'git upload-pack --advertise-refs' '
12
+ cat >expect <<-EOF &&
13
+ $(git rev-parse HEAD) HEAD
14
+ $(git rev-parse HEAD) $(git symbolic-ref HEAD)
15
+ 0000
16
+ EOF
17
+
18
+ # We only care about GIT_PROTOCOL, not GIT_TEST_PROTOCOL_VERSION
19
+ sane_unset GIT_PROTOCOL &&
20
+ GIT_TEST_PROTOCOL_VERSION=2 \
21
+ git upload-pack --advertise-refs . >out 2>err &&
22
+
23
+ test-tool pkt-line unpack <out >actual &&
24
+ test_must_be_empty err &&
25
+ test_cmp actual expect &&
26
+
27
+ # The --advertise-refs alias works
28
+ git upload-pack --advertise-refs . >out 2>err &&
29
+
30
+ test-tool pkt-line unpack <out >actual &&
31
+ test_must_be_empty err &&
32
+ test_cmp actual expect
33
+'
34
+
35
+test_expect_success 'git upload-pack --advertise-refs: v0' '
36
+ # With no specified protocol
37
+ cat >expect <<-EOF &&
38
+ $(git rev-parse HEAD) HEAD
39
+ $(git rev-parse HEAD) $(git symbolic-ref HEAD)
40
+ 0000
41
+ EOF
42
+
43
+ git upload-pack --advertise-refs . >out 2>err &&
44
+ test-tool pkt-line unpack <out >actual &&
45
+ test_must_be_empty err &&
46
+ test_cmp actual expect &&
47
+
48
+ # With explicit v0
49
+ GIT_PROTOCOL=version=0 \
50
+ git upload-pack --advertise-refs . >out 2>err &&
51
+ test-tool pkt-line unpack <out >actual 2>err &&
52
+ test_must_be_empty err &&
53
+ test_cmp actual expect
54
+
55
+'
56
+
57
+test_expect_success 'git receive-pack --advertise-refs: v0' '
58
+ # With no specified protocol
59
+ cat >expect <<-EOF &&
60
+ $(git rev-parse HEAD) $(git symbolic-ref HEAD)
61
+ 0000
62
+ EOF
63
+
64
+ git receive-pack --advertise-refs . >out 2>err &&
65
+ test-tool pkt-line unpack <out >actual &&
66
+ test_must_be_empty err &&
67
+ test_cmp actual expect &&
68
+
69
+ # With explicit v0
70
+ GIT_PROTOCOL=version=0 \
71
+ git receive-pack --advertise-refs . >out 2>err &&
72
+ test-tool pkt-line unpack <out >actual 2>err &&
73
+ test_must_be_empty err &&
74
+ test_cmp actual expect
75
+
76
+'
77
+
78
+test_expect_success 'git upload-pack --advertise-refs: v1' '
79
+ # With no specified protocol
80
+ cat >expect <<-EOF &&
81
+ version 1
82
+ $(git rev-parse HEAD) HEAD
83
+ $(git rev-parse HEAD) $(git symbolic-ref HEAD)
84
+ 0000
85
+ EOF
86
+
87
+ GIT_PROTOCOL=version=1 \
88
+ git upload-pack --advertise-refs . >out &&
89
+
90
+ test-tool pkt-line unpack <out >actual 2>err &&
91
+ test_must_be_empty err &&
92
+ test_cmp actual expect
93
+'
94
+
95
+test_expect_success 'git receive-pack --advertise-refs: v1' '
96
+ # With no specified protocol
97
+ cat >expect <<-EOF &&
98
+ version 1
99
+ $(git rev-parse HEAD) $(git symbolic-ref HEAD)
100
+ 0000
101
+ EOF
102
+
103
+ GIT_PROTOCOL=version=1 \
104
+ git receive-pack --advertise-refs . >out &&
105
+
106
+ test-tool pkt-line unpack <out >actual 2>err &&
107
+ test_must_be_empty err &&
108
+ test_cmp actual expect
109
+'
110
+
111
+test_expect_success 'git upload-pack --advertise-refs: v2' '
112
+ cat >expect <<-EOF &&
113
+ version 2
114
+ agent=FAKE
115
+ ls-refs=unborn
116
+ fetch=shallow wait-for-done
117
+ server-option
118
+ object-format=$(test_oid algo)
119
+ object-info
120
+ 0000
121
+ EOF
122
+
123
+ GIT_PROTOCOL=version=2 \
124
+ GIT_USER_AGENT=FAKE \
125
+ git upload-pack --advertise-refs . >out 2>err &&
126
+
127
+ test-tool pkt-line unpack <out >actual &&
128
+ test_must_be_empty err &&
129
+ test_cmp actual expect
130
+'
131
+
132
+test_expect_success 'git receive-pack --advertise-refs: v2' '
133
+ # There is no v2 yet for receive-pack, implicit v0
134
+ cat >expect <<-EOF &&
135
+ $(git rev-parse HEAD) $(git symbolic-ref HEAD)
136
+ 0000
137
+ EOF
138
+
139
+ GIT_PROTOCOL=version=2 \
140
+ git receive-pack --advertise-refs . >out 2>err &&
141
+
142
+ test-tool pkt-line unpack <out >actual &&
143
+ test_must_be_empty err &&
144
+ test_cmp actual expect
145
+'
146
+
147
+test_done