2015-08-10 15:48:21 +00:00
|
|
|
#!/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
|
clone: use computed length in guess_dir_name
Commit 7e837c6 (clone: simplify string handling in
guess_dir_name(), 2015-07-09) changed clone to use
strip_suffix instead of hand-rolled pointer manipulation.
However, strip_suffix will strip from the end of a
NUL-terminated string, and we may have already stripped some
characters (like directory separators, or "/.git"). This
leads to commands like:
git clone host:foo.git/
failing to strip the ".git".
We must instead convert our pointer arithmetic into a
computed length and feed that to strip_suffix_mem, which will
then reduce the length further for us.
It would be nicer if we could drop the pointer manipulation
entirely, and just continually strip using strip_suffix. But
that doesn't quite work for two reasons:
1. The early suffixes we're stripping are not constant; we
need to look for is_dir_sep, which could be one of
several characters.
2. Mid-way through the stripping we compute the pointer
"start", which shows us the beginning of the pathname.
Which really give us two lengths to work with: the
offset from the start of the string, and from the start
of the path. By using pointers for the early part, we
can just compute the length from "start" when we need
it.
Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 15:48:22 +00:00
|
|
|
test_clone_dir host:foo/.git foo.git bare
|
2015-08-10 15:48:21 +00:00
|
|
|
|
|
|
|
# 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
|
clone: use computed length in guess_dir_name
Commit 7e837c6 (clone: simplify string handling in
guess_dir_name(), 2015-07-09) changed clone to use
strip_suffix instead of hand-rolled pointer manipulation.
However, strip_suffix will strip from the end of a
NUL-terminated string, and we may have already stripped some
characters (like directory separators, or "/.git"). This
leads to commands like:
git clone host:foo.git/
failing to strip the ".git".
We must instead convert our pointer arithmetic into a
computed length and feed that to strip_suffix_mem, which will
then reduce the length further for us.
It would be nicer if we could drop the pointer manipulation
entirely, and just continually strip using strip_suffix. But
that doesn't quite work for two reasons:
1. The early suffixes we're stripping are not constant; we
need to look for is_dir_sep, which could be one of
several characters.
2. Mid-way through the stripping we compute the pointer
"start", which shows us the beginning of the pathname.
Which really give us two lengths to work with: the
offset from the start of the string, and from the start
of the path. By using pointers for the early part, we
can just compute the length from "start" when we need
it.
Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 15:48:22 +00:00
|
|
|
test_clone_dir ssh://host/foo/.git foo.git bare
|
2015-08-10 15:48:21 +00:00
|
|
|
|
|
|
|
# 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
|
clone: use computed length in guess_dir_name
Commit 7e837c6 (clone: simplify string handling in
guess_dir_name(), 2015-07-09) changed clone to use
strip_suffix instead of hand-rolled pointer manipulation.
However, strip_suffix will strip from the end of a
NUL-terminated string, and we may have already stripped some
characters (like directory separators, or "/.git"). This
leads to commands like:
git clone host:foo.git/
failing to strip the ".git".
We must instead convert our pointer arithmetic into a
computed length and feed that to strip_suffix_mem, which will
then reduce the length further for us.
It would be nicer if we could drop the pointer manipulation
entirely, and just continually strip using strip_suffix. But
that doesn't quite work for two reasons:
1. The early suffixes we're stripping are not constant; we
need to look for is_dir_sep, which could be one of
several characters.
2. Mid-way through the stripping we compute the pointer
"start", which shows us the beginning of the pathname.
Which really give us two lengths to work with: the
offset from the start of the string, and from the start
of the path. By using pointers for the early part, we
can just compute the length from "start" when we need
it.
Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 15:48:22 +00:00
|
|
|
test_clone_dir ssh://host/foo.git/ foo
|
|
|
|
test_clone_dir ssh://host/foo.git/// foo
|
2015-08-10 15:48:21 +00:00
|
|
|
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
|
clone: use computed length in guess_dir_name
Commit 7e837c6 (clone: simplify string handling in
guess_dir_name(), 2015-07-09) changed clone to use
strip_suffix instead of hand-rolled pointer manipulation.
However, strip_suffix will strip from the end of a
NUL-terminated string, and we may have already stripped some
characters (like directory separators, or "/.git"). This
leads to commands like:
git clone host:foo.git/
failing to strip the ".git".
We must instead convert our pointer arithmetic into a
computed length and feed that to strip_suffix_mem, which will
then reduce the length further for us.
It would be nicer if we could drop the pointer manipulation
entirely, and just continually strip using strip_suffix. But
that doesn't quite work for two reasons:
1. The early suffixes we're stripping are not constant; we
need to look for is_dir_sep, which could be one of
several characters.
2. Mid-way through the stripping we compute the pointer
"start", which shows us the beginning of the pathname.
Which really give us two lengths to work with: the
offset from the start of the string, and from the start
of the path. By using pointers for the early part, we
can just compute the length from "start" when we need
it.
Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 15:48:22 +00:00
|
|
|
test_clone_dir host:foo.git/ foo
|
2015-08-10 15:48:21 +00:00
|
|
|
test_clone_dir host:foo/.git/ foo
|
clone: use computed length in guess_dir_name
Commit 7e837c6 (clone: simplify string handling in
guess_dir_name(), 2015-07-09) changed clone to use
strip_suffix instead of hand-rolled pointer manipulation.
However, strip_suffix will strip from the end of a
NUL-terminated string, and we may have already stripped some
characters (like directory separators, or "/.git"). This
leads to commands like:
git clone host:foo.git/
failing to strip the ".git".
We must instead convert our pointer arithmetic into a
computed length and feed that to strip_suffix_mem, which will
then reduce the length further for us.
It would be nicer if we could drop the pointer manipulation
entirely, and just continually strip using strip_suffix. But
that doesn't quite work for two reasons:
1. The early suffixes we're stripping are not constant; we
need to look for is_dir_sep, which could be one of
several characters.
2. Mid-way through the stripping we compute the pointer
"start", which shows us the beginning of the pathname.
Which really give us two lengths to work with: the
offset from the start of the string, and from the start
of the path. By using pointers for the early part, we
can just compute the length from "start" when we need
it.
Signed-off-by: Jeff King <peff@peff.net>
Acked-by: Sebastian Schuberth <sschuberth@gmail.com>
Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2015-08-10 15:48:22 +00:00
|
|
|
test_clone_dir host:foo.git/// foo
|
2015-08-10 15:48:21 +00:00
|
|
|
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
|
2015-08-10 15:48:24 +00:00
|
|
|
test_clone_dir ssh://host:1234/ host
|
2015-08-10 15:48:23 +00:00
|
|
|
test_clone_dir ssh://user@host/ host
|
2015-08-10 15:48:24 +00:00
|
|
|
test_clone_dir host:/ host
|
2015-08-10 15:48:21 +00:00
|
|
|
|
|
|
|
# auth materials should be redacted
|
2015-08-10 15:48:23 +00:00
|
|
|
test_clone_dir ssh://user:password@host/ host
|
2015-08-10 15:48:24 +00:00
|
|
|
test_clone_dir ssh://user:password@host:1234/ host
|
|
|
|
test_clone_dir ssh://user:passw@rd@host:1234/ host
|
|
|
|
test_clone_dir user@host:/ host
|
|
|
|
test_clone_dir user:password@host:/ host
|
|
|
|
test_clone_dir user:passw@rd@host:/ host
|
2015-08-10 15:48:21 +00:00
|
|
|
|
|
|
|
# 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
|