fetch-pack: perform a fetch using v2
[git] / t / t5702-protocol-v2.sh
1 #!/bin/sh
2
3 test_description='test git wire-protocol version 2'
4
5 TEST_NO_CREATE_REPO=1
6
7 . ./test-lib.sh
8
9 # Test protocol v2 with 'git://' transport
10 #
11 . "$TEST_DIRECTORY"/lib-git-daemon.sh
12 start_git_daemon --export-all --enable=receive-pack
13 daemon_parent=$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent
14
15 test_expect_success 'create repo to be served by git-daemon' '
16         git init "$daemon_parent" &&
17         test_commit -C "$daemon_parent" one
18 '
19
20 test_expect_success 'list refs with git:// using protocol v2' '
21         GIT_TRACE_PACKET=1 git -c protocol.version=2 \
22                 ls-remote --symref "$GIT_DAEMON_URL/parent" >actual 2>log &&
23
24         # Client requested to use protocol v2
25         grep "git> .*\\\0\\\0version=2\\\0$" log &&
26         # Server responded using protocol v2
27         grep "git< version 2" log &&
28
29         git ls-remote --symref "$GIT_DAEMON_URL/parent" >expect &&
30         test_cmp actual expect
31 '
32
33 test_expect_success 'ref advertisment is filtered with ls-remote using protocol v2' '
34         GIT_TRACE_PACKET=1 git -c protocol.version=2 \
35                 ls-remote "$GIT_DAEMON_URL/parent" master 2>log &&
36
37         grep "ref-pattern master" log &&
38         ! grep "refs/tags/" log
39 '
40
41 test_expect_success 'clone with git:// using protocol v2' '
42         GIT_TRACE_PACKET=1 git -c protocol.version=2 \
43                 clone "$GIT_DAEMON_URL/parent" daemon_child 2>log &&
44
45         git -C daemon_child log -1 --format=%s >actual &&
46         git -C "$daemon_parent" log -1 --format=%s >expect &&
47         test_cmp expect actual &&
48
49         # Client requested to use protocol v2
50         grep "clone> .*\\\0\\\0version=2\\\0$" log &&
51         # Server responded using protocol v2
52         grep "clone< version 2" log
53 '
54
55 test_expect_success 'fetch with git:// using protocol v2' '
56         test_commit -C "$daemon_parent" two &&
57
58         GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=2 \
59                 fetch 2>log &&
60
61         git -C daemon_child log -1 --format=%s origin/master >actual &&
62         git -C "$daemon_parent" log -1 --format=%s >expect &&
63         test_cmp expect actual &&
64
65         # Client requested to use protocol v2
66         grep "fetch> .*\\\0\\\0version=2\\\0$" log &&
67         # Server responded using protocol v2
68         grep "fetch< version 2" log
69 '
70
71 test_expect_success 'pull with git:// using protocol v2' '
72         GIT_TRACE_PACKET=1 git -C daemon_child -c protocol.version=2 \
73                 pull 2>log &&
74
75         git -C daemon_child log -1 --format=%s >actual &&
76         git -C "$daemon_parent" log -1 --format=%s >expect &&
77         test_cmp expect actual &&
78
79         # Client requested to use protocol v2
80         grep "fetch> .*\\\0\\\0version=2\\\0$" log &&
81         # Server responded using protocol v2
82         grep "fetch< version 2" log
83 '
84
85 stop_git_daemon
86
87 # Test protocol v2 with 'file://' transport
88 #
89 test_expect_success 'create repo to be served by file:// transport' '
90         git init file_parent &&
91         test_commit -C file_parent one
92 '
93
94 test_expect_success 'list refs with file:// using protocol v2' '
95         GIT_TRACE_PACKET=1 git -c protocol.version=2 \
96                 ls-remote --symref "file://$(pwd)/file_parent" >actual 2>log &&
97
98         # Server responded using protocol v2
99         grep "git< version 2" log &&
100
101         git ls-remote --symref "file://$(pwd)/file_parent" >expect &&
102         test_cmp actual expect
103 '
104
105 test_expect_success 'ref advertisment is filtered with ls-remote using protocol v2' '
106         GIT_TRACE_PACKET=1 git -c protocol.version=2 \
107                 ls-remote "file://$(pwd)/file_parent" master 2>log &&
108
109         grep "ref-pattern master" log &&
110         ! grep "refs/tags/" log
111 '
112
113 test_expect_success 'clone with file:// using protocol v2' '
114         GIT_TRACE_PACKET=1 git -c protocol.version=2 \
115                 clone "file://$(pwd)/file_parent" file_child 2>log &&
116
117         git -C file_child log -1 --format=%s >actual &&
118         git -C file_parent log -1 --format=%s >expect &&
119         test_cmp expect actual &&
120
121         # Server responded using protocol v2
122         grep "clone< version 2" log
123 '
124
125 test_expect_success 'fetch with file:// using protocol v2' '
126         test_commit -C file_parent two &&
127
128         GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=2 \
129                 fetch origin 2>log &&
130
131         git -C file_child log -1 --format=%s origin/master >actual &&
132         git -C file_parent log -1 --format=%s >expect &&
133         test_cmp expect actual &&
134
135         # Server responded using protocol v2
136         grep "fetch< version 2" log
137 '
138
139 test_expect_success 'ref advertisment is filtered during fetch using protocol v2' '
140         test_commit -C file_parent three &&
141
142         GIT_TRACE_PACKET=1 git -C file_child -c protocol.version=2 \
143                 fetch origin master 2>log &&
144
145         git -C file_child log -1 --format=%s origin/master >actual &&
146         git -C file_parent log -1 --format=%s >expect &&
147         test_cmp expect actual &&
148
149         grep "ref-pattern master" log &&
150         ! grep "refs/tags/" log
151 '
152
153 test_done