@@ -40,6 +40,30 @@ write_command () {
4040 fi
4141}
4242
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+
4367# c(o/foo) d(o/bar)
4468# \ /
4569# b e(baz) f(main)
@@ -77,15 +101,11 @@ test_expect_success 'config controls ref-in-want advertisement' '
77101'
78102
79103test_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 &&
84105 want-ref refs/heads/non-existent
85- done
86- 0000
87106 EOF
88107
108+ test-tool pkt-line pack <pkt >in &&
89109 test_must_fail test-tool serve-v2 --stateless-rpc 2>out <in &&
90110 grep "unknown ref" out
91111'
@@ -97,16 +117,11 @@ test_expect_success 'basic want-ref' '
97117 EOF
98118 git rev-parse f >expected_commits &&
99119
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 &&
105121 want-ref refs/heads/main
106- have $oid
107- done
108- 0000
122+ have $(git rev-parse a)
109123 EOF
124+ test-tool pkt-line pack <pkt >in &&
110125
111126 test-tool serve-v2 --stateless-rpc >out <in &&
112127 check_output
@@ -121,17 +136,12 @@ test_expect_success 'multiple want-ref lines' '
121136 EOF
122137 git rev-parse c d >expected_commits &&
123138
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 &&
129140 want-ref refs/heads/o/foo
130141 want-ref refs/heads/o/bar
131- have $oid
132- done
133- 0000
142+ have $(git rev-parse b)
134143 EOF
144+ test-tool pkt-line pack <pkt >in &&
135145
136146 test-tool serve-v2 --stateless-rpc >out <in &&
137147 check_output
@@ -144,16 +154,12 @@ test_expect_success 'mix want and want-ref' '
144154 EOF
145155 git rev-parse e f >expected_commits &&
146156
147- test-tool pkt-line pack >in <<-EOF &&
148- $(write_command fetch)
149- 0001
150- no-progress
157+ write_fetch_command >pkt <<-EOF &&
151158 want-ref refs/heads/main
152159 want $(git rev-parse e)
153160 have $(git rev-parse a)
154- done
155- 0000
156161 EOF
162+ test-tool pkt-line pack <pkt >in &&
157163
158164 test-tool serve-v2 --stateless-rpc >out <in &&
159165 check_output
@@ -166,16 +172,11 @@ test_expect_success 'want-ref with ref we already have commit for' '
166172 EOF
167173 >expected_commits &&
168174
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 &&
174176 want-ref refs/heads/o/foo
175- have $oid
176- done
177- 0000
177+ have $(git rev-parse c)
178178 EOF
179+ test-tool pkt-line pack <pkt >in &&
179180
180181 test-tool serve-v2 --stateless-rpc >out <in &&
181182 check_output
0 commit comments