[PATCH] Support working directory located at root
- From
Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
- Date
- Feb 8, 2010, 14:53 UTC
- Message-ID
- <1265640810-6361-1-git-send-email-pclouds@gmail.com>
Git should work regardless where the working directory is located, even at root. This patch fixes two places where it assumes working directory always have parent directory.
In setup_git_directory_gently(), when Git goes up to root and finds .git there, it happily sets worktree to "".
In prefix_path(), loosen the outside repo check a little bit. Usually when a path XXX is inside worktree /foo, it must be either "/foo", or "/foo/...". When worktree is simply "/", we can safely ignore the check: we have a slash at the beginning already.
Not related to worktree, but also set gitdir correctly if a bare repo is placed (insanely?) at root.
Thanks João Carlos Mendes Luís for pointing out this problem.
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> --- Tell me if this patch is rejected, I'll send another one that makes setup_git_* die() if worktree/gitdir is to be set empty. I don't think we expect gitdir or worktree to be empty anywhere.
setup.c | 6 ++++-- 1 files changed, 4 insertions(+), 2 deletions(-)
diff --git a/setup.c b/setup.c index b38cbee..0fcd2fd 100644 --- a/setup.c +++ b/setup.c @@ -25,7 +25,7 @@ const char *prefix_path(const char *prefix, int len, const char *path) len = strlen(work_tree); total = strlen(sanitized) + 1; if (strncmp(sanitized, work_tree, len) || - (sanitized[len] != '\0' && sanitized[len] != '/')) { + (len > 1 && sanitized[len] != '\0' && sanitized[len] != '/')) { error_out: die("'%s' is outside repository", orig); } @@ -403,7 +403,7 @@ const char *setup_git_directory_gently(int *nongit_ok) if (!work_tree_env) inside_work_tree = 0; if (offset != len) { - cwd[offset] = '\0'; + cwd[offset ? offset : 1] = '\0'; set_git_dir(cwd); } else set_git_dir("."); @@ -427,6 +427,8 @@ const char *setup_git_directory_gently(int *nongit_ok) inside_git_dir = 0; if (!work_tree_env) inside_work_tree = 1; + if (offset == 0) /* reached root, set worktree to '/' */ + offset = 1; git_work_tree_cfg = xstrndup(cwd, offset); if (check_repository_format_gently(nongit_ok)) return NULL;
-- 1.7.0.rc0.54.gd33ef