@@ -40,6 +40,30 @@ write_command () {
40
40
fi
41
41
}
42
42
43
+ # Write a complete fetch command to stdout, suitable for use with `test-tool
44
+ # pkt-line`. "want-ref", "want", and "have" lines are read from stdin.
45
+ #
46
+ # Examples:
47
+ #
48
+ # write_fetch_command <<-EOF
49
+ # want-ref refs/heads/main
50
+ # have $(git rev-parse a)
51
+ # EOF
52
+ #
53
+ # write_fetch_command <<-EOF
54
+ # want $(git rev-parse b)
55
+ # have $(git rev-parse a)
56
+ # EOF
57
+ #
58
+ write_fetch_command () {
59
+ write_command fetch &&
60
+ echo " 0001" &&
61
+ echo " no-progress" &&
62
+ cat &&
63
+ echo " done" &&
64
+ echo " 0000"
65
+ }
66
+
43
67
# c(o/foo) d(o/bar)
44
68
# \ /
45
69
# b e(baz) f(main)
@@ -77,15 +101,11 @@ test_expect_success 'config controls ref-in-want advertisement' '
77
101
'
78
102
79
103
test_expect_success ' invalid want-ref line' '
80
- test-tool pkt-line pack >in <<-EOF &&
81
- $(write_command fetch)
82
- 0001
83
- no-progress
104
+ write_fetch_command >pkt <<-EOF &&
84
105
want-ref refs/heads/non-existent
85
- done
86
- 0000
87
106
EOF
88
107
108
+ test-tool pkt-line pack <pkt >in &&
89
109
test_must_fail test-tool serve-v2 --stateless-rpc 2>out <in &&
90
110
grep "unknown ref" out
91
111
'
@@ -97,16 +117,11 @@ test_expect_success 'basic want-ref' '
97
117
EOF
98
118
git rev-parse f >expected_commits &&
99
119
100
- oid=$(git rev-parse a) &&
101
- test-tool pkt-line pack >in <<-EOF &&
102
- $(write_command fetch)
103
- 0001
104
- no-progress
120
+ write_fetch_command >pkt <<-EOF &&
105
121
want-ref refs/heads/main
106
- have $oid
107
- done
108
- 0000
122
+ have $(git rev-parse a)
109
123
EOF
124
+ test-tool pkt-line pack <pkt >in &&
110
125
111
126
test-tool serve-v2 --stateless-rpc >out <in &&
112
127
check_output
@@ -121,17 +136,12 @@ test_expect_success 'multiple want-ref lines' '
121
136
EOF
122
137
git rev-parse c d >expected_commits &&
123
138
124
- oid=$(git rev-parse b) &&
125
- test-tool pkt-line pack >in <<-EOF &&
126
- $(write_command fetch)
127
- 0001
128
- no-progress
139
+ write_fetch_command >pkt <<-EOF &&
129
140
want-ref refs/heads/o/foo
130
141
want-ref refs/heads/o/bar
131
- have $oid
132
- done
133
- 0000
142
+ have $(git rev-parse b)
134
143
EOF
144
+ test-tool pkt-line pack <pkt >in &&
135
145
136
146
test-tool serve-v2 --stateless-rpc >out <in &&
137
147
check_output
@@ -144,16 +154,12 @@ test_expect_success 'mix want and want-ref' '
144
154
EOF
145
155
git rev-parse e f >expected_commits &&
146
156
147
- test-tool pkt-line pack >in <<-EOF &&
148
- $(write_command fetch)
149
- 0001
150
- no-progress
157
+ write_fetch_command >pkt <<-EOF &&
151
158
want-ref refs/heads/main
152
159
want $(git rev-parse e)
153
160
have $(git rev-parse a)
154
- done
155
- 0000
156
161
EOF
162
+ test-tool pkt-line pack <pkt >in &&
157
163
158
164
test-tool serve-v2 --stateless-rpc >out <in &&
159
165
check_output
@@ -166,16 +172,11 @@ test_expect_success 'want-ref with ref we already have commit for' '
166
172
EOF
167
173
>expected_commits &&
168
174
169
- oid=$(git rev-parse c) &&
170
- test-tool pkt-line pack >in <<-EOF &&
171
- $(write_command fetch)
172
- 0001
173
- no-progress
175
+ write_fetch_command >pkt <<-EOF &&
174
176
want-ref refs/heads/o/foo
175
- have $oid
176
- done
177
- 0000
177
+ have $(git rev-parse c)
178
178
EOF
179
+ test-tool pkt-line pack <pkt >in &&
179
180
180
181
test-tool serve-v2 --stateless-rpc >out <in &&
181
182
check_output
0 commit comments