Skip to content

Commit d2588c2

Browse files
committed
Merge branch 'unc-paths'
A bug fix for pushing to shared folders (fixing a regression introduced into v2.11.0). Signed-off-by: Johannes Schindelin <[email protected]>
2 parents 66d27de + 2174823 commit d2588c2

File tree

2 files changed

+60
-9
lines changed

2 files changed

+60
-9
lines changed

path.c

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -996,7 +996,7 @@ const char *remove_leading_path(const char *in, const char *prefix)
996996
*
997997
* Performs the following normalizations on src, storing the result in dst:
998998
* - Ensures that components are separated by '/' (Windows only)
999-
* - Squashes sequences of '/'.
999+
* - Squashes sequences of '/' except "//server/share" on Windows
10001000
* - Removes "." components.
10011001
* - Removes ".." components, and the components the precede them.
10021002
* Returns failure (non-zero) if a ".." component appears as first path
@@ -1019,17 +1019,22 @@ const char *remove_leading_path(const char *in, const char *prefix)
10191019
int normalize_path_copy_len(char *dst, const char *src, int *prefix_len)
10201020
{
10211021
char *dst0;
1022-
int i = has_unc_prefix(src);
1022+
const char *end;
10231023

1024-
for (i = i ? i : has_dos_drive_prefix(src); i > 0; i--)
1025-
*dst++ = *src++;
1024+
/*
1025+
* Copy initial part of absolute path: "/", "C:/", "//server/share/".
1026+
*/
1027+
end = src + offset_1st_component(src);
1028+
while (src < end) {
1029+
char c = *src++;
1030+
if (is_dir_sep(c))
1031+
c = '/';
1032+
*dst++ = c;
1033+
}
10261034
dst0 = dst;
10271035

1028-
if (is_dir_sep(*src)) {
1029-
*dst++ = '/';
1030-
while (is_dir_sep(*src))
1031-
src++;
1032-
}
1036+
while (is_dir_sep(*src))
1037+
src++;
10331038

10341039
for (;;) {
10351040
char c = *src;

t/t5580-clone-push-unc.sh

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/sh
2+
3+
test_description='various UNC path tests (Windows-only)'
4+
. ./test-lib.sh
5+
6+
if ! test_have_prereq MINGW; then
7+
skip_all='skipping UNC path tests, requires Windows'
8+
test_done
9+
fi
10+
11+
UNCPATH="$(pwd)"
12+
case "$UNCPATH" in
13+
[A-Z]:*)
14+
# Use administrative share e.g. \\localhost\C$\git-sdk-64\usr\src\git
15+
# (we use forward slashes here because MSYS2 and Git accept them, and
16+
# they are easier on the eyes)
17+
UNCPATH="//localhost/${UNCPATH%%:*}\$/${UNCPATH#?:}"
18+
test -d "$UNCPATH" || {
19+
skip_all='could not access administrative share; skipping'
20+
test_done
21+
}
22+
;;
23+
*)
24+
skip_all='skipping UNC path tests, cannot determine current path as UNC'
25+
test_done
26+
;;
27+
esac
28+
29+
test_expect_success setup '
30+
test_commit initial
31+
'
32+
33+
test_expect_success clone '
34+
git clone "file://$UNCPATH" clone
35+
'
36+
37+
test_expect_success push '
38+
(
39+
cd clone &&
40+
git checkout -b to-push &&
41+
test_commit to-push &&
42+
git push origin HEAD
43+
)
44+
'
45+
46+
test_done

0 commit comments

Comments
 (0)