@matheusbsbs / matheus-bagliano / commits / e371a4c648
Fork 0

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>

Johannes Schindelin committed Mar 2, 2008 at 07:40 UTC e371a4c648e72673fcfdf0b45192857dd149e2f5
2 files changed +5 -1
path.c
+3 -1
@@ -311,8 +311,10 @@ const char *make_absolute_path(const char *path)
311 if (last_slash) {
312 *last_slash = '\0';
313 last_elem = xstrdup(last_slash + 1);
314 - } else
314 + } else {
315 last_elem = xstrdup(buf);
316 + *buf = '\0';
317 + }
318 }
319
320 if (*buf) {
t/t0000-basic.sh
+2
@@ -304,6 +304,8 @@ test_expect_success 'absolute path works as expected' '
304 test "$dir" = "$(test-absolute-path $dir2)" &&
305 file="$dir"/index &&
306 test "$file" = "$(test-absolute-path $dir2/index)" &&
307 + basename=blub &&
308 + test "$dir/$basename" = $(cd .git && test-absolute-path $basename) &&
309 ln -s ../first/file .git/syml &&
310 sym="$(cd first; pwd -P)"/file &&
311 test "$sym" = "$(test-absolute-path $dir2/syml)"