Skip to content

Commit b7ce24d

Browse files
dschogitster
authored andcommitted
Turn git serve into a test helper
The `git serve` built-in was introduced in ed10cb9 (serve: introduce git-serve, 2018-03-15) as a backend to serve Git protocol v2, probably originally intended to be spawned by `git upload-pack`. However, in the version that the protocol v2 patches made it into core Git, `git upload-pack` calls the `serve()` function directly instead of spawning `git serve`; The only reason in life for `git serve` to survive as a built-in command is to provide a way to test the protocol v2 functionality. Meaning that it does not even have to be a built-in that is installed with end-user facing Git installations, but it can be a test helper instead. Let's make it so. Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6ea18ff commit b7ce24d

File tree

9 files changed

+36
-30
lines changed

9 files changed

+36
-30
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ TEST_BUILTINS_OBJS += test-repository.o
758758
TEST_BUILTINS_OBJS += test-revision-walking.o
759759
TEST_BUILTINS_OBJS += test-run-command.o
760760
TEST_BUILTINS_OBJS += test-scrap-cache-tree.o
761+
TEST_BUILTINS_OBJS += test-serve-v2.o
761762
TEST_BUILTINS_OBJS += test-sha1.o
762763
TEST_BUILTINS_OBJS += test-sha1-array.o
763764
TEST_BUILTINS_OBJS += test-sha256.o
@@ -1127,7 +1128,6 @@ BUILTIN_OBJS += builtin/rev-parse.o
11271128
BUILTIN_OBJS += builtin/revert.o
11281129
BUILTIN_OBJS += builtin/rm.o
11291130
BUILTIN_OBJS += builtin/send-pack.o
1130-
BUILTIN_OBJS += builtin/serve.o
11311131
BUILTIN_OBJS += builtin/shortlog.o
11321132
BUILTIN_OBJS += builtin/show-branch.o
11331133
BUILTIN_OBJS += builtin/show-index.o

builtin.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ extern int cmd_rev_parse(int argc, const char **argv, const char *prefix);
219219
extern int cmd_revert(int argc, const char **argv, const char *prefix);
220220
extern int cmd_rm(int argc, const char **argv, const char *prefix);
221221
extern int cmd_send_pack(int argc, const char **argv, const char *prefix);
222-
extern int cmd_serve(int argc, const char **argv, const char *prefix);
223222
extern int cmd_shortlog(int argc, const char **argv, const char *prefix);
224223
extern int cmd_show(int argc, const char **argv, const char *prefix);
225224
extern int cmd_show_branch(int argc, const char **argv, const char *prefix);

git.c

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -548,7 +548,6 @@ static struct cmd_struct commands[] = {
548548
{ "revert", cmd_revert, RUN_SETUP | NEED_WORK_TREE },
549549
{ "rm", cmd_rm, RUN_SETUP },
550550
{ "send-pack", cmd_send_pack, RUN_SETUP },
551-
{ "serve", cmd_serve, RUN_SETUP },
552551
{ "shortlog", cmd_shortlog, RUN_SETUP_GENTLY | USE_PAGER },
553552
{ "show", cmd_show, RUN_SETUP },
554553
{ "show-branch", cmd_show_branch, RUN_SETUP },

builtin/serve.c renamed to t/helper/test-serve-v2.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1+
#include "test-tool.h"
12
#include "cache.h"
2-
#include "builtin.h"
33
#include "parse-options.h"
44
#include "serve.h"
55

66
static char const * const serve_usage[] = {
7-
N_("git serve [<options>]"),
7+
N_("test-tool serve-v2 [<options>]"),
88
NULL
99
};
1010

11-
int cmd_serve(int argc, const char **argv, const char *prefix)
11+
int cmd__serve_v2(int argc, const char **argv)
1212
{
1313
struct serve_options opts = SERVE_OPTIONS_INIT;
1414

@@ -19,6 +19,7 @@ int cmd_serve(int argc, const char **argv, const char *prefix)
1919
N_("exit immediately after advertising capabilities")),
2020
OPT_END()
2121
};
22+
const char *prefix = setup_git_directory();
2223

2324
/* ignore all unknown cmdline switches for now */
2425
argc = parse_options(argc, argv, prefix, options, serve_usage,

t/helper/test-tool.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ static struct test_cmd cmds[] = {
4848
{ "revision-walking", cmd__revision_walking },
4949
{ "run-command", cmd__run_command },
5050
{ "scrap-cache-tree", cmd__scrap_cache_tree },
51+
{ "serve-v2", cmd__serve_v2 },
5152
{ "sha1", cmd__sha1 },
5253
{ "sha1-array", cmd__sha1_array },
5354
{ "sha256", cmd__sha256 },

t/helper/test-tool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ int cmd__repository(int argc, const char **argv);
3939
int cmd__revision_walking(int argc, const char **argv);
4040
int cmd__run_command(int argc, const char **argv);
4141
int cmd__scrap_cache_tree(int argc, const char **argv);
42+
int cmd__serve_v2(int argc, const char **argv);
4243
int cmd__sha1(int argc, const char **argv);
4344
int cmd__sha1_array(int argc, const char **argv);
4445
int cmd__sha256(int argc, const char **argv);

t/t5701-git-serve.sh

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22

3-
test_description='test git-serve and server commands'
3+
test_description='test protocol v2 server commands'
44

55
. ./test-lib.sh
66

@@ -14,7 +14,8 @@ test_expect_success 'test capability advertisement' '
1414
0000
1515
EOF
1616
17-
GIT_TEST_SIDEBAND_ALL=0 git serve --advertise-capabilities >out &&
17+
GIT_TEST_SIDEBAND_ALL=0 test-tool serve-v2 \
18+
--advertise-capabilities >out &&
1819
test-tool pkt-line unpack <out >actual &&
1920
test_cmp expect actual
2021
'
@@ -24,11 +25,11 @@ test_expect_success 'stateless-rpc flag does not list capabilities' '
2425
test-tool pkt-line pack >in <<-EOF &&
2526
0000
2627
EOF
27-
git serve --stateless-rpc >out <in &&
28+
test-tool serve-v2 --stateless-rpc >out <in &&
2829
test_must_be_empty out &&
2930
3031
# EOF
31-
git serve --stateless-rpc >out &&
32+
test-tool serve-v2 --stateless-rpc >out &&
3233
test_must_be_empty out
3334
'
3435

@@ -37,7 +38,7 @@ test_expect_success 'request invalid capability' '
3738
foobar
3839
0000
3940
EOF
40-
test_must_fail git serve --stateless-rpc 2>err <in &&
41+
test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
4142
test_i18ngrep "unknown capability" err
4243
'
4344

@@ -46,7 +47,7 @@ test_expect_success 'request with no command' '
4647
agent=git/test
4748
0000
4849
EOF
49-
test_must_fail git serve --stateless-rpc 2>err <in &&
50+
test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
5051
test_i18ngrep "no command requested" err
5152
'
5253

@@ -56,7 +57,7 @@ test_expect_success 'request invalid command' '
5657
agent=git/test
5758
0000
5859
EOF
59-
test_must_fail git serve --stateless-rpc 2>err <in &&
60+
test_must_fail test-tool serve-v2 --stateless-rpc 2>err <in &&
6061
test_i18ngrep "invalid command" err
6162
'
6263

@@ -87,7 +88,7 @@ test_expect_success 'basics of ls-refs' '
8788
0000
8889
EOF
8990
90-
git serve --stateless-rpc <in >out &&
91+
test-tool serve-v2 --stateless-rpc <in >out &&
9192
test-tool pkt-line unpack <out >actual &&
9293
test_cmp expect actual
9394
'
@@ -107,7 +108,7 @@ test_expect_success 'basic ref-prefixes' '
107108
0000
108109
EOF
109110
110-
git serve --stateless-rpc <in >out &&
111+
test-tool serve-v2 --stateless-rpc <in >out &&
111112
test-tool pkt-line unpack <out >actual &&
112113
test_cmp expect actual
113114
'
@@ -127,7 +128,7 @@ test_expect_success 'refs/heads prefix' '
127128
0000
128129
EOF
129130
130-
git serve --stateless-rpc <in >out &&
131+
test-tool serve-v2 --stateless-rpc <in >out &&
131132
test-tool pkt-line unpack <out >actual &&
132133
test_cmp expect actual
133134
'
@@ -148,7 +149,7 @@ test_expect_success 'peel parameter' '
148149
0000
149150
EOF
150151
151-
git serve --stateless-rpc <in >out &&
152+
test-tool serve-v2 --stateless-rpc <in >out &&
152153
test-tool pkt-line unpack <out >actual &&
153154
test_cmp expect actual
154155
'
@@ -169,7 +170,7 @@ test_expect_success 'symrefs parameter' '
169170
0000
170171
EOF
171172
172-
git serve --stateless-rpc <in >out &&
173+
test-tool serve-v2 --stateless-rpc <in >out &&
173174
test-tool pkt-line unpack <out >actual &&
174175
test_cmp expect actual
175176
'
@@ -189,7 +190,7 @@ test_expect_success 'sending server-options' '
189190
0000
190191
EOF
191192
192-
git serve --stateless-rpc <in >out &&
193+
test-tool serve-v2 --stateless-rpc <in >out &&
193194
test-tool pkt-line unpack <out >actual &&
194195
test_cmp expect actual
195196
'
@@ -204,7 +205,10 @@ test_expect_success 'unexpected lines are not allowed in fetch request' '
204205
0000
205206
EOF
206207
207-
test_must_fail git -C server serve --stateless-rpc <in >/dev/null 2>err &&
208+
(
209+
cd server &&
210+
test_must_fail test-tool serve-v2 --stateless-rpc
211+
) <in >/dev/null 2>err &&
208212
grep "unexpected line: .this-is-not-a-command." err
209213
'
210214

t/t5702-protocol-v2.sh

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -359,12 +359,13 @@ test_expect_success 'even with handcrafted request, filter does not work if not
359359
0000
360360
EOF
361361
362-
test_must_fail git -C server serve --stateless-rpc <in >/dev/null 2>err &&
362+
test_must_fail test-tool -C server serve-v2 --stateless-rpc \
363+
<in >/dev/null 2>err &&
363364
grep "unexpected line: .filter blob:none." err &&
364365
365366
# Exercise to ensure that if advertised, filter works
366367
git -C server config uploadpack.allowfilter 1 &&
367-
git -C server serve --stateless-rpc <in >/dev/null
368+
test-tool -C server serve-v2 --stateless-rpc <in >/dev/null
368369
'
369370

370371
test_expect_success 'default refspec is used to filter ref when fetchcing' '

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,15 +48,15 @@ test_expect_success 'setup repository' '
4848
'
4949

5050
test_expect_success 'config controls ref-in-want advertisement' '
51-
git serve --advertise-capabilities >out &&
51+
test-tool serve-v2 --advertise-capabilities >out &&
5252
! grep -a ref-in-want out &&
5353
5454
git config uploadpack.allowRefInWant false &&
55-
git serve --advertise-capabilities >out &&
55+
test-tool serve-v2 --advertise-capabilities >out &&
5656
! grep -a ref-in-want out &&
5757
5858
git config uploadpack.allowRefInWant true &&
59-
git serve --advertise-capabilities >out &&
59+
test-tool serve-v2 --advertise-capabilities >out &&
6060
grep -a ref-in-want out
6161
'
6262

@@ -70,7 +70,7 @@ test_expect_success 'invalid want-ref line' '
7070
0000
7171
EOF
7272
73-
test_must_fail git serve --stateless-rpc 2>out <in &&
73+
test_must_fail test-tool serve-v2 --stateless-rpc 2>out <in &&
7474
grep "unknown ref" out
7575
'
7676

@@ -90,7 +90,7 @@ test_expect_success 'basic want-ref' '
9090
0000
9191
EOF
9292
93-
git serve --stateless-rpc >out <in &&
93+
test-tool serve-v2 --stateless-rpc >out <in &&
9494
check_output
9595
'
9696

@@ -112,7 +112,7 @@ test_expect_success 'multiple want-ref lines' '
112112
0000
113113
EOF
114114
115-
git serve --stateless-rpc >out <in &&
115+
test-tool serve-v2 --stateless-rpc >out <in &&
116116
check_output
117117
'
118118

@@ -133,7 +133,7 @@ test_expect_success 'mix want and want-ref' '
133133
0000
134134
EOF
135135
136-
git serve --stateless-rpc >out <in &&
136+
test-tool serve-v2 --stateless-rpc >out <in &&
137137
check_output
138138
'
139139

@@ -153,7 +153,7 @@ test_expect_success 'want-ref with ref we already have commit for' '
153153
0000
154154
EOF
155155
156-
git serve --stateless-rpc >out <in &&
156+
test-tool serve-v2 --stateless-rpc >out <in &&
157157
check_output
158158
'
159159

0 commit comments

Comments
 (0)