]> git.ipfire.org Git - thirdparty/git.git/blob - t/lib-bundle-uri-protocol.sh
3022ea4a95b782a85c03650009dff8e343664274
[thirdparty/git.git] / t / lib-bundle-uri-protocol.sh
1 # Set up and run tests of the 'bundle-uri' command in protocol v2
2 #
3 # The test that includes this script should set BUNDLE_URI_PROTOCOL
4 # to one of "file", "git", or "http".
5
6 BUNDLE_URI_TEST_PARENT=
7 BUNDLE_URI_TEST_URI=
8 BUNDLE_URI_TEST_BUNDLE_URI=
9 case "$BUNDLE_URI_PROTOCOL" in
10 file)
11 BUNDLE_URI_PARENT=file_parent
12 BUNDLE_URI_REPO_URI="file://$PWD/file_parent"
13 BUNDLE_URI_BUNDLE_URI="$BUNDLE_URI_REPO_URI/fake.bdl"
14 test_set_prereq BUNDLE_URI_FILE
15 ;;
16 git)
17 . "$TEST_DIRECTORY"/lib-git-daemon.sh
18 start_git_daemon --export-all --enable=receive-pack
19 BUNDLE_URI_PARENT="$GIT_DAEMON_DOCUMENT_ROOT_PATH/parent"
20 BUNDLE_URI_REPO_URI="$GIT_DAEMON_URL/parent"
21 BUNDLE_URI_BUNDLE_URI="https://example.com/fake.bdl"
22 test_set_prereq BUNDLE_URI_GIT
23 ;;
24 http)
25 . "$TEST_DIRECTORY"/lib-httpd.sh
26 start_httpd
27 BUNDLE_URI_PARENT="$HTTPD_DOCUMENT_ROOT_PATH/http_parent"
28 BUNDLE_URI_REPO_URI="$HTTPD_URL/smart/http_parent"
29 BUNDLE_URI_BUNDLE_URI="https://example.com/fake.bdl"
30 test_set_prereq BUNDLE_URI_HTTP
31 ;;
32 *)
33 BUG "Need to pass valid BUNDLE_URI_PROTOCOL (was \"$BUNDLE_URI_PROTOCOL\")"
34 ;;
35 esac
36
37 test_expect_success "setup protocol v2 $BUNDLE_URI_PROTOCOL:// tests" '
38 git init "$BUNDLE_URI_PARENT" &&
39 test_commit -C "$BUNDLE_URI_PARENT" one &&
40 git -C "$BUNDLE_URI_PARENT" config uploadpack.advertiseBundleURIs true
41 '
42
43 case "$BUNDLE_URI_PROTOCOL" in
44 http)
45 test_expect_success "setup config for $BUNDLE_URI_PROTOCOL:// tests" '
46 git -C "$BUNDLE_URI_PARENT" config http.receivepack true
47 '
48 ;;
49 *)
50 ;;
51 esac
52 BUNDLE_URI_BUNDLE_URI_ESCAPED=$(echo "$BUNDLE_URI_BUNDLE_URI" | test_uri_escape)
53
54 test_expect_success "connect with $BUNDLE_URI_PROTOCOL:// using protocol v2: no bundle-uri" '
55 test_when_finished "rm -f log" &&
56 test_when_finished "git -C \"$BUNDLE_URI_PARENT\" config uploadpack.advertiseBundleURIs true" &&
57 git -C "$BUNDLE_URI_PARENT" config uploadpack.advertiseBundleURIs false &&
58
59 GIT_TRACE_PACKET="$PWD/log" \
60 git \
61 -c protocol.version=2 \
62 ls-remote --symref "$BUNDLE_URI_REPO_URI" \
63 >actual 2>err &&
64
65 # Server responded using protocol v2
66 grep "< version 2" log &&
67
68 ! grep bundle-uri log
69 '
70
71 test_expect_success "connect with $BUNDLE_URI_PROTOCOL:// using protocol v2: have bundle-uri" '
72 test_when_finished "rm -f log" &&
73
74 GIT_TRACE_PACKET="$PWD/log" \
75 git \
76 -c protocol.version=2 \
77 ls-remote --symref "$BUNDLE_URI_REPO_URI" \
78 >actual 2>err &&
79
80 # Server responded using protocol v2
81 grep "< version 2" log &&
82
83 # Server advertised bundle-uri capability
84 grep "< bundle-uri" log
85 '
86
87 test_expect_success "clone with $BUNDLE_URI_PROTOCOL:// using protocol v2: request bundle-uris" '
88 test_when_finished "rm -rf log cloned cloned2" &&
89
90 GIT_TRACE_PACKET="$PWD/log" \
91 git \
92 -c transfer.bundleURI=false \
93 -c protocol.version=2 \
94 clone "$BUNDLE_URI_REPO_URI" cloned \
95 >actual 2>err &&
96
97 # Server responded using protocol v2
98 grep "< version 2" log &&
99
100 # Server advertised bundle-uri capability
101 grep "< bundle-uri" log &&
102
103 # Client did not issue bundle-uri command
104 ! grep "> command=bundle-uri" log &&
105
106 GIT_TRACE_PACKET="$PWD/log" \
107 git \
108 -c transfer.bundleURI=true \
109 -c protocol.version=2 \
110 clone "$BUNDLE_URI_REPO_URI" cloned2 \
111 >actual 2>err &&
112
113 # Server responded using protocol v2
114 grep "< version 2" log &&
115
116 # Server advertised bundle-uri capability
117 grep "< bundle-uri" log &&
118
119 # Client issued bundle-uri command
120 grep "> command=bundle-uri" log
121 '
122
123 # The remaining tests will all assume transfer.bundleURI=true
124 #
125 # This test can be removed when transfer.bundleURI is enabled by default.
126 test_expect_success 'enable transfer.bundleURI for remaining tests' '
127 git config --global transfer.bundleURI true
128 '
129
130 test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol v2" '
131 test_config -C "$BUNDLE_URI_PARENT" \
132 bundle.only.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED" &&
133
134 # All data about bundle URIs
135 cat >expect <<-EOF &&
136 [bundle]
137 version = 1
138 mode = all
139 [bundle "only"]
140 uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED
141 EOF
142
143 test-tool bundle-uri \
144 ls-remote \
145 "$BUNDLE_URI_REPO_URI" \
146 >actual &&
147 test_cmp_config_output expect actual
148 '
149
150 test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol v2 and extra data" '
151 test_config -C "$BUNDLE_URI_PARENT" \
152 bundle.only.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED" &&
153
154 # Extra data should be ignored
155 test_config -C "$BUNDLE_URI_PARENT" bundle.only.extra bogus &&
156
157 # All data about bundle URIs
158 cat >expect <<-EOF &&
159 [bundle]
160 version = 1
161 mode = all
162 [bundle "only"]
163 uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED
164 EOF
165
166 test-tool bundle-uri \
167 ls-remote \
168 "$BUNDLE_URI_REPO_URI" \
169 >actual &&
170 test_cmp_config_output expect actual
171 '
172
173 test_expect_success "test bundle-uri with $BUNDLE_URI_PROTOCOL:// using protocol v2 with list" '
174 test_config -C "$BUNDLE_URI_PARENT" \
175 bundle.bundle1.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED-1.bdl" &&
176 test_config -C "$BUNDLE_URI_PARENT" \
177 bundle.bundle2.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED-2.bdl" &&
178 test_config -C "$BUNDLE_URI_PARENT" \
179 bundle.bundle3.uri "$BUNDLE_URI_BUNDLE_URI_ESCAPED-3.bdl" &&
180
181 # All data about bundle URIs
182 cat >expect <<-EOF &&
183 [bundle]
184 version = 1
185 mode = all
186 [bundle "bundle1"]
187 uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED-1.bdl
188 [bundle "bundle2"]
189 uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED-2.bdl
190 [bundle "bundle3"]
191 uri = $BUNDLE_URI_BUNDLE_URI_ESCAPED-3.bdl
192 EOF
193
194 test-tool bundle-uri \
195 ls-remote \
196 "$BUNDLE_URI_REPO_URI" \
197 >actual &&
198 test_cmp_config_output expect actual
199 '