Skip to content

Commit 1adf29e

Browse files
committed
t5730: introduce fetch command helper
Assembling a "raw" fetch command to be fed directly to "test-tool serve-v2" is extracted into a test helper. Suggested-by: Junio C Hamano <[email protected]> Signed-off-by: Kim Altintop <[email protected]>
1 parent ebf3c04 commit 1adf29e

File tree

1 file changed

+74
-33
lines changed

1 file changed

+74
-33
lines changed

t/t5703-upload-pack-ref-in-want.sh

Lines changed: 74 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,54 @@ 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" values can be given in this order,
45+
# with sections separated by "--".
46+
#
47+
# Examples:
48+
#
49+
# write_fetch_command refs/heads/main
50+
#
51+
# write_fetch_command \
52+
# refs/heads/main \
53+
# -- \
54+
# -- \
55+
# $(git rev-parse x)
56+
#
57+
# write_fetch_command \
58+
# --
59+
# $(git rev-parse a) \
60+
# --
61+
# $(git rev-parse b)
62+
write_fetch_command () {
63+
write_command fetch &&
64+
echo "0001" &&
65+
echo "no-progress" || return
66+
while :
67+
do
68+
case $# in 0) break ;; esac &&
69+
case "$1" in --) shift; break ;; esac &&
70+
echo "want-ref $1" &&
71+
shift || return
72+
done &&
73+
while :
74+
do
75+
case $# in 0) break ;; esac &&
76+
case "$1" in --) shift; break ;; esac &&
77+
echo "want $1" &&
78+
shift || return
79+
done &&
80+
while :
81+
do
82+
case $# in 0) break ;; esac &&
83+
case "$1" in --) shift; break ;; esac &&
84+
echo "have $1" &&
85+
shift || return
86+
done &&
87+
echo "done" &&
88+
echo "0000"
89+
}
90+
4391
# c(o/foo) d(o/bar)
4492
# \ /
4593
# b e(baz) f(main)
@@ -97,15 +145,13 @@ test_expect_success 'basic want-ref' '
97145
EOF
98146
git rev-parse f >expected_commits &&
99147
100-
oid=$(git rev-parse a) &&
101148
test-tool pkt-line pack >in <<-EOF &&
102-
$(write_command fetch)
103-
0001
104-
no-progress
105-
want-ref refs/heads/main
106-
have $oid
107-
done
108-
0000
149+
$(write_fetch_command \
150+
refs/heads/main \
151+
-- \
152+
-- \
153+
$(git rev-parse a) \
154+
)
109155
EOF
110156
111157
test-tool serve-v2 --stateless-rpc >out <in &&
@@ -121,16 +167,14 @@ test_expect_success 'multiple want-ref lines' '
121167
EOF
122168
git rev-parse c d >expected_commits &&
123169
124-
oid=$(git rev-parse b) &&
125170
test-tool pkt-line pack >in <<-EOF &&
126-
$(write_command fetch)
127-
0001
128-
no-progress
129-
want-ref refs/heads/o/foo
130-
want-ref refs/heads/o/bar
131-
have $oid
132-
done
133-
0000
171+
$(write_fetch_command \
172+
refs/heads/o/foo \
173+
refs/heads/o/bar \
174+
-- \
175+
-- \
176+
$(git rev-parse b) \
177+
)
134178
EOF
135179
136180
test-tool serve-v2 --stateless-rpc >out <in &&
@@ -145,14 +189,13 @@ test_expect_success 'mix want and want-ref' '
145189
git rev-parse e f >expected_commits &&
146190
147191
test-tool pkt-line pack >in <<-EOF &&
148-
$(write_command fetch)
149-
0001
150-
no-progress
151-
want-ref refs/heads/main
152-
want $(git rev-parse e)
153-
have $(git rev-parse a)
154-
done
155-
0000
192+
$(write_fetch_command \
193+
refs/heads/main \
194+
-- \
195+
$(git rev-parse e) \
196+
-- \
197+
$(git rev-parse a) \
198+
)
156199
EOF
157200
158201
test-tool serve-v2 --stateless-rpc >out <in &&
@@ -166,15 +209,13 @@ test_expect_success 'want-ref with ref we already have commit for' '
166209
EOF
167210
>expected_commits &&
168211
169-
oid=$(git rev-parse c) &&
170212
test-tool pkt-line pack >in <<-EOF &&
171-
$(write_command fetch)
172-
0001
173-
no-progress
174-
want-ref refs/heads/o/foo
175-
have $oid
176-
done
177-
0000
213+
$(write_fetch_command \
214+
refs/heads/o/foo \
215+
-- \
216+
-- \
217+
$(git rev-parse c) \
218+
)
178219
EOF
179220
180221
test-tool serve-v2 --stateless-rpc >out <in &&

0 commit comments

Comments
 (0)