mirror of
https://github.com/git/git.git
synced 2024-11-24 10:26:17 +08:00
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:
parent
e498257d65
commit
490544b128
9
dir.c
9
dir.c
@ -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)
|
||||
|
@ -30,6 +30,7 @@ test_rev_parse() {
|
||||
|
||||
EMPTY_TREE=$(git write-tree)
|
||||
mkdir -p work/sub/dir || exit 1
|
||||
mkdir -p work2 || exit 1
|
||||
mv .git repo.git || exit 1
|
||||
|
||||
say "core.worktree = relative path"
|
||||
@ -54,7 +55,9 @@ GIT_DIR=$(pwd)/repo.git
|
||||
GIT_CONFIG=$GIT_DIR/config
|
||||
git config core.worktree "$(pwd)/work"
|
||||
test_rev_parse 'outside' false false false
|
||||
cd work || exit 1
|
||||
cd work2
|
||||
test_rev_parse 'outside2' false false false
|
||||
cd ../work || exit 1
|
||||
test_rev_parse 'inside' false false true ''
|
||||
cd sub/dir || exit 1
|
||||
test_rev_parse 'subdirectory' false false true sub/dir/
|
||||
@ -67,7 +70,9 @@ git config core.worktree non-existent
|
||||
GIT_WORK_TREE=work
|
||||
export GIT_WORK_TREE
|
||||
test_rev_parse 'outside' false false false
|
||||
cd work || exit 1
|
||||
cd work2
|
||||
test_rev_parse 'outside' false false false
|
||||
cd ../work || exit 1
|
||||
GIT_WORK_TREE=.
|
||||
test_rev_parse 'inside' false false true ''
|
||||
cd sub/dir || exit 1
|
||||
@ -76,6 +81,7 @@ test_rev_parse 'subdirectory' false false true sub/dir/
|
||||
cd ../../.. || exit 1
|
||||
|
||||
mv work repo.git/work
|
||||
mv work2 repo.git/work2
|
||||
|
||||
say "GIT_WORK_TREE=absolute path, work tree below git dir"
|
||||
GIT_DIR=$(pwd)/repo.git
|
||||
@ -86,6 +92,8 @@ cd repo.git || exit 1
|
||||
test_rev_parse 'in repo.git' false true false
|
||||
cd objects || exit 1
|
||||
test_rev_parse 'in repo.git/objects' false true false
|
||||
cd ../work2 || exit 1
|
||||
test_rev_parse 'in repo.git/work2' false true false
|
||||
cd ../work || exit 1
|
||||
test_rev_parse 'in repo.git/work' false true true ''
|
||||
cd sub/dir || exit 1
|
||||
|
Loading…
Reference in New Issue
Block a user