mirror of
https://github.com/git/git.git
synced 2026-02-19 14:21:50 +00:00
Merge branch 'mh/abspath' into next
Will merge to 'next'. * mh/abspath: t0060: split absolute path test in two to exercise some of it on Windows t0060: verify that real_path() removes extra slashes real_path(): properly handle nonexistent top-level paths t0060: verify that real_path() works correctly with absolute paths real_path(): reject the empty string t0060: verify that real_path() fails if passed the empty string absolute_path(): reject the empty string t0060: verify that absolute_path() fails if passed the empty string t0060: move tests of real_path() from t0000 to here
This commit is contained in:
@@ -35,6 +35,9 @@ const char *real_path(const char *path)
|
||||
if (path == buf || path == next_buf)
|
||||
return path;
|
||||
|
||||
if (!*path)
|
||||
die("The empty string is not a valid path");
|
||||
|
||||
if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
|
||||
die ("Too long path: %.*s", 60, path);
|
||||
|
||||
@@ -42,8 +45,8 @@ const char *real_path(const char *path)
|
||||
if (!is_directory(buf)) {
|
||||
char *last_slash = find_last_dir_sep(buf);
|
||||
if (last_slash) {
|
||||
*last_slash = '\0';
|
||||
last_elem = xstrdup(last_slash + 1);
|
||||
last_slash[1] = '\0';
|
||||
} else {
|
||||
last_elem = xstrdup(buf);
|
||||
*buf = '\0';
|
||||
@@ -123,7 +126,9 @@ const char *absolute_path(const char *path)
|
||||
{
|
||||
static char buf[PATH_MAX + 1];
|
||||
|
||||
if (is_absolute_path(path)) {
|
||||
if (!*path) {
|
||||
die("The empty string is not a valid path");
|
||||
} else if (is_absolute_path(path)) {
|
||||
if (strlcpy(buf, path, PATH_MAX) >= PATH_MAX)
|
||||
die("Too long path: %.*s", 60, path);
|
||||
} else {
|
||||
|
||||
@@ -450,24 +450,6 @@ test_expect_success 'update-index D/F conflict' '
|
||||
test $numpath0 = 1
|
||||
'
|
||||
|
||||
test_expect_success SYMLINKS 'real path works as expected' '
|
||||
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 &&
|
||||
test "$dir" = "$(test-path-utils real_path $dir2)" &&
|
||||
file="$dir"/index &&
|
||||
test "$file" = "$(test-path-utils real_path $dir2/index)" &&
|
||||
basename=blub &&
|
||||
test "$dir/$basename" = "$(cd .git && test-path-utils real_path "$basename")" &&
|
||||
ln -s ../first/file .git/syml &&
|
||||
sym="$(cd first; pwd -P)"/file &&
|
||||
test "$sym" = "$(test-path-utils real_path "$dir2/syml")"
|
||||
'
|
||||
|
||||
test_expect_success 'very long name in the index handled sanely' '
|
||||
|
||||
a=a && # 1
|
||||
|
||||
@@ -139,4 +139,63 @@ test_expect_success 'strip_path_suffix' '
|
||||
test c:/msysgit = $(test-path-utils strip_path_suffix \
|
||||
c:/msysgit/libexec//git-core libexec/git-core)
|
||||
'
|
||||
|
||||
test_expect_success 'absolute path rejects the empty string' '
|
||||
test_must_fail test-path-utils absolute_path ""
|
||||
'
|
||||
|
||||
test_expect_success 'real path rejects the empty string' '
|
||||
test_must_fail test-path-utils real_path ""
|
||||
'
|
||||
|
||||
test_expect_success POSIX 'real path works on absolute paths 1' '
|
||||
nopath="hopefully-absent-path" &&
|
||||
test "/" = "$(test-path-utils real_path "/")" &&
|
||||
test "/$nopath" = "$(test-path-utils real_path "/$nopath")"
|
||||
'
|
||||
|
||||
test_expect_success 'real path works on absolute paths 2' '
|
||||
nopath="hopefully-absent-path" &&
|
||||
# Find an existing top-level directory for the remaining tests:
|
||||
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
|
||||
test "$d" = "$(test-path-utils real_path "$d")" &&
|
||||
test "$d/$nopath" = "$(test-path-utils real_path "$d/$nopath")"
|
||||
'
|
||||
|
||||
test_expect_success POSIX 'real path removes extra leading slashes' '
|
||||
nopath="hopefully-absent-path" &&
|
||||
test "/" = "$(test-path-utils real_path "///")" &&
|
||||
test "/$nopath" = "$(test-path-utils real_path "///$nopath")" &&
|
||||
# Find an existing top-level directory for the remaining tests:
|
||||
d=$(pwd -P | sed -e "s|^\([^/]*/[^/]*\)/.*|\1|") &&
|
||||
test "$d" = "$(test-path-utils real_path "//$d")" &&
|
||||
test "$d/$nopath" = "$(test-path-utils real_path "//$d/$nopath")"
|
||||
'
|
||||
|
||||
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|") &&
|
||||
test "$d" = "$(test-path-utils real_path "$d///")" &&
|
||||
test "$d/$nopath" = "$(test-path-utils real_path "$d///$nopath")"
|
||||
'
|
||||
|
||||
test_expect_success SYMLINKS 'real path works on symlinks' '
|
||||
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 &&
|
||||
test "$dir" = "$(test-path-utils real_path $dir2)" &&
|
||||
file="$dir"/index &&
|
||||
test "$file" = "$(test-path-utils real_path $dir2/index)" &&
|
||||
basename=blub &&
|
||||
test "$dir/$basename" = "$(cd .git && test-path-utils real_path "$basename")" &&
|
||||
ln -s ../first/file .git/syml &&
|
||||
sym="$(cd first; pwd -P)"/file &&
|
||||
test "$sym" = "$(test-path-utils real_path "$dir2/syml")"
|
||||
'
|
||||
|
||||
test_done
|
||||
|
||||
Reference in New Issue
Block a user