get_relative_cwd() tries to determine a common prefix for dir and cwd. The fix in 490544b (get_cwd_relative(): do not misinterpret suffix as subdirectory, 2010-05-22) made the logic less naive (so that foo-bar is not misdetected as being within foo) but broke some other cases, in particular foo not being detected as being within foo/ any more. Fix it by taking into a account that a directory name may or may not end in /. Document with a test. Reported-by: Matthijs Kooijman <matthijs@xxxxxxxx> Signed-off-by: Michael J Gruber <git@xxxxxxxxxxxxxxxxxxxx> --- So I think this would be a proper fix. I tried to be nice and base it on the commit which I bisected the problem to. I saw much too late that their were later (failed) attempts at fixing this and a major rewrite of the test, which is quite a nuisance. Anyway, this problem needs a fix, and by taking get_cwd_relative() from this patch on top of next the problem is fixed. I have not looked into resolving the merge conflict in the test. dir.c | 23 +++++++++++++++-------- t/t1501-worktree.sh | 13 +++++++++++++ 2 files changed, 28 insertions(+), 8 deletions(-) diff --git a/dir.c b/dir.c index 5615f33..b090cd0 100644 --- a/dir.c +++ b/dir.c @@ -956,16 +956,23 @@ char *get_relative_cwd(char *buffer, int size, const char *dir) dir++; cwd++; } - if (*dir) + + /* dir has more than just '/' left */ + if (*dir && ((*dir != '/') || *(dir+1))) return NULL; - switch (*cwd) { - case '\0': + /* *dir is now '\0' or '/' followed by '\0' */ + if (cwd == buffer) /* we did not move */ + return (*cwd) ? NULL : cwd; + /* we have moved at least by 1 */ + if (*dir) /* == '/' */ + return (*cwd) ? NULL : cwd; + if (!(*cwd)) /* both ended */ return cwd; - case '/': - return cwd + 1; - default: - return NULL; - } + if (*(dir-1) == '/') /* must have been common */ + return cwd; + if (*cwd == '/') + return cwd+1; + return NULL; } int is_inside_dir(const char *dir) diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh index bd8b607..f0dbdd8 100755 --- a/t/t1501-worktree.sh +++ b/t/t1501-worktree.sh @@ -63,6 +63,19 @@ cd sub/dir || exit 1 test_rev_parse 'subdirectory' false false true sub/dir/ cd ../../.. || exit 1 +say "core.worktree = absolute path/" +GIT_DIR=$(pwd)/repo.git +GIT_CONFIG=$GIT_DIR/config +git config core.worktree "$(pwd)/work/" +test_rev_parse 'outside' false false false +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/ +cd ../../.. || exit 1 + say "GIT_WORK_TREE=relative path (override core.worktree)" GIT_DIR=$(pwd)/repo.git GIT_CONFIG=$GIT_DIR/config -- 1.7.4.1.607.g888da -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html