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>
Clemens Buchacher committed
May 22, 2010 at 13:13 UTC
490544b1282416a033dc25481db205248ac0bfc8
2 files changed
+17
-4
dir.c
+7
-2
@@ -958,9 +958,14 @@ char *get_relative_cwd(char *buffer, int size, const char *dir)
958
}
959
if (*dir)
960
return NULL;
961
- if (*cwd == '/')
961
+ switch (*cwd) {
962
+ case '\0':
963
+ return cwd;
964
+ case '/':
965
return cwd + 1;
963
- return cwd;
966
+ default:
967
+ return NULL;
968
+ }
969
}
970
971
int is_inside_dir(const char *dir)
t/t1501-worktree.sh
+10
-2
@@ -30,6 +30,7 @@ test_rev_parse() {
30
31
EMPTY_TREE=$(git write-tree)
32
mkdir -p work/sub/dir || exit 1
33
+mkdir -p work2 || exit 1
34
mv .git repo.git || exit 1
35
36
say "core.worktree = relative path"
@@ -54,7 +55,9 @@ GIT_DIR=$(pwd)/repo.git
55
GIT_CONFIG=$GIT_DIR/config
56
git config core.worktree "$(pwd)/work"
57
test_rev_parse 'outside' false false false
57
-cd work || exit 1
58
+cd work2
59
+test_rev_parse 'outside2' false false false
60
+cd ../work || exit 1
61
test_rev_parse 'inside' false false true ''
62
cd sub/dir || exit 1
63
test_rev_parse 'subdirectory' false false true sub/dir/
@@ -67,7 +70,9 @@ git config core.worktree non-existent
70
GIT_WORK_TREE=work
71
export GIT_WORK_TREE
72
test_rev_parse 'outside' false false false
70
-cd work || exit 1
73
+cd work2
74
+test_rev_parse 'outside' false false false
75
+cd ../work || exit 1
76
GIT_WORK_TREE=.
77
test_rev_parse 'inside' false false true ''
78
cd sub/dir || exit 1
@@ -76,6 +81,7 @@ test_rev_parse 'subdirectory' false false true sub/dir/
81
cd ../../.. || exit 1
82
83
mv work repo.git/work
84
+mv work2 repo.git/work2
85
86
say "GIT_WORK_TREE=absolute path, work tree below git dir"
87
GIT_DIR=$(pwd)/repo.git
@@ -86,6 +92,8 @@ cd repo.git || exit 1
92
test_rev_parse 'in repo.git' false true false
93
cd objects || exit 1
94
test_rev_parse 'in repo.git/objects' false true false
95
+cd ../work2 || exit 1
96
+test_rev_parse 'in repo.git/work2' false true false
97
cd ../work || exit 1
98
test_rev_parse 'in repo.git/work' false true true ''
99
cd sub/dir || exit 1