Skip to content

Commit 52f6893

Browse files
committed
Merge branch 'jk/guess-repo-name-regression-fix' into maint
"git clone $URL" in recent releases of Git contains a regression in the code that invents a new repository name incorrectly based on the $URL. This has been corrected. * jk/guess-repo-name-regression-fix: clone: use computed length in guess_dir_name clone: add tests for output directory
2 parents 84deb3e + db2e220 commit 52f6893

File tree

2 files changed

+108
-1
lines changed

2 files changed

+108
-1
lines changed

builtin/clone.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,8 @@ static char *guess_dir_name(const char *repo, int is_bundle, int is_bare)
174174
/*
175175
* Strip .{bundle,git}.
176176
*/
177-
strip_suffix(start, is_bundle ? ".bundle" : ".git" , &len);
177+
len = end - start;
178+
strip_suffix_mem(start, &len, is_bundle ? ".bundle" : ".git");
178179

179180
if (is_bare)
180181
dir = xstrfmt("%.*s.git", (int)len, start);

t/t5603-clone-dirname.sh

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
#!/bin/sh
2+
3+
test_description='check output directory names used by git-clone'
4+
. ./test-lib.sh
5+
6+
# we use a fake ssh wrapper that ignores the arguments
7+
# entirely; we really only care that we get _some_ repo,
8+
# as the real test is what clone does on the local side
9+
test_expect_success 'setup ssh wrapper' '
10+
write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF &&
11+
git upload-pack "$TRASH_DIRECTORY"
12+
EOF
13+
GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" &&
14+
export GIT_SSH &&
15+
export TRASH_DIRECTORY
16+
'
17+
18+
# make sure that cloning $1 results in local directory $2
19+
test_clone_dir () {
20+
url=$1; shift
21+
dir=$1; shift
22+
expect=success
23+
bare=non-bare
24+
clone_opts=
25+
for i in "$@"
26+
do
27+
case "$i" in
28+
fail)
29+
expect=failure
30+
;;
31+
bare)
32+
bare=bare
33+
clone_opts=--bare
34+
;;
35+
esac
36+
done
37+
test_expect_$expect "clone of $url goes to $dir ($bare)" "
38+
rm -rf $dir &&
39+
git clone $clone_opts $url &&
40+
test_path_is_dir $dir
41+
"
42+
}
43+
44+
# basic syntax with bare and non-bare variants
45+
test_clone_dir host:foo foo
46+
test_clone_dir host:foo foo.git bare
47+
test_clone_dir host:foo.git foo
48+
test_clone_dir host:foo.git foo.git bare
49+
test_clone_dir host:foo/.git foo
50+
test_clone_dir host:foo/.git foo.git bare
51+
52+
# similar, but using ssh URL rather than host:path syntax
53+
test_clone_dir ssh://host/foo foo
54+
test_clone_dir ssh://host/foo foo.git bare
55+
test_clone_dir ssh://host/foo.git foo
56+
test_clone_dir ssh://host/foo.git foo.git bare
57+
test_clone_dir ssh://host/foo/.git foo
58+
test_clone_dir ssh://host/foo/.git foo.git bare
59+
60+
# we should remove trailing slashes and .git suffixes
61+
test_clone_dir ssh://host/foo/ foo
62+
test_clone_dir ssh://host/foo/// foo
63+
test_clone_dir ssh://host/foo/.git/ foo
64+
test_clone_dir ssh://host/foo.git/ foo
65+
test_clone_dir ssh://host/foo.git/// foo
66+
test_clone_dir ssh://host/foo///.git/ foo
67+
test_clone_dir ssh://host/foo/.git/// foo
68+
69+
test_clone_dir host:foo/ foo
70+
test_clone_dir host:foo/// foo
71+
test_clone_dir host:foo.git/ foo
72+
test_clone_dir host:foo/.git/ foo
73+
test_clone_dir host:foo.git/// foo
74+
test_clone_dir host:foo///.git/ foo
75+
test_clone_dir host:foo/.git/// foo
76+
77+
# omitting the path should default to the hostname
78+
test_clone_dir ssh://host/ host
79+
test_clone_dir ssh://host:1234/ host fail
80+
test_clone_dir ssh://user@host/ host fail
81+
test_clone_dir host:/ host fail
82+
83+
# auth materials should be redacted
84+
test_clone_dir ssh://user:password@host/ host fail
85+
test_clone_dir ssh://user:password@host:1234/ host fail
86+
test_clone_dir ssh://user:passw@rd@host:1234/ host fail
87+
test_clone_dir user@host:/ host fail
88+
test_clone_dir user:password@host:/ host fail
89+
test_clone_dir user:passw@rd@host:/ host fail
90+
91+
# auth-like material should not be dropped
92+
test_clone_dir ssh://host/foo@bar foo@bar
93+
test_clone_dir ssh://host/[email protected] foo@bar
94+
test_clone_dir ssh://user:password@host/foo@bar foo@bar
95+
test_clone_dir ssh://user:passw@rd@host/[email protected] foo@bar
96+
97+
test_clone_dir host:/foo@bar foo@bar
98+
test_clone_dir host:/[email protected] foo@bar
99+
test_clone_dir user:password@host:/foo@bar foo@bar
100+
test_clone_dir user:passw@rd@host:/[email protected] foo@bar
101+
102+
# trailing port-like numbers should not be stripped for paths
103+
test_clone_dir ssh://user:password@host/test:1234 1234
104+
test_clone_dir ssh://user:password@host/test:1234.git 1234
105+
106+
test_done

0 commit comments

Comments
 (0)