Skip to content

Commit

Permalink
Fix make_absolute_path() for parameters without a slash
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Johannes Schindelin authored and Junio C Hamano committed Mar 2, 2008
1 parent 2b459b4 commit e371a4c
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 3 additions & 1 deletion path.c
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,10 @@ const char *make_absolute_path(const char *path)
if (last_slash) {
*last_slash = '\0';
last_elem = xstrdup(last_slash + 1);
} else
} else {
last_elem = xstrdup(buf);
*buf = '\0';
}
}

if (*buf) {
Expand Down
2 changes: 2 additions & 0 deletions t/t0000-basic.sh
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,8 @@ test_expect_success 'absolute path works as expected' '
test "$dir" = "$(test-absolute-path $dir2)" &&
file="$dir"/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 &&
sym="$(cd first; pwd -P)"/file &&
test "$sym" = "$(test-absolute-path $dir2/syml)"
Expand Down

0 comments on commit e371a4c

Please sign in to comment.