summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>2011-03-26 16:04:24 +0700
committerJunio C Hamano <gitster@pobox.com>2011-03-28 17:01:15 -0700
commit9b125da490990ae4d08dd1517dc38b188b874fa8 (patch)
tree1da0d8359926faf97b67946095f5e5e9937186cc /setup.c
parent78bc46675353e4833a59e0f4dfa47d57a9c1a46b (diff)
downloadgit-9b125da490990ae4d08dd1517dc38b188b874fa8.tar.gz
setup: return correct prefix if worktree is '/'
The same old problem reappears after setup code is reworked. We tend to assume there is at least one path component in a path and forget that path can be simply '/'. 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>
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/setup.c b/setup.c
index dadc66659a..f0468c6864 100644
--- a/setup.c
+++ b/setup.c
@@ -322,6 +322,7 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
const char *worktree;
char *gitfile;
+ int offset;
if (PATH_MAX - 40 < strlen(gitdirenv))
die("'$%s' too big", GIT_DIR_ENVIRONMENT);
@@ -387,15 +388,15 @@ static const char *setup_explicit_git_dir(const char *gitdirenv,
return NULL;
}
- if (!prefixcmp(cwd, worktree) &&
- cwd[strlen(worktree)] == '/') { /* cwd inside worktree */
+ offset = dir_inside_of(cwd, worktree);
+ if (offset >= 0) { /* cwd inside worktree? */
set_git_dir(make_absolute_path(gitdirenv));
if (chdir(worktree))
die_errno("Could not chdir to '%s'", worktree);
cwd[len++] = '/';
cwd[len] = '\0';
free(gitfile);
- return cwd + strlen(worktree) + 1;
+ return cwd + offset;
}
/* cwd outside worktree */