-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
clone: add tests for output directory
When we run "git clone $url", clone guesses from the $url what to name the local output directory. We don't have any test coverage of this, so let's add some basic tests. This reveals a few problems: - cloning "foo.git/" does not properly remove the ".git"; this is a recent regression from 7e837c6 (clone: simplify string handling in guess_dir_name(), 2015-07-09) - likewise, cloning foo/.git does not seem to handle the bare case (we should end up in foo.git, but we try to use foo/.git on the local end), which also comes from 7e837c6. - cloning the root is not very smart about URL parsing, and usernames and port numbers may end up in the directory name All of these tests are marked as failures. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
- Loading branch information
Jeff King
authored and
Junio C Hamano
committed
Aug 10, 2015
1 parent
7e837c6
commit d6a31e0
Showing
1 changed file
with
106 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
#!/bin/sh | ||
|
||
test_description='check output directory names used by git-clone' | ||
. ./test-lib.sh | ||
|
||
# we use a fake ssh wrapper that ignores the arguments | ||
# entirely; we really only care that we get _some_ repo, | ||
# as the real test is what clone does on the local side | ||
test_expect_success 'setup ssh wrapper' ' | ||
write_script "$TRASH_DIRECTORY/ssh-wrapper" <<-\EOF && | ||
git upload-pack "$TRASH_DIRECTORY" | ||
EOF | ||
GIT_SSH="$TRASH_DIRECTORY/ssh-wrapper" && | ||
export GIT_SSH && | ||
export TRASH_DIRECTORY | ||
' | ||
|
||
# make sure that cloning $1 results in local directory $2 | ||
test_clone_dir () { | ||
url=$1; shift | ||
dir=$1; shift | ||
expect=success | ||
bare=non-bare | ||
clone_opts= | ||
for i in "$@" | ||
do | ||
case "$i" in | ||
fail) | ||
expect=failure | ||
;; | ||
bare) | ||
bare=bare | ||
clone_opts=--bare | ||
;; | ||
esac | ||
done | ||
test_expect_$expect "clone of $url goes to $dir ($bare)" " | ||
rm -rf $dir && | ||
git clone $clone_opts $url && | ||
test_path_is_dir $dir | ||
" | ||
} | ||
|
||
# basic syntax with bare and non-bare variants | ||
test_clone_dir host:foo foo | ||
test_clone_dir host:foo foo.git bare | ||
test_clone_dir host:foo.git foo | ||
test_clone_dir host:foo.git foo.git bare | ||
test_clone_dir host:foo/.git foo | ||
test_clone_dir host:foo/.git foo.git bare fail | ||
|
||
# similar, but using ssh URL rather than host:path syntax | ||
test_clone_dir ssh://host/foo foo | ||
test_clone_dir ssh://host/foo foo.git bare | ||
test_clone_dir ssh://host/foo.git foo | ||
test_clone_dir ssh://host/foo.git foo.git bare | ||
test_clone_dir ssh://host/foo/.git foo | ||
test_clone_dir ssh://host/foo/.git foo.git bare fail | ||
|
||
# we should remove trailing slashes and .git suffixes | ||
test_clone_dir ssh://host/foo/ foo | ||
test_clone_dir ssh://host/foo/// foo | ||
test_clone_dir ssh://host/foo/.git/ foo | ||
test_clone_dir ssh://host/foo.git/ foo fail | ||
test_clone_dir ssh://host/foo.git/// foo fail | ||
test_clone_dir ssh://host/foo///.git/ foo | ||
test_clone_dir ssh://host/foo/.git/// foo | ||
|
||
test_clone_dir host:foo/ foo | ||
test_clone_dir host:foo/// foo | ||
test_clone_dir host:foo.git/ foo fail | ||
test_clone_dir host:foo/.git/ foo | ||
test_clone_dir host:foo.git/// foo fail | ||
test_clone_dir host:foo///.git/ foo | ||
test_clone_dir host:foo/.git/// foo | ||
|
||
# omitting the path should default to the hostname | ||
test_clone_dir ssh://host/ host | ||
test_clone_dir ssh://host:1234/ host fail | ||
test_clone_dir ssh://user@host/ host fail | ||
test_clone_dir host:/ host fail | ||
|
||
# auth materials should be redacted | ||
test_clone_dir ssh://user:password@host/ host fail | ||
test_clone_dir ssh://user:password@host:1234/ host fail | ||
test_clone_dir ssh://user:passw@rd@host:1234/ host fail | ||
test_clone_dir user@host:/ host fail | ||
test_clone_dir user:password@host:/ host fail | ||
test_clone_dir user:passw@rd@host:/ host fail | ||
|
||
# auth-like material should not be dropped | ||
test_clone_dir ssh://host/foo@bar foo@bar | ||
test_clone_dir ssh://host/foo@bar.git foo@bar | ||
test_clone_dir ssh://user:password@host/foo@bar foo@bar | ||
test_clone_dir ssh://user:passw@rd@host/foo@bar.git foo@bar | ||
|
||
test_clone_dir host:/foo@bar foo@bar | ||
test_clone_dir host:/foo@bar.git foo@bar | ||
test_clone_dir user:password@host:/foo@bar foo@bar | ||
test_clone_dir user:passw@rd@host:/foo@bar.git foo@bar | ||
|
||
# trailing port-like numbers should not be stripped for paths | ||
test_clone_dir ssh://user:password@host/test:1234 1234 | ||
test_clone_dir ssh://user:password@host/test:1234.git 1234 | ||
|
||
test_done |