summaryrefslogtreecommitdiff
path: root/setup.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2007-08-05 14:12:53 +0100
committerJunio C Hamano <gitster@pobox.com>2007-08-10 01:12:07 -0700
commit7efeb8f09866ddd09485c0e6f371a6cbba3d2a0a (patch)
treeadd9ba706a65a6e13b6b8da4776b8610ff5df019 /setup.c
parent524e5ffcf41a67ec113a9c3730ddc8fb8d3317f5 (diff)
downloadgit-7efeb8f09866ddd09485c0e6f371a6cbba3d2a0a.tar.gz
Reinstate the old behaviour when GIT_DIR is set and GIT_WORK_TREE is unset
The old behaviour was to unilaterally default to the cwd is the work tree when GIT_DIR was set, but GIT_WORK_TREE wasn't, no matter if we are inside the GIT_DIR, or if GIT_DIR is actually something like ../../../.git. Signed-off-by: Johannes Schindelin <Johannes.Schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'setup.c')
-rw-r--r--setup.c52
1 files changed, 10 insertions, 42 deletions
diff --git a/setup.c b/setup.c
index b55b82c99e..06004f1587 100644
--- a/setup.c
+++ b/setup.c
@@ -189,53 +189,21 @@ int is_inside_work_tree(void)
}
/*
- * If no worktree was given, and we are outside of a default work tree,
- * now is the time to set it.
- *
- * In other words, if the user calls git with something like
- *
- * git --git-dir=/some/where/else/.git bla
- *
- * default to /some/where/else as working directory; if the specified
- * git-dir does not end in "/.git", the cwd is used as working directory.
+ * set_work_tree() is only ever called if you set GIT_DIR explicitely.
+ * The old behaviour (which we retain here) is to set the work tree root
+ * to the cwd, unless overridden by the config, the command line, or
+ * GIT_WORK_TREE.
*/
-const char *set_work_tree(const char *dir)
+static const char *set_work_tree(const char *dir)
{
- char dir_buffer[PATH_MAX], *rel = NULL;
- static char buffer[PATH_MAX + 1];
- int len, suffix_len = strlen(DEFAULT_GIT_DIR_ENVIRONMENT) + 1;
-
- /* strip the variable 'dir' of the postfix "/.git" if it has it */
- len = strlen(dir);
- if (len > suffix_len &&
- !strcmp(dir + len - suffix_len, "/" DEFAULT_GIT_DIR_ENVIRONMENT)) {
- if ((len - suffix_len) >= sizeof(dir_buffer))
- die("directory name too long");
- memcpy(dir_buffer, dir, len - suffix_len);
- dir_buffer[len - suffix_len] = '\0';
-
- /* are we inside the default work tree? */
- rel = get_relative_cwd(buffer, sizeof(buffer), dir_buffer);
- }
+ char buffer[PATH_MAX + 1];
- /* if rel is set, the cwd is _not_ the current working tree */
- if (rel && *rel) {
- if (!is_absolute_path(dir))
- set_git_dir(make_absolute_path(dir));
- dir = dir_buffer;
- if (chdir(dir))
- die("cannot chdir to %s: %s", dir, strerror(errno));
- else
- strcat(rel, "/");
- inside_git_dir = 0;
- } else {
- rel = NULL;
- dir = getcwd(buffer, sizeof(buffer));
- }
- git_work_tree_cfg = xstrdup(dir);
+ if (!getcwd(buffer, sizeof(buffer)))
+ die ("Could not get the current working directory");
+ git_work_tree_cfg = xstrdup(buffer);
inside_work_tree = 1;
- return rel;
+ return NULL;
}
/*