get_cwd_relative(): do not misinterpret suffix as subdirectory

If the current working directory is the same as the work tree path
plus a suffix, e.g. 'work' and 'work-xyz', then the suffix '-xyz'
would be interpreted as a subdirectory of 'work'.

Signed-off-by: Clemens Buchacher <drizzd@aon.at>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Clemens Buchacher
2010-05-22 13:13:05 +02:00
committed by Junio C Hamano
parent e498257d65
commit 490544b128
2 changed files with 17 additions and 4 deletions

9
dir.c
View File

@ -958,9 +958,14 @@ char *get_relative_cwd(char *buffer, int size, const char *dir)
}
if (*dir)
return NULL;
if (*cwd == '/')
switch (*cwd) {
case '\0':
return cwd;
case '/':
return cwd + 1;
return cwd;
default:
return NULL;
}
}
int is_inside_dir(const char *dir)