Fix make_absolute_path() for parameters without a slash
When passing "xyz" to make_absolute_path(), make_absolute_path() erroneously tried to chdir("xyz"), and then append "/xyz". Instead, skip the chdir() completely when no slash was found. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
parent
2b459b483c
commit
e371a4c648
4
path.c
4
path.c
@ -311,8 +311,10 @@ const char *make_absolute_path(const char *path)
|
|||||||
if (last_slash) {
|
if (last_slash) {
|
||||||
*last_slash = '\0';
|
*last_slash = '\0';
|
||||||
last_elem = xstrdup(last_slash + 1);
|
last_elem = xstrdup(last_slash + 1);
|
||||||
} else
|
} else {
|
||||||
last_elem = xstrdup(buf);
|
last_elem = xstrdup(buf);
|
||||||
|
*buf = '\0';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (*buf) {
|
if (*buf) {
|
||||||
|
@ -304,6 +304,8 @@ test_expect_success 'absolute path works as expected' '
|
|||||||
test "$dir" = "$(test-absolute-path $dir2)" &&
|
test "$dir" = "$(test-absolute-path $dir2)" &&
|
||||||
file="$dir"/index &&
|
file="$dir"/index &&
|
||||||
test "$file" = "$(test-absolute-path $dir2/index)" &&
|
test "$file" = "$(test-absolute-path $dir2/index)" &&
|
||||||
|
basename=blub &&
|
||||||
|
test "$dir/$basename" = $(cd .git && test-absolute-path $basename) &&
|
||||||
ln -s ../first/file .git/syml &&
|
ln -s ../first/file .git/syml &&
|
||||||
sym="$(cd first; pwd -P)"/file &&
|
sym="$(cd first; pwd -P)"/file &&
|
||||||
test "$sym" = "$(test-absolute-path $dir2/syml)"
|
test "$sym" = "$(test-absolute-path $dir2/syml)"
|
||||||
|
Loading…
Reference in New Issue
Block a user