@matheusbsbs / matheus-bagliano / commits / 7efeb8f098
Fork 0

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>

Johannes Schindelin committed Aug 5, 2007 at 14:12 UTC 7efeb8f09866ddd09485c0e6f371a6cbba3d2a0a
2 files changed +14 -44
setup.c
+10 -42
@@ -189,53 +189,21 @@ int is_inside_work_tree(void)
189 }
190
191 /*
192 - * If no worktree was given, and we are outside of a default work tree,
193 - * now is the time to set it.
194 - *
195 - * In other words, if the user calls git with something like
196 - *
197 - * git --git-dir=/some/where/else/.git bla
198 - *
199 - * default to /some/where/else as working directory; if the specified
200 - * git-dir does not end in "/.git", the cwd is used as working directory.
192 + * set_work_tree() is only ever called if you set GIT_DIR explicitely.
193 + * The old behaviour (which we retain here) is to set the work tree root
194 + * to the cwd, unless overridden by the config, the command line, or
195 + * GIT_WORK_TREE.
196 */
202 -const char *set_work_tree(const char *dir)
197 +static const char *set_work_tree(const char *dir)
198 {
204 - char dir_buffer[PATH_MAX], *rel = NULL;
205 - static char buffer[PATH_MAX + 1];
206 - int len, suffix_len = strlen(DEFAULT_GIT_DIR_ENVIRONMENT) + 1;
207 -
208 - /* strip the variable 'dir' of the postfix "/.git" if it has it */
209 - len = strlen(dir);
210 - if (len > suffix_len &&
211 - !strcmp(dir + len - suffix_len, "/" DEFAULT_GIT_DIR_ENVIRONMENT)) {
212 - if ((len - suffix_len) >= sizeof(dir_buffer))
213 - die("directory name too long");
214 - memcpy(dir_buffer, dir, len - suffix_len);
215 - dir_buffer[len - suffix_len] = '\0';
216 -
217 - /* are we inside the default work tree? */
218 - rel = get_relative_cwd(buffer, sizeof(buffer), dir_buffer);
219 - }
199 + char buffer[PATH_MAX + 1];
200
221 - /* if rel is set, the cwd is _not_ the current working tree */
222 - if (rel && *rel) {
223 - if (!is_absolute_path(dir))
224 - set_git_dir(make_absolute_path(dir));
225 - dir = dir_buffer;
226 - if (chdir(dir))
227 - die("cannot chdir to %s: %s", dir, strerror(errno));
228 - else
229 - strcat(rel, "/");
230 - inside_git_dir = 0;
231 - } else {
232 - rel = NULL;
233 - dir = getcwd(buffer, sizeof(buffer));
234 - }
235 - git_work_tree_cfg = xstrdup(dir);
201 + if (!getcwd(buffer, sizeof(buffer)))
202 + die ("Could not get the current working directory");
203 + git_work_tree_cfg = xstrdup(buffer);
204 inside_work_tree = 1;
205
238 - return rel;
206 + return NULL;
207 }
208
209 /*
t/t1500-rev-parse.sh
+4 -2
@@ -28,6 +28,8 @@ test_rev_parse() {
28 [ $# -eq 0 ] && return
29 }
30
31 +# label is-bare is-inside-git is-inside-work prefix
32 +
33 test_rev_parse toplevel false false true ''
34
35 cd .git || exit 1
@@ -53,13 +55,13 @@ export GIT_DIR=../.git
55 export GIT_CONFIG="$(pwd)"/../.git/config
56
57 git config core.bare false
56 -test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true work/
58 +test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true ''
59
60 git config core.bare true
61 test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false false ''
62
63 git config --unset core.bare
62 -test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true work/
64 +test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true ''
65
66 mv ../.git ../repo.git || exit 1
67 export GIT_DIR=../repo.git