get_cwd_relative(): do not misinterpret root path
Commit 490544b
(get_cwd_relative(): do not misinterpret suffix as
subdirectory) handles case where:
dir = "/path/work";
cwd = "/path/work-xyz";
When it comes to the end of get_cwd_relative(), dir is at '\0' and cwd
is at '-'. The rest of cwd, "-xyz", clearly cannot be the relative
path from dir to cwd. However there is another case where:
dir = "/"; /* or even "c:/" */
cwd = "/path/to/here";
In this special case, while *cwd == 'p', which is not a path
separator, the rest of cwd, "path/to/here", can be returned as a
relative path from dir to cwd.
Handle this case and make t1509 pass again.
Reported-by: Albert Strasheim <fullung@gmail.com>
Reported-by: Matthijs Kooijman <matthijs@stdin.nl>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
520ea857e6
commit
fbbb4e19be
6
dir.c
6
dir.c
@ -964,6 +964,12 @@ char *get_relative_cwd(char *buffer, int size, const char *dir)
|
|||||||
case '/':
|
case '/':
|
||||||
return cwd + 1;
|
return cwd + 1;
|
||||||
default:
|
default:
|
||||||
|
/*
|
||||||
|
* dir can end with a path separator when it's root
|
||||||
|
* directory. Return proper prefix in that case.
|
||||||
|
*/
|
||||||
|
if (dir[-1] == '/')
|
||||||
|
return cwd;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user