summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2007-10-16 23:37:36 (GMT)
committerShawn O. Pearce <spearce@spearce.org>2007-10-17 00:18:04 (GMT)
commitdd5c8af176bb935a0b01a7dc2d5e022565c3aac3 (patch)
tree7bcd6b5db31c7b9317240b2f904d92df8437bbc1 /setup.c
parent33c8d38c7879ee9af0365481eecb4b3906da111a (diff)
downloadgit-dd5c8af176bb935a0b01a7dc2d5e022565c3aac3.zip
git-dd5c8af176bb935a0b01a7dc2d5e022565c3aac3.tar.gz
git-dd5c8af176bb935a0b01a7dc2d5e022565c3aac3.tar.bz2
Fix setup_git_directory_gently() with relative GIT_DIR & GIT_WORK_TREE
There are a few programs, such as config and diff, which allow running without a git repository. Therefore, they have to call setup_git_directory_gently(). However, when GIT_DIR and GIT_WORK_TREE were set, and the current directory was a subdirectory of the work tree, setup_git_directory_gently() would return a bogus NULL prefix. This patch fixes that. Noticed by REPLeffect on IRC. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/setup.c b/setup.c
index 06004f1..145eca5 100644
--- a/setup.c
+++ b/setup.c
@@ -227,9 +227,20 @@ const char *setup_git_directory_gently(int *nongit_ok)
if (PATH_MAX - 40 < strlen(gitdirenv))
die("'$%s' too big", GIT_DIR_ENVIRONMENT);
if (is_git_directory(gitdirenv)) {
+ static char buffer[1024 + 1];
+ const char *retval;
+
if (!work_tree_env)
return set_work_tree(gitdirenv);
- return NULL;
+ retval = get_relative_cwd(buffer, sizeof(buffer) - 1,
+ get_git_work_tree());
+ if (!retval || !*retval)
+ return NULL;
+ set_git_dir(make_absolute_path(gitdirenv));
+ if (chdir(work_tree_env) < 0)
+ die ("Could not chdir to %s", work_tree_env);
+ strcat(buffer, "/");
+ return retval;
}
if (nongit_ok) {
*nongit_ok = 1;