Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

real_path(): properly handle nonexistent top-level paths

The change has two points:

1. Do not strip off a leading slash, because that erroneously turns an
   absolute path into a relative path.

2. Do not remove slashes from groups of multiple slashes; instead let
   chdir() handle them.  It could be, for example, that it wants to
   leave leading double-slashes alone.

Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information...
commit f4c21e89d7c6b578140e90c02b40eccb51ab8428 1 parent 7bcf48d
Michael Haggerty mhagger authored committed

Showing 2 changed files with 2 additions and 2 deletions. Show diff stats Hide diff stats

  1. +1 1  abspath.c
  2. +1 1  t/t0060-path-utils.sh
2  abspath.c
@@ -45,8 +45,8 @@ const char *real_path(const char *path)
45 45 if (!is_directory(buf)) {
46 46 char *last_slash = find_last_dir_sep(buf);
47 47 if (last_slash) {
48   - *last_slash = '\0';
49 48 last_elem = xstrdup(last_slash + 1);
  49 + last_slash[1] = '\0';
50 50 } else {
51 51 last_elem = xstrdup(buf);
52 52 *buf = '\0';
2  t/t0060-path-utils.sh
@@ -148,7 +148,7 @@ test_expect_success 'real path rejects the empty string' '
148 148 test_must_fail test-path-utils real_path ""
149 149 '
150 150
151   -test_expect_failure POSIX 'real path works on absolute paths' '
  151 +test_expect_success POSIX 'real path works on absolute paths' '
152 152 nopath="hopefully-absent-path" &&
153 153 test "/" = "$(test-path-utils real_path "/")" &&
154 154 test "/$nopath" = "$(test-path-utils real_path "/$nopath")" &&

Git Notes

amlog

Message-Id: <1346971264-23744-8-git-send-email-mhagger@alum.mit.edu>

0 comments on commit f4c21e8

Please sign in to comment.
Something went wrong with that request. Please try again.