Skip to content

Commit 7cb0268

Browse files
chriscoolgitster
authored andcommitted
t5710: use proper file:// URIs for absolute paths
In t5710, we frequently construct local file URIs using `file://$(pwd)`. On Unix-like systems, $(pwd) returns an absolute path starting with a slash (e.g., `/tmp/repo`), resulting in a valid 3-slash URI with an empty host (`file:///tmp/repo`). However, on Windows, $(pwd) returns a path starting with a drive letter (e.g., `D:/a/repo`). This results in a 2-slash URI (`file://D:/a/repo`). Standard URI parsers misinterpret this format, treating `D:` as the host rather than part of the absolute path. This is to be expected because RFC 8089 says that the `//` prefix with an empty local host must be followed by an absolute path starting with a slash. While this hasn't broken the existing tests (because the old `promisor.acceptFromServer` logic relies entirely on strict `strcmp()` without normalizing the URLs), it will break future commits that pass these URLs through `url_normalize()` or similar functions. To future-proof the tests and ensure cross-platform URI compliance, let's introduce a $PWD_URL helper that explicitly guarantees a leading slash for the path component, ensuring valid 3-slash `file:///` URIs on all operating systems. While at it, let's also introduce $ENCODED_PWD_URL to handle spaces in directory paths (which is needed for URL glob pattern matching). Then let's replace all instances of `file://$(pwd)` with $PWD_URL across the test script, and let's simplify the `ENCODED_URL` constructions in the `sendFields` and `checkFields` tests to use $ENCODED_PWD_URL directly. Signed-off-by: Christian Couder <chriscool@tuxfamily.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 1fb0818 commit 7cb0268

1 file changed

Lines changed: 32 additions & 23 deletions

File tree

t/t5710-promisor-remote-capability.sh

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@ copy_to_lop () {
7676
cp "$path" "$path2"
7777
}
7878

79+
# On Windows, 'pwd' returns a path like 'D:/foo/bar'. Prepend '/' to turn
80+
# it into '/D:/foo/bar', which is what git expects in file:// URLs on Windows.
81+
# On Unix, the path already starts with '/', so this is a no-op.
82+
pwd_path=$(pwd)
83+
case "$pwd_path" in
84+
[a-zA-Z]:*) pwd_path="/$pwd_path" ;;
85+
esac
86+
PWD_URL="file://$pwd_path"
87+
# Same as PWD_URL but with spaces percent-encoded, for use in URL patterns.
88+
ENCODED_PWD_URL="file://$(echo "$pwd_path" | sed "s/ /%20/g")"
89+
7990
test_expect_success "setup for testing promisor remote advertisement" '
8091
# Create another bare repo called "lop" (for Large Object Promisor)
8192
git init --bare lop &&
@@ -88,7 +99,7 @@ test_expect_success "setup for testing promisor remote advertisement" '
8899
initialize_server 1 "$oid" &&
89100
90101
# Configure lop as promisor remote for server
91-
git -C server remote add lop "file://$(pwd)/lop" &&
102+
git -C server remote add lop "$PWD_URL/lop" &&
92103
git -C server config remote.lop.promisor true &&
93104
94105
git -C lop config uploadpack.allowFilter true &&
@@ -104,7 +115,7 @@ test_expect_success "clone with promisor.advertise set to 'true'" '
104115
# Clone from server to create a client
105116
GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
106117
-c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
107-
-c remote.lop.url="file://$(pwd)/lop" \
118+
-c remote.lop.url="$PWD_URL/lop" \
108119
-c promisor.acceptfromserver=All \
109120
--no-local --filter="blob:limit=5k" server client &&
110121
@@ -119,7 +130,7 @@ test_expect_success "clone with promisor.advertise set to 'false'" '
119130
# Clone from server to create a client
120131
GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
121132
-c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
122-
-c remote.lop.url="file://$(pwd)/lop" \
133+
-c remote.lop.url="$PWD_URL/lop" \
123134
-c promisor.acceptfromserver=All \
124135
--no-local --filter="blob:limit=5k" server client &&
125136
@@ -137,7 +148,7 @@ test_expect_success "clone with promisor.acceptfromserver set to 'None'" '
137148
# Clone from server to create a client
138149
GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
139150
-c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
140-
-c remote.lop.url="file://$(pwd)/lop" \
151+
-c remote.lop.url="$PWD_URL/lop" \
141152
-c promisor.acceptfromserver=None \
142153
--no-local --filter="blob:limit=5k" server client &&
143154
@@ -156,8 +167,8 @@ test_expect_success "init + fetch with promisor.advertise set to 'true'" '
156167
git -C client init &&
157168
git -C client config remote.lop.promisor true &&
158169
git -C client config remote.lop.fetch "+refs/heads/*:refs/remotes/lop/*" &&
159-
git -C client config remote.lop.url "file://$(pwd)/lop" &&
160-
git -C client config remote.server.url "file://$(pwd)/server" &&
170+
git -C client config remote.lop.url "$PWD_URL/lop" &&
171+
git -C client config remote.server.url "$PWD_URL/server" &&
161172
git -C client config remote.server.fetch "+refs/heads/*:refs/remotes/server/*" &&
162173
git -C client config promisor.acceptfromserver All &&
163174
GIT_NO_LAZY_FETCH=0 git -C client fetch --filter="blob:limit=5k" server &&
@@ -242,7 +253,7 @@ test_expect_success "clone with promisor.acceptfromserver set to 'KnownName'" '
242253
# Clone from server to create a client
243254
GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
244255
-c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
245-
-c remote.lop.url="file://$(pwd)/lop" \
256+
-c remote.lop.url="$PWD_URL/lop" \
246257
-c promisor.acceptfromserver=KnownName \
247258
--no-local --filter="blob:limit=5k" server client &&
248259
@@ -257,7 +268,7 @@ test_expect_success "clone with 'KnownName' and different remote names" '
257268
# Clone from server to create a client
258269
GIT_NO_LAZY_FETCH=0 git clone -c remote.serverTwo.promisor=true \
259270
-c remote.serverTwo.fetch="+refs/heads/*:refs/remotes/lop/*" \
260-
-c remote.serverTwo.url="file://$(pwd)/lop" \
271+
-c remote.serverTwo.url="$PWD_URL/lop" \
261272
-c promisor.acceptfromserver=KnownName \
262273
--no-local --filter="blob:limit=5k" server client &&
263274
@@ -294,7 +305,7 @@ test_expect_success "clone with promisor.acceptfromserver set to 'KnownUrl'" '
294305
# Clone from server to create a client
295306
GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
296307
-c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
297-
-c remote.lop.url="file://$(pwd)/lop" \
308+
-c remote.lop.url="$PWD_URL/lop" \
298309
-c promisor.acceptfromserver=KnownUrl \
299310
--no-local --filter="blob:limit=5k" server client &&
300311
@@ -311,7 +322,7 @@ test_expect_success "clone with 'KnownUrl' and different remote urls" '
311322
# Clone from server to create a client
312323
GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
313324
-c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
314-
-c remote.lop.url="file://$(pwd)/serverTwo" \
325+
-c remote.lop.url="$PWD_URL/serverTwo" \
315326
-c promisor.acceptfromserver=KnownUrl \
316327
--no-local --filter="blob:limit=5k" server client &&
317328
@@ -326,7 +337,7 @@ test_expect_success "clone with 'KnownUrl' and url not configured on the server"
326337
git -C server config promisor.advertise true &&
327338
test_when_finished "rm -rf client" &&
328339
329-
test_when_finished "git -C server config set remote.lop.url \"file://$(pwd)/lop\"" &&
340+
test_when_finished "git -C server config set remote.lop.url \"$PWD_URL/lop\"" &&
330341
git -C server config unset remote.lop.url &&
331342
332343
# Clone from server to create a client
@@ -335,7 +346,7 @@ test_expect_success "clone with 'KnownUrl' and url not configured on the server"
335346
# missing, so the remote name will be used instead which will fail.
336347
test_must_fail env GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
337348
-c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
338-
-c remote.lop.url="file://$(pwd)/lop" \
349+
-c remote.lop.url="$PWD_URL/lop" \
339350
-c promisor.acceptfromserver=KnownUrl \
340351
--no-local --filter="blob:limit=5k" server client &&
341352
@@ -347,7 +358,7 @@ test_expect_success "clone with 'KnownUrl' and empty url, so not advertised" '
347358
git -C server config promisor.advertise true &&
348359
test_when_finished "rm -rf client" &&
349360
350-
test_when_finished "git -C server config set remote.lop.url \"file://$(pwd)/lop\"" &&
361+
test_when_finished "git -C server config set remote.lop.url \"$PWD_URL/lop\"" &&
351362
git -C server config set remote.lop.url "" &&
352363
353364
# Clone from server to create a client
@@ -356,7 +367,7 @@ test_expect_success "clone with 'KnownUrl' and empty url, so not advertised" '
356367
# so the remote name will be used instead which will fail.
357368
test_must_fail env GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
358369
-c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
359-
-c remote.lop.url="file://$(pwd)/lop" \
370+
-c remote.lop.url="$PWD_URL/lop" \
360371
-c promisor.acceptfromserver=KnownUrl \
361372
--no-local --filter="blob:limit=5k" server client &&
362373
@@ -380,13 +391,12 @@ test_expect_success "clone with promisor.sendFields" '
380391
GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \
381392
-c remote.lop.promisor=true \
382393
-c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
383-
-c remote.lop.url="file://$(pwd)/lop" \
394+
-c remote.lop.url="$PWD_URL/lop" \
384395
-c promisor.acceptfromserver=All \
385396
--no-local --filter="blob:limit=5k" server client &&
386397
387398
# Check that fields are properly transmitted
388-
ENCODED_URL=$(echo "file://$(pwd)/lop" | sed -e "s/ /%20/g") &&
389-
PR1="name=lop,url=$ENCODED_URL,partialCloneFilter=blob:none" &&
399+
PR1="name=lop,url=$ENCODED_PWD_URL/lop,partialCloneFilter=blob:none" &&
390400
PR2="name=otherLop,url=https://invalid.invalid,partialCloneFilter=blob:limit=10k,token=fooBar" &&
391401
test_grep "clone< promisor-remote=$PR1;$PR2" trace &&
392402
test_grep "clone> promisor-remote=lop;otherLop" trace &&
@@ -411,15 +421,14 @@ test_expect_success "clone with promisor.checkFields" '
411421
GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \
412422
-c remote.lop.promisor=true \
413423
-c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
414-
-c remote.lop.url="file://$(pwd)/lop" \
424+
-c remote.lop.url="$PWD_URL/lop" \
415425
-c remote.lop.partialCloneFilter="blob:none" \
416426
-c promisor.acceptfromserver=All \
417427
-c promisor.checkFields=partialcloneFilter \
418428
--no-local --filter="blob:limit=5k" server client &&
419429
420430
# Check that fields are properly transmitted
421-
ENCODED_URL=$(echo "file://$(pwd)/lop" | sed -e "s/ /%20/g") &&
422-
PR1="name=lop,url=$ENCODED_URL,partialCloneFilter=blob:none" &&
431+
PR1="name=lop,url=$ENCODED_PWD_URL/lop,partialCloneFilter=blob:none" &&
423432
PR2="name=otherLop,url=https://invalid.invalid,partialCloneFilter=blob:limit=10k,token=fooBar" &&
424433
test_grep "clone< promisor-remote=$PR1;$PR2" trace &&
425434
test_grep "clone> promisor-remote=lop" trace &&
@@ -449,7 +458,7 @@ test_expect_success "clone with promisor.storeFields=partialCloneFilter" '
449458
GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \
450459
-c remote.lop.promisor=true \
451460
-c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
452-
-c remote.lop.url="file://$(pwd)/lop" \
461+
-c remote.lop.url="$PWD_URL/lop" \
453462
-c remote.lop.token="fooYYY" \
454463
-c remote.lop.partialCloneFilter="blob:none" \
455464
-c promisor.acceptfromserver=All \
@@ -501,7 +510,7 @@ test_expect_success "clone and fetch with --filter=auto" '
501510
502511
GIT_TRACE_PACKET="$(pwd)/trace" GIT_NO_LAZY_FETCH=0 git clone \
503512
-c remote.lop.promisor=true \
504-
-c remote.lop.url="file://$(pwd)/lop" \
513+
-c remote.lop.url="$PWD_URL/lop" \
505514
-c promisor.acceptfromserver=All \
506515
--no-local --filter=auto server client 2>err &&
507516
@@ -558,7 +567,7 @@ test_expect_success "clone with promisor.advertise set to 'true' but don't delet
558567
# Clone from server to create a client
559568
GIT_NO_LAZY_FETCH=0 git clone -c remote.lop.promisor=true \
560569
-c remote.lop.fetch="+refs/heads/*:refs/remotes/lop/*" \
561-
-c remote.lop.url="file://$(pwd)/lop" \
570+
-c remote.lop.url="$PWD_URL/lop" \
562571
-c promisor.acceptfromserver=All \
563572
--no-local --filter="blob:limit=5k" server client &&
564573

0 commit comments

Comments
 (0)