2008-05-20 08:48:54 +02:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Copyright (c) 2008 David Reiss
|
|
|
|
#
|
|
|
|
|
|
|
|
test_description='Test various path utilities'
|
|
|
|
|
|
|
|
. ./test-lib.sh
|
|
|
|
|
2009-03-11 22:15:10 +01:00
|
|
|
norm_path() {
|
2018-03-24 08:44:49 +01:00
|
|
|
expected=$(test-tool path-utils print_path "$2")
|
2009-03-11 22:15:10 +01:00
|
|
|
test_expect_success $3 "normalize path: $1 => $2" \
|
2018-03-24 08:44:49 +01:00
|
|
|
"test \"\$(test-tool path-utils normalize_path_copy '$1')\" = '$expected'"
|
2008-05-20 08:48:54 +02:00
|
|
|
}
|
|
|
|
|
2013-06-25 17:53:42 +02:00
|
|
|
relative_path() {
|
2018-03-24 08:44:49 +01:00
|
|
|
expected=$(test-tool path-utils print_path "$3")
|
2013-06-25 17:53:42 +02:00
|
|
|
test_expect_success $4 "relative path: $1 $2 => $3" \
|
2018-03-24 08:44:49 +01:00
|
|
|
"test \"\$(test-tool path-utils relative_path '$1' '$2')\" = '$expected'"
|
2013-06-25 17:53:42 +02:00
|
|
|
}
|
|
|
|
|
2016-04-16 02:50:12 +02:00
|
|
|
test_submodule_relative_url() {
|
|
|
|
test_expect_success "test_submodule_relative_url: $1 $2 $3 => $4" "
|
|
|
|
actual=\$(git submodule--helper resolve-relative-url-test '$1' '$2' '$3') &&
|
|
|
|
test \"\$actual\" = '$4'
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
2014-11-30 09:24:31 +01:00
|
|
|
test_git_path() {
|
|
|
|
test_expect_success "git-path $1 $2 => $3" "
|
|
|
|
$1 git rev-parse --git-path $2 >actual &&
|
|
|
|
echo $3 >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
2009-03-11 22:15:10 +01:00
|
|
|
# On Windows, we are using MSYS's bash, which mangles the paths.
|
|
|
|
# Absolute paths are anchored at the MSYS installation directory,
|
|
|
|
# which means that the path / accounts for this many characters:
|
2018-03-24 08:44:49 +01:00
|
|
|
rootoff=$(test-tool path-utils normalize_path_copy / | wc -c)
|
2009-03-11 22:15:10 +01:00
|
|
|
# Account for the trailing LF:
|
2009-03-23 07:22:29 +01:00
|
|
|
if test $rootoff = 2; then
|
2009-03-11 22:15:10 +01:00
|
|
|
rootoff= # we are on Unix
|
|
|
|
else
|
|
|
|
rootoff=$(($rootoff-1))
|
mingw: accomodate t0060-path-utils for MSYS2
On Windows, there are no POSIX paths, only Windows ones (an absolute
Windows path looks like "C:\Program Files\Git\ReleaseNotes.html", under
most circumstances, forward slashes are also allowed and synonymous to
backslashes).
So when a POSIX shell (such as MSYS2's Bash, which is used by Git for
Windows to execute all those shell scripts that are part of Git) passes
a POSIX path to test-path-utils.exe (which is not POSIX-aware), the path
is translated into a Windows path. For example, /etc/profile becomes
C:/Program Files/Git/etc/profile.
This path translation poses a problem when passing the root directory as
parameter to test-path-utils.exe, as it is not well defined whether the
translated root directory should end in a slash or not. MSys1 stripped
the trailing slash, but MSYS2 does not.
Originally, the Git for Windows project patched MSYS2's runtime to
accomodate Git's regression test, but we really should do it the other
way round.
To work with both of MSys1's and MSYS2's behaviors, we simply test what
the current system does in the beginning of t0060-path-utils.sh and then
adjust the expected longest ancestor length accordingly.
It looks quite a bit tricky what we actually do in this patch: first, we
adjust the expected length for the trailing slash we did not originally
expect (subtracting one). So far, so good.
But now comes the part where things work in a surprising way: when the
expected length was 0, the prefix to match is the root directory. If the
root directory is converted into a path with a trailing slash, however,
we know that the logic in longest_ancestor_length() cannot match: to
avoid partial matches of the last directory component, it verifies that
the character after the matching prefix is a slash (but because the
slash was part of the matching prefix, the next character cannot be a
slash). So the return value is -1. Alas, this is exactly what the
expected length is after subtracting the value of $rootslash! So we skip
adding the $rootoff value in that case (and only in that case).
Directories other than the root directory are handled fine (as they are
specified without a trailing slash, something not possible for the root
directory, and MSYS2 converts them into Windows paths that also lack
trailing slashes), therefore we do not need any more special handling.
Thanks to Ray Donnelly for his patient help with this issue.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-01-27 17:19:40 +01:00
|
|
|
# In MSYS2, the root directory "/" is translated into a Windows
|
|
|
|
# directory *with* trailing slash. Let's test for that and adjust
|
|
|
|
# our expected longest ancestor length accordingly.
|
2018-03-24 08:44:49 +01:00
|
|
|
case "$(test-tool path-utils print_path /)" in
|
mingw: accomodate t0060-path-utils for MSYS2
On Windows, there are no POSIX paths, only Windows ones (an absolute
Windows path looks like "C:\Program Files\Git\ReleaseNotes.html", under
most circumstances, forward slashes are also allowed and synonymous to
backslashes).
So when a POSIX shell (such as MSYS2's Bash, which is used by Git for
Windows to execute all those shell scripts that are part of Git) passes
a POSIX path to test-path-utils.exe (which is not POSIX-aware), the path
is translated into a Windows path. For example, /etc/profile becomes
C:/Program Files/Git/etc/profile.
This path translation poses a problem when passing the root directory as
parameter to test-path-utils.exe, as it is not well defined whether the
translated root directory should end in a slash or not. MSys1 stripped
the trailing slash, but MSYS2 does not.
Originally, the Git for Windows project patched MSYS2's runtime to
accomodate Git's regression test, but we really should do it the other
way round.
To work with both of MSys1's and MSYS2's behaviors, we simply test what
the current system does in the beginning of t0060-path-utils.sh and then
adjust the expected longest ancestor length accordingly.
It looks quite a bit tricky what we actually do in this patch: first, we
adjust the expected length for the trailing slash we did not originally
expect (subtracting one). So far, so good.
But now comes the part where things work in a surprising way: when the
expected length was 0, the prefix to match is the root directory. If the
root directory is converted into a path with a trailing slash, however,
we know that the logic in longest_ancestor_length() cannot match: to
avoid partial matches of the last directory component, it verifies that
the character after the matching prefix is a slash (but because the
slash was part of the matching prefix, the next character cannot be a
slash). So the return value is -1. Alas, this is exactly what the
expected length is after subtracting the value of $rootslash! So we skip
adding the $rootoff value in that case (and only in that case).
Directories other than the root directory are handled fine (as they are
specified without a trailing slash, something not possible for the root
directory, and MSYS2 converts them into Windows paths that also lack
trailing slashes), therefore we do not need any more special handling.
Thanks to Ray Donnelly for his patient help with this issue.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-01-27 17:19:40 +01:00
|
|
|
*/) rootslash=1;;
|
|
|
|
*) rootslash=0;;
|
|
|
|
esac
|
2009-03-11 22:15:10 +01:00
|
|
|
fi
|
|
|
|
|
2008-05-20 08:49:26 +02:00
|
|
|
ancestor() {
|
2009-03-11 22:15:10 +01:00
|
|
|
# We do some math with the expected ancestor length.
|
|
|
|
expected=$3
|
|
|
|
if test -n "$rootoff" && test "x$expected" != x-1; then
|
mingw: accomodate t0060-path-utils for MSYS2
On Windows, there are no POSIX paths, only Windows ones (an absolute
Windows path looks like "C:\Program Files\Git\ReleaseNotes.html", under
most circumstances, forward slashes are also allowed and synonymous to
backslashes).
So when a POSIX shell (such as MSYS2's Bash, which is used by Git for
Windows to execute all those shell scripts that are part of Git) passes
a POSIX path to test-path-utils.exe (which is not POSIX-aware), the path
is translated into a Windows path. For example, /etc/profile becomes
C:/Program Files/Git/etc/profile.
This path translation poses a problem when passing the root directory as
parameter to test-path-utils.exe, as it is not well defined whether the
translated root directory should end in a slash or not. MSys1 stripped
the trailing slash, but MSYS2 does not.
Originally, the Git for Windows project patched MSYS2's runtime to
accomodate Git's regression test, but we really should do it the other
way round.
To work with both of MSys1's and MSYS2's behaviors, we simply test what
the current system does in the beginning of t0060-path-utils.sh and then
adjust the expected longest ancestor length accordingly.
It looks quite a bit tricky what we actually do in this patch: first, we
adjust the expected length for the trailing slash we did not originally
expect (subtracting one). So far, so good.
But now comes the part where things work in a surprising way: when the
expected length was 0, the prefix to match is the root directory. If the
root directory is converted into a path with a trailing slash, however,
we know that the logic in longest_ancestor_length() cannot match: to
avoid partial matches of the last directory component, it verifies that
the character after the matching prefix is a slash (but because the
slash was part of the matching prefix, the next character cannot be a
slash). So the return value is -1. Alas, this is exactly what the
expected length is after subtracting the value of $rootslash! So we skip
adding the $rootoff value in that case (and only in that case).
Directories other than the root directory are handled fine (as they are
specified without a trailing slash, something not possible for the root
directory, and MSYS2 converts them into Windows paths that also lack
trailing slashes), therefore we do not need any more special handling.
Thanks to Ray Donnelly for his patient help with this issue.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2016-01-27 17:19:40 +01:00
|
|
|
expected=$(($expected-$rootslash))
|
|
|
|
test $expected -lt 0 ||
|
2009-03-11 22:15:10 +01:00
|
|
|
expected=$(($expected+$rootoff))
|
|
|
|
fi
|
|
|
|
test_expect_success "longest ancestor: $1 $2 => $expected" \
|
2018-03-24 08:44:49 +01:00
|
|
|
"actual=\$(test-tool path-utils longest_ancestor_length '$1' '$2') &&
|
2009-03-11 22:15:10 +01:00
|
|
|
test \"\$actual\" = '$expected'"
|
2008-05-20 08:49:26 +02:00
|
|
|
}
|
|
|
|
|
2013-06-25 17:53:57 +02:00
|
|
|
# Some absolute path tests should be skipped on Windows due to path mangling
|
|
|
|
# on POSIX-style absolute paths
|
2009-03-11 22:15:10 +01:00
|
|
|
case $(uname -s) in
|
|
|
|
*MINGW*)
|
|
|
|
;;
|
2017-07-03 16:41:37 +02:00
|
|
|
*CYGWIN*)
|
|
|
|
;;
|
2009-03-11 22:15:10 +01:00
|
|
|
*)
|
|
|
|
test_set_prereq POSIX
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
|
2018-03-24 08:44:49 +01:00
|
|
|
test_expect_success basename 'test-tool path-utils basename'
|
|
|
|
test_expect_success dirname 'test-tool path-utils dirname'
|
2016-01-12 08:57:57 +01:00
|
|
|
|
2009-03-11 22:15:10 +01:00
|
|
|
norm_path "" ""
|
|
|
|
norm_path . ""
|
|
|
|
norm_path ./ ""
|
|
|
|
norm_path ./. ""
|
|
|
|
norm_path ./.. ++failed++
|
|
|
|
norm_path ../. ++failed++
|
|
|
|
norm_path ./../.// ++failed++
|
|
|
|
norm_path dir/.. ""
|
|
|
|
norm_path dir/sub/../.. ""
|
|
|
|
norm_path dir/sub/../../.. ++failed++
|
|
|
|
norm_path dir dir
|
|
|
|
norm_path dir// dir/
|
|
|
|
norm_path ./dir dir
|
|
|
|
norm_path dir/. dir/
|
|
|
|
norm_path dir///./ dir/
|
|
|
|
norm_path dir//sub/.. dir/
|
|
|
|
norm_path dir/sub/../ dir/
|
|
|
|
norm_path dir/sub/../. dir/
|
|
|
|
norm_path dir/s1/../s2/ dir/s2/
|
|
|
|
norm_path d1/s1///s2/..//../s3/ d1/s3/
|
|
|
|
norm_path d1/s1//../s2/../../d2 d2
|
|
|
|
norm_path d1/.../d2 d1/.../d2
|
|
|
|
norm_path d1/..././../d2 d1/d2
|
|
|
|
|
2013-06-25 17:53:57 +02:00
|
|
|
norm_path / /
|
2009-03-11 22:15:10 +01:00
|
|
|
norm_path // / POSIX
|
|
|
|
norm_path /// / POSIX
|
2013-06-25 17:53:57 +02:00
|
|
|
norm_path /. /
|
2009-03-11 22:15:10 +01:00
|
|
|
norm_path /./ / POSIX
|
|
|
|
norm_path /./.. ++failed++ POSIX
|
2013-06-25 17:53:57 +02:00
|
|
|
norm_path /../. ++failed++
|
2009-03-11 22:15:10 +01:00
|
|
|
norm_path /./../.// ++failed++ POSIX
|
|
|
|
norm_path /dir/.. / POSIX
|
|
|
|
norm_path /dir/sub/../.. / POSIX
|
|
|
|
norm_path /dir/sub/../../.. ++failed++ POSIX
|
2013-06-25 17:53:57 +02:00
|
|
|
norm_path /dir /dir
|
|
|
|
norm_path /dir// /dir/
|
|
|
|
norm_path /./dir /dir
|
|
|
|
norm_path /dir/. /dir/
|
|
|
|
norm_path /dir///./ /dir/
|
|
|
|
norm_path /dir//sub/.. /dir/
|
|
|
|
norm_path /dir/sub/../ /dir/
|
2009-03-11 22:15:10 +01:00
|
|
|
norm_path //dir/sub/../. /dir/ POSIX
|
2013-06-25 17:53:57 +02:00
|
|
|
norm_path /dir/s1/../s2/ /dir/s2/
|
|
|
|
norm_path /d1/s1///s2/..//../s3/ /d1/s3/
|
|
|
|
norm_path /d1/s1//../s2/../../d2 /d2
|
|
|
|
norm_path /d1/.../d2 /d1/.../d2
|
|
|
|
norm_path /d1/..././../d2 /d1/d2
|
2008-05-20 08:48:54 +02:00
|
|
|
|
2008-05-20 08:49:26 +02:00
|
|
|
ancestor / / -1
|
|
|
|
ancestor /foo / 0
|
|
|
|
ancestor /foo /fo -1
|
|
|
|
ancestor /foo /foo -1
|
|
|
|
ancestor /foo /bar -1
|
|
|
|
ancestor /foo /foo/bar -1
|
2012-10-28 17:16:25 +01:00
|
|
|
ancestor /foo /foo:/bar -1
|
|
|
|
ancestor /foo /:/foo:/bar 0
|
|
|
|
ancestor /foo /foo:/:/bar 0
|
|
|
|
ancestor /foo /:/bar:/foo 0
|
2008-05-20 08:49:26 +02:00
|
|
|
ancestor /foo/bar / 0
|
|
|
|
ancestor /foo/bar /fo -1
|
|
|
|
ancestor /foo/bar /foo 4
|
|
|
|
ancestor /foo/bar /foo/ba -1
|
|
|
|
ancestor /foo/bar /:/fo 0
|
|
|
|
ancestor /foo/bar /foo:/foo/ba 4
|
|
|
|
ancestor /foo/bar /bar -1
|
2012-10-28 17:16:25 +01:00
|
|
|
ancestor /foo/bar /fo -1
|
|
|
|
ancestor /foo/bar /foo:/bar 4
|
|
|
|
ancestor /foo/bar /:/foo:/bar 4
|
|
|
|
ancestor /foo/bar /foo:/:/bar 4
|
|
|
|
ancestor /foo/bar /:/bar:/fo 0
|
|
|
|
ancestor /foo/bar /:/bar 0
|
|
|
|
ancestor /foo/bar /foo 4
|
|
|
|
ancestor /foo/bar /foo:/bar 4
|
|
|
|
ancestor /foo/bar /bar -1
|
2008-05-20 08:49:26 +02:00
|
|
|
|
2009-02-19 20:10:49 +01:00
|
|
|
test_expect_success 'strip_path_suffix' '
|
2018-03-24 08:44:49 +01:00
|
|
|
test c:/msysgit = $(test-tool path-utils strip_path_suffix \
|
2009-02-19 20:10:49 +01:00
|
|
|
c:/msysgit/libexec//git-core libexec/git-core)
|
|
|
|
'
|
2012-09-07 00:40:57 +02:00
|
|
|
|
2012-09-07 00:40:59 +02:00
|
|
|
test_expect_success 'absolute path rejects the empty string' '
|
2018-03-24 08:44:49 +01:00
|
|
|
test_must_fail test-tool path-utils absolute_path ""
|
2012-09-07 00:40:58 +02:00
|
|
|
'
|
|
|
|
|
2012-09-07 00:41:01 +02:00
|
|
|
test_expect_success 'real path rejects the empty string' '
|
2018-03-24 08:44:49 +01:00
|
|
|
test_must_fail test-tool path-utils real_path ""
|
2012-09-07 00:41:00 +02:00
|
|
|
'
|
|
|
|
|
2012-09-09 17:42:20 +02:00
|
|
|
test_expect_success POSIX 'real path works on absolute paths 1' '
|
2012-09-07 00:41:02 +02:00
|
|
|
nopath="hopefully-absent-path" &&
|
2018-03-24 08:44:49 +01:00
|
|
|
test "/" = "$(test-tool path-utils real_path "/")" &&
|
|
|
|
test "/$nopath" = "$(test-tool path-utils real_path "/$nopath")"
|
2012-09-09 17:42:20 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'real path works on absolute paths 2' '
|
|
|
|
nopath="hopefully-absent-path" &&
|
2012-09-07 00:41:02 +02:00
|
|
|
# Find an existing top-level directory for the remaining tests:
|
|
|
|
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
|
2018-03-24 08:44:49 +01:00
|
|
|
test "$d" = "$(test-tool path-utils real_path "$d")" &&
|
|
|
|
test "$d/$nopath" = "$(test-tool path-utils real_path "$d/$nopath")"
|
2012-09-07 00:41:02 +02:00
|
|
|
'
|
|
|
|
|
2012-09-07 00:41:04 +02:00
|
|
|
test_expect_success POSIX 'real path removes extra leading slashes' '
|
|
|
|
nopath="hopefully-absent-path" &&
|
2018-03-24 08:44:49 +01:00
|
|
|
test "/" = "$(test-tool path-utils real_path "///")" &&
|
|
|
|
test "/$nopath" = "$(test-tool path-utils real_path "///$nopath")" &&
|
2012-09-07 00:41:04 +02:00
|
|
|
# Find an existing top-level directory for the remaining tests:
|
|
|
|
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
|
2018-03-24 08:44:49 +01:00
|
|
|
test "$d" = "$(test-tool path-utils real_path "//$d")" &&
|
|
|
|
test "$d/$nopath" = "$(test-tool path-utils real_path "//$d/$nopath")"
|
2012-09-07 00:41:04 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'real path removes other extra slashes' '
|
|
|
|
nopath="hopefully-absent-path" &&
|
|
|
|
# Find an existing top-level directory for the remaining tests:
|
|
|
|
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
|
2018-03-24 08:44:49 +01:00
|
|
|
test "$d" = "$(test-tool path-utils real_path "$d///")" &&
|
|
|
|
test "$d/$nopath" = "$(test-tool path-utils real_path "$d///$nopath")"
|
2012-09-07 00:41:04 +02:00
|
|
|
'
|
|
|
|
|
2012-09-07 00:41:02 +02:00
|
|
|
test_expect_success SYMLINKS 'real path works on symlinks' '
|
2012-09-07 00:40:57 +02:00
|
|
|
mkdir first &&
|
|
|
|
ln -s ../.git first/.git &&
|
|
|
|
mkdir second &&
|
|
|
|
ln -s ../first second/other &&
|
|
|
|
mkdir third &&
|
|
|
|
dir="$(cd .git; pwd -P)" &&
|
|
|
|
dir2=third/../second/other/.git &&
|
2018-03-24 08:44:49 +01:00
|
|
|
test "$dir" = "$(test-tool path-utils real_path $dir2)" &&
|
2012-09-07 00:40:57 +02:00
|
|
|
file="$dir"/index &&
|
2018-03-24 08:44:49 +01:00
|
|
|
test "$file" = "$(test-tool path-utils real_path $dir2/index)" &&
|
2012-09-07 00:40:57 +02:00
|
|
|
basename=blub &&
|
2018-03-24 08:44:49 +01:00
|
|
|
test "$dir/$basename" = "$(cd .git && test-tool path-utils real_path "$basename")" &&
|
2012-09-07 00:40:57 +02:00
|
|
|
ln -s ../first/file .git/syml &&
|
|
|
|
sym="$(cd first; pwd -P)"/file &&
|
2018-03-24 08:44:49 +01:00
|
|
|
test "$sym" = "$(test-tool path-utils real_path "$dir2/syml")"
|
2012-09-07 00:40:57 +02:00
|
|
|
'
|
|
|
|
|
2014-02-04 15:25:20 +01:00
|
|
|
test_expect_success SYMLINKS 'prefix_path works with absolute paths to work tree symlinks' '
|
2014-02-04 15:25:16 +01:00
|
|
|
ln -s target symlink &&
|
2018-03-24 08:44:49 +01:00
|
|
|
test "$(test-tool path-utils prefix_path prefix "$(pwd)/symlink")" = "symlink"
|
2014-02-04 15:25:16 +01:00
|
|
|
'
|
|
|
|
|
2014-02-04 15:25:17 +01:00
|
|
|
test_expect_success 'prefix_path works with only absolute path to work tree' '
|
|
|
|
echo "" >expected &&
|
2018-03-24 08:44:49 +01:00
|
|
|
test-tool path-utils prefix_path prefix "$(pwd)" >actual &&
|
2014-02-04 15:25:17 +01:00
|
|
|
test_cmp expected actual
|
|
|
|
'
|
|
|
|
|
2014-02-04 15:25:18 +01:00
|
|
|
test_expect_success 'prefix_path rejects absolute path to dir with same beginning as work tree' '
|
2018-03-24 08:44:49 +01:00
|
|
|
test_must_fail test-tool path-utils prefix_path prefix "$(pwd)a"
|
2014-02-04 15:25:18 +01:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success SYMLINKS 'prefix_path works with absolute path to a symlink to work tree having same beginning as work tree' '
|
|
|
|
git init repo &&
|
|
|
|
ln -s repo repolink &&
|
2018-03-24 08:44:49 +01:00
|
|
|
test "a" = "$(cd repo && test-tool path-utils prefix_path prefix "$(pwd)/../repolink/a")"
|
2014-02-04 15:25:18 +01:00
|
|
|
'
|
|
|
|
|
2013-10-14 04:29:38 +02:00
|
|
|
relative_path /foo/a/b/c/ /foo/a/b/ c/
|
|
|
|
relative_path /foo/a/b/c/ /foo/a/b c/
|
|
|
|
relative_path /foo/a//b//c/ ///foo/a/b// c/ POSIX
|
|
|
|
relative_path /foo/a/b /foo/a/b ./
|
|
|
|
relative_path /foo/a/b/ /foo/a/b ./
|
|
|
|
relative_path /foo/a /foo/a/b ../
|
|
|
|
relative_path / /foo/a/b/ ../../../
|
|
|
|
relative_path /foo/a/c /foo/a/b/ ../c
|
|
|
|
relative_path /foo/a/c /foo/a/b ../c
|
|
|
|
relative_path /foo/x/y /foo/a/b/ ../../x/y
|
|
|
|
relative_path /foo/a/b "<empty>" /foo/a/b
|
|
|
|
relative_path /foo/a/b "<null>" /foo/a/b
|
|
|
|
relative_path foo/a/b/c/ foo/a/b/ c/
|
|
|
|
relative_path foo/a/b/c/ foo/a/b c/
|
|
|
|
relative_path foo/a/b//c foo/a//b c
|
|
|
|
relative_path foo/a/b/ foo/a/b/ ./
|
|
|
|
relative_path foo/a/b/ foo/a/b ./
|
|
|
|
relative_path foo/a foo/a/b ../
|
|
|
|
relative_path foo/x/y foo/a/b ../../x/y
|
|
|
|
relative_path foo/a/c foo/a/b ../c
|
2013-10-14 04:29:39 +02:00
|
|
|
relative_path foo/a/b /foo/x/y foo/a/b
|
|
|
|
relative_path /foo/a/b foo/x/y /foo/a/b
|
|
|
|
relative_path d:/a/b D:/a/c ../b MINGW
|
|
|
|
relative_path C:/a/b D:/a/c C:/a/b MINGW
|
2013-10-14 04:29:38 +02:00
|
|
|
relative_path foo/a/b "<empty>" foo/a/b
|
|
|
|
relative_path foo/a/b "<null>" foo/a/b
|
|
|
|
relative_path "<empty>" /foo/a/b ./
|
|
|
|
relative_path "<empty>" "<empty>" ./
|
|
|
|
relative_path "<empty>" "<null>" ./
|
|
|
|
relative_path "<null>" "<empty>" ./
|
|
|
|
relative_path "<null>" "<null>" ./
|
|
|
|
relative_path "<null>" /foo/a/b ./
|
2013-06-25 17:53:42 +02:00
|
|
|
|
2014-11-30 09:24:31 +01:00
|
|
|
test_git_path A=B info/grafts .git/info/grafts
|
|
|
|
test_git_path GIT_GRAFT_FILE=foo info/grafts foo
|
|
|
|
test_git_path GIT_GRAFT_FILE=foo info/////grafts foo
|
|
|
|
test_git_path GIT_INDEX_FILE=foo index foo
|
|
|
|
test_git_path GIT_INDEX_FILE=foo index/foo .git/index/foo
|
|
|
|
test_git_path GIT_INDEX_FILE=foo index2 .git/index2
|
|
|
|
test_expect_success 'setup fake objects directory foo' 'mkdir foo'
|
|
|
|
test_git_path GIT_OBJECT_DIRECTORY=foo objects foo
|
|
|
|
test_git_path GIT_OBJECT_DIRECTORY=foo objects/foo foo/foo
|
|
|
|
test_git_path GIT_OBJECT_DIRECTORY=foo objects2 .git/objects2
|
$GIT_COMMON_DIR: a new environment variable
This variable is intended to support multiple working directories
attached to a repository. Such a repository may have a main working
directory, created by either "git init" or "git clone" and one or more
linked working directories. These working directories and the main
repository share the same repository directory.
In linked working directories, $GIT_COMMON_DIR must be defined to point
to the real repository directory and $GIT_DIR points to an unused
subdirectory inside $GIT_COMMON_DIR. File locations inside the
repository are reorganized from the linked worktree view point:
- worktree-specific such as HEAD, logs/HEAD, index, other top-level
refs and unrecognized files are from $GIT_DIR.
- the rest like objects, refs, info, hooks, packed-refs, shallow...
are from $GIT_COMMON_DIR (except info/sparse-checkout, but that's
a separate patch)
Scripts are supposed to retrieve paths in $GIT_DIR with "git rev-parse
--git-path", which will take care of "$GIT_DIR vs $GIT_COMMON_DIR"
business.
The redirection is done by git_path(), git_pathdup() and
strbuf_git_path(). The selected list of paths goes to $GIT_COMMON_DIR,
not the other way around in case a developer adds a new
worktree-specific file and it's accidentally promoted to be shared
across repositories (this includes unknown files added by third party
commands)
The list of known files that belong to $GIT_DIR are:
ADD_EDIT.patch BISECT_ANCESTORS_OK BISECT_EXPECTED_REV BISECT_LOG
BISECT_NAMES CHERRY_PICK_HEAD COMMIT_MSG FETCH_HEAD HEAD MERGE_HEAD
MERGE_MODE MERGE_RR NOTES_EDITMSG NOTES_MERGE_WORKTREE ORIG_HEAD
REVERT_HEAD SQUASH_MSG TAG_EDITMSG fast_import_crash_* logs/HEAD
next-index-* rebase-apply rebase-merge rsync-refs-* sequencer/*
shallow_*
Path mapping is NOT done for git_path_submodule(). Multi-checkouts are
not supported as submodules.
Helped-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-30 09:24:36 +01:00
|
|
|
test_expect_success 'setup common repository' 'git --git-dir=bar init'
|
|
|
|
test_git_path GIT_COMMON_DIR=bar index .git/index
|
|
|
|
test_git_path GIT_COMMON_DIR=bar HEAD .git/HEAD
|
|
|
|
test_git_path GIT_COMMON_DIR=bar logs/HEAD .git/logs/HEAD
|
2015-09-01 04:13:11 +02:00
|
|
|
test_git_path GIT_COMMON_DIR=bar logs/refs/bisect/foo .git/logs/refs/bisect/foo
|
|
|
|
test_git_path GIT_COMMON_DIR=bar logs/refs/bisec/foo bar/logs/refs/bisec/foo
|
|
|
|
test_git_path GIT_COMMON_DIR=bar logs/refs/bisec bar/logs/refs/bisec
|
|
|
|
test_git_path GIT_COMMON_DIR=bar logs/refs/bisectfoo bar/logs/refs/bisectfoo
|
$GIT_COMMON_DIR: a new environment variable
This variable is intended to support multiple working directories
attached to a repository. Such a repository may have a main working
directory, created by either "git init" or "git clone" and one or more
linked working directories. These working directories and the main
repository share the same repository directory.
In linked working directories, $GIT_COMMON_DIR must be defined to point
to the real repository directory and $GIT_DIR points to an unused
subdirectory inside $GIT_COMMON_DIR. File locations inside the
repository are reorganized from the linked worktree view point:
- worktree-specific such as HEAD, logs/HEAD, index, other top-level
refs and unrecognized files are from $GIT_DIR.
- the rest like objects, refs, info, hooks, packed-refs, shallow...
are from $GIT_COMMON_DIR (except info/sparse-checkout, but that's
a separate patch)
Scripts are supposed to retrieve paths in $GIT_DIR with "git rev-parse
--git-path", which will take care of "$GIT_DIR vs $GIT_COMMON_DIR"
business.
The redirection is done by git_path(), git_pathdup() and
strbuf_git_path(). The selected list of paths goes to $GIT_COMMON_DIR,
not the other way around in case a developer adds a new
worktree-specific file and it's accidentally promoted to be shared
across repositories (this includes unknown files added by third party
commands)
The list of known files that belong to $GIT_DIR are:
ADD_EDIT.patch BISECT_ANCESTORS_OK BISECT_EXPECTED_REV BISECT_LOG
BISECT_NAMES CHERRY_PICK_HEAD COMMIT_MSG FETCH_HEAD HEAD MERGE_HEAD
MERGE_MODE MERGE_RR NOTES_EDITMSG NOTES_MERGE_WORKTREE ORIG_HEAD
REVERT_HEAD SQUASH_MSG TAG_EDITMSG fast_import_crash_* logs/HEAD
next-index-* rebase-apply rebase-merge rsync-refs-* sequencer/*
shallow_*
Path mapping is NOT done for git_path_submodule(). Multi-checkouts are
not supported as submodules.
Helped-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-30 09:24:36 +01:00
|
|
|
test_git_path GIT_COMMON_DIR=bar objects bar/objects
|
|
|
|
test_git_path GIT_COMMON_DIR=bar objects/bar bar/objects/bar
|
|
|
|
test_git_path GIT_COMMON_DIR=bar info/exclude bar/info/exclude
|
|
|
|
test_git_path GIT_COMMON_DIR=bar info/grafts bar/info/grafts
|
2014-11-30 09:24:55 +01:00
|
|
|
test_git_path GIT_COMMON_DIR=bar info/sparse-checkout .git/info/sparse-checkout
|
2015-09-01 04:13:10 +02:00
|
|
|
test_git_path GIT_COMMON_DIR=bar info//sparse-checkout .git/info//sparse-checkout
|
$GIT_COMMON_DIR: a new environment variable
This variable is intended to support multiple working directories
attached to a repository. Such a repository may have a main working
directory, created by either "git init" or "git clone" and one or more
linked working directories. These working directories and the main
repository share the same repository directory.
In linked working directories, $GIT_COMMON_DIR must be defined to point
to the real repository directory and $GIT_DIR points to an unused
subdirectory inside $GIT_COMMON_DIR. File locations inside the
repository are reorganized from the linked worktree view point:
- worktree-specific such as HEAD, logs/HEAD, index, other top-level
refs and unrecognized files are from $GIT_DIR.
- the rest like objects, refs, info, hooks, packed-refs, shallow...
are from $GIT_COMMON_DIR (except info/sparse-checkout, but that's
a separate patch)
Scripts are supposed to retrieve paths in $GIT_DIR with "git rev-parse
--git-path", which will take care of "$GIT_DIR vs $GIT_COMMON_DIR"
business.
The redirection is done by git_path(), git_pathdup() and
strbuf_git_path(). The selected list of paths goes to $GIT_COMMON_DIR,
not the other way around in case a developer adds a new
worktree-specific file and it's accidentally promoted to be shared
across repositories (this includes unknown files added by third party
commands)
The list of known files that belong to $GIT_DIR are:
ADD_EDIT.patch BISECT_ANCESTORS_OK BISECT_EXPECTED_REV BISECT_LOG
BISECT_NAMES CHERRY_PICK_HEAD COMMIT_MSG FETCH_HEAD HEAD MERGE_HEAD
MERGE_MODE MERGE_RR NOTES_EDITMSG NOTES_MERGE_WORKTREE ORIG_HEAD
REVERT_HEAD SQUASH_MSG TAG_EDITMSG fast_import_crash_* logs/HEAD
next-index-* rebase-apply rebase-merge rsync-refs-* sequencer/*
shallow_*
Path mapping is NOT done for git_path_submodule(). Multi-checkouts are
not supported as submodules.
Helped-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-30 09:24:36 +01:00
|
|
|
test_git_path GIT_COMMON_DIR=bar remotes/bar bar/remotes/bar
|
|
|
|
test_git_path GIT_COMMON_DIR=bar branches/bar bar/branches/bar
|
|
|
|
test_git_path GIT_COMMON_DIR=bar logs/refs/heads/master bar/logs/refs/heads/master
|
|
|
|
test_git_path GIT_COMMON_DIR=bar refs/heads/master bar/refs/heads/master
|
2015-09-01 04:13:11 +02:00
|
|
|
test_git_path GIT_COMMON_DIR=bar refs/bisect/foo .git/refs/bisect/foo
|
$GIT_COMMON_DIR: a new environment variable
This variable is intended to support multiple working directories
attached to a repository. Such a repository may have a main working
directory, created by either "git init" or "git clone" and one or more
linked working directories. These working directories and the main
repository share the same repository directory.
In linked working directories, $GIT_COMMON_DIR must be defined to point
to the real repository directory and $GIT_DIR points to an unused
subdirectory inside $GIT_COMMON_DIR. File locations inside the
repository are reorganized from the linked worktree view point:
- worktree-specific such as HEAD, logs/HEAD, index, other top-level
refs and unrecognized files are from $GIT_DIR.
- the rest like objects, refs, info, hooks, packed-refs, shallow...
are from $GIT_COMMON_DIR (except info/sparse-checkout, but that's
a separate patch)
Scripts are supposed to retrieve paths in $GIT_DIR with "git rev-parse
--git-path", which will take care of "$GIT_DIR vs $GIT_COMMON_DIR"
business.
The redirection is done by git_path(), git_pathdup() and
strbuf_git_path(). The selected list of paths goes to $GIT_COMMON_DIR,
not the other way around in case a developer adds a new
worktree-specific file and it's accidentally promoted to be shared
across repositories (this includes unknown files added by third party
commands)
The list of known files that belong to $GIT_DIR are:
ADD_EDIT.patch BISECT_ANCESTORS_OK BISECT_EXPECTED_REV BISECT_LOG
BISECT_NAMES CHERRY_PICK_HEAD COMMIT_MSG FETCH_HEAD HEAD MERGE_HEAD
MERGE_MODE MERGE_RR NOTES_EDITMSG NOTES_MERGE_WORKTREE ORIG_HEAD
REVERT_HEAD SQUASH_MSG TAG_EDITMSG fast_import_crash_* logs/HEAD
next-index-* rebase-apply rebase-merge rsync-refs-* sequencer/*
shallow_*
Path mapping is NOT done for git_path_submodule(). Multi-checkouts are
not supported as submodules.
Helped-by: Jens Lehmann <Jens.Lehmann@web.de>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2014-11-30 09:24:36 +01:00
|
|
|
test_git_path GIT_COMMON_DIR=bar hooks/me bar/hooks/me
|
|
|
|
test_git_path GIT_COMMON_DIR=bar config bar/config
|
|
|
|
test_git_path GIT_COMMON_DIR=bar packed-refs bar/packed-refs
|
|
|
|
test_git_path GIT_COMMON_DIR=bar shallow bar/shallow
|
2014-11-30 09:24:31 +01:00
|
|
|
|
2016-10-18 22:06:07 +02:00
|
|
|
# In the tests below, $(pwd) must be used because it is a native path on
|
|
|
|
# Windows and avoids MSYS's path mangling (which simplifies "foo/../bar" and
|
|
|
|
# strips the dot from trailing "/.").
|
2016-04-16 02:50:12 +02:00
|
|
|
|
|
|
|
test_submodule_relative_url "../" "../foo" "../submodule" "../../submodule"
|
|
|
|
test_submodule_relative_url "../" "../foo/bar" "../submodule" "../../foo/submodule"
|
|
|
|
test_submodule_relative_url "../" "../foo/submodule" "../submodule" "../../foo/submodule"
|
|
|
|
test_submodule_relative_url "../" "./foo" "../submodule" "../submodule"
|
|
|
|
test_submodule_relative_url "../" "./foo/bar" "../submodule" "../foo/submodule"
|
|
|
|
test_submodule_relative_url "../../../" "../foo/bar" "../sub/a/b/c" "../../../../foo/sub/a/b/c"
|
2016-10-18 22:06:07 +02:00
|
|
|
test_submodule_relative_url "../" "$(pwd)/addtest" "../repo" "$(pwd)/repo"
|
2016-04-16 02:50:12 +02:00
|
|
|
test_submodule_relative_url "../" "foo/bar" "../submodule" "../foo/submodule"
|
|
|
|
test_submodule_relative_url "../" "foo" "../submodule" "../submodule"
|
|
|
|
|
|
|
|
test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c" "../foo/sub/a/b/c"
|
2016-10-10 19:56:11 +02:00
|
|
|
test_submodule_relative_url "(null)" "../foo/bar" "../sub/a/b/c/" "../foo/sub/a/b/c"
|
2016-10-10 19:56:10 +02:00
|
|
|
test_submodule_relative_url "(null)" "../foo/bar/" "../sub/a/b/c" "../foo/sub/a/b/c"
|
2016-04-16 02:50:12 +02:00
|
|
|
test_submodule_relative_url "(null)" "../foo/bar" "../submodule" "../foo/submodule"
|
|
|
|
test_submodule_relative_url "(null)" "../foo/submodule" "../submodule" "../foo/submodule"
|
|
|
|
test_submodule_relative_url "(null)" "../foo" "../submodule" "../submodule"
|
|
|
|
test_submodule_relative_url "(null)" "./foo/bar" "../submodule" "foo/submodule"
|
|
|
|
test_submodule_relative_url "(null)" "./foo" "../submodule" "submodule"
|
|
|
|
test_submodule_relative_url "(null)" "//somewhere else/repo" "../subrepo" "//somewhere else/subrepo"
|
2016-10-18 22:06:07 +02:00
|
|
|
test_submodule_relative_url "(null)" "$(pwd)/subsuper_update_r" "../subsubsuper_update_r" "$(pwd)/subsubsuper_update_r"
|
|
|
|
test_submodule_relative_url "(null)" "$(pwd)/super_update_r2" "../subsuper_update_r" "$(pwd)/subsuper_update_r"
|
|
|
|
test_submodule_relative_url "(null)" "$(pwd)/." "../." "$(pwd)/."
|
|
|
|
test_submodule_relative_url "(null)" "$(pwd)" "./." "$(pwd)/."
|
|
|
|
test_submodule_relative_url "(null)" "$(pwd)/addtest" "../repo" "$(pwd)/repo"
|
|
|
|
test_submodule_relative_url "(null)" "$(pwd)" "./å äö" "$(pwd)/å äö"
|
|
|
|
test_submodule_relative_url "(null)" "$(pwd)/." "../submodule" "$(pwd)/submodule"
|
|
|
|
test_submodule_relative_url "(null)" "$(pwd)/submodule" "../submodule" "$(pwd)/submodule"
|
|
|
|
test_submodule_relative_url "(null)" "$(pwd)/home2/../remote" "../bundle1" "$(pwd)/home2/../bundle1"
|
|
|
|
test_submodule_relative_url "(null)" "$(pwd)/submodule_update_repo" "./." "$(pwd)/submodule_update_repo/."
|
2016-04-16 02:50:12 +02:00
|
|
|
test_submodule_relative_url "(null)" "file:///tmp/repo" "../subrepo" "file:///tmp/subrepo"
|
|
|
|
test_submodule_relative_url "(null)" "foo/bar" "../submodule" "foo/submodule"
|
|
|
|
test_submodule_relative_url "(null)" "foo" "../submodule" "submodule"
|
|
|
|
test_submodule_relative_url "(null)" "helper:://hostname/repo" "../subrepo" "helper:://hostname/subrepo"
|
|
|
|
test_submodule_relative_url "(null)" "ssh://hostname/repo" "../subrepo" "ssh://hostname/subrepo"
|
|
|
|
test_submodule_relative_url "(null)" "ssh://hostname:22/repo" "../subrepo" "ssh://hostname:22/subrepo"
|
|
|
|
test_submodule_relative_url "(null)" "user@host:path/to/repo" "../subrepo" "user@host:path/to/subrepo"
|
|
|
|
test_submodule_relative_url "(null)" "user@host:repo" "../subrepo" "user@host:subrepo"
|
|
|
|
|
2018-05-12 22:16:51 +02:00
|
|
|
test_expect_success 'match .gitmodules' '
|
2018-05-29 10:09:58 +02:00
|
|
|
test-tool path-utils is_dotgitmodules \
|
2018-05-12 22:16:51 +02:00
|
|
|
.gitmodules \
|
|
|
|
\
|
|
|
|
.git${u200c}modules \
|
|
|
|
\
|
|
|
|
.Gitmodules \
|
|
|
|
.gitmoduleS \
|
|
|
|
\
|
|
|
|
".gitmodules " \
|
|
|
|
".gitmodules." \
|
|
|
|
".gitmodules " \
|
|
|
|
".gitmodules. " \
|
|
|
|
".gitmodules ." \
|
|
|
|
".gitmodules.." \
|
|
|
|
".gitmodules " \
|
|
|
|
".gitmodules. " \
|
|
|
|
".gitmodules . " \
|
|
|
|
".gitmodules ." \
|
|
|
|
\
|
|
|
|
".Gitmodules " \
|
|
|
|
".Gitmodules." \
|
|
|
|
".Gitmodules " \
|
|
|
|
".Gitmodules. " \
|
|
|
|
".Gitmodules ." \
|
|
|
|
".Gitmodules.." \
|
|
|
|
".Gitmodules " \
|
|
|
|
".Gitmodules. " \
|
|
|
|
".Gitmodules . " \
|
|
|
|
".Gitmodules ." \
|
|
|
|
\
|
|
|
|
GITMOD~1 \
|
|
|
|
gitmod~1 \
|
|
|
|
GITMOD~2 \
|
|
|
|
gitmod~3 \
|
|
|
|
GITMOD~4 \
|
|
|
|
\
|
|
|
|
"GITMOD~1 " \
|
|
|
|
"gitmod~2." \
|
|
|
|
"GITMOD~3 " \
|
|
|
|
"gitmod~4. " \
|
|
|
|
"GITMOD~1 ." \
|
|
|
|
"gitmod~2 " \
|
|
|
|
"GITMOD~3. " \
|
|
|
|
"gitmod~4 . " \
|
|
|
|
\
|
|
|
|
GI7EBA~1 \
|
|
|
|
gi7eba~9 \
|
|
|
|
\
|
|
|
|
GI7EB~10 \
|
|
|
|
GI7EB~11 \
|
|
|
|
GI7EB~99 \
|
|
|
|
GI7EB~10 \
|
|
|
|
GI7E~100 \
|
|
|
|
GI7E~101 \
|
|
|
|
GI7E~999 \
|
|
|
|
~1000000 \
|
|
|
|
~9999999 \
|
|
|
|
\
|
|
|
|
--not \
|
|
|
|
".gitmodules x" \
|
|
|
|
".gitmodules .x" \
|
|
|
|
\
|
|
|
|
" .gitmodules" \
|
|
|
|
\
|
|
|
|
..gitmodules \
|
|
|
|
\
|
|
|
|
gitmodules \
|
|
|
|
\
|
|
|
|
.gitmodule \
|
|
|
|
\
|
|
|
|
".gitmodules x " \
|
|
|
|
".gitmodules .x" \
|
|
|
|
\
|
|
|
|
GI7EBA~ \
|
|
|
|
GI7EBA~0 \
|
|
|
|
GI7EBA~~1 \
|
|
|
|
GI7EBA~X \
|
|
|
|
Gx7EBA~1 \
|
|
|
|
GI7EBX~1 \
|
|
|
|
\
|
|
|
|
GI7EB~1 \
|
|
|
|
GI7EB~01 \
|
|
|
|
GI7EB~1X
|
|
|
|
'
|
|
|
|
|
2008-05-20 08:48:54 +02:00
|
|
|
test_done
|