@matheusbsbs / matheus-bagliano / commits / e90fdc39b6
Fork 0

Clean up work-tree handling

The old version of work-tree support was an unholy mess, barely readable, and not to the point. For example, why do you have to provide a worktree, when it is not used? As in "git status". Now it works. Another riddle was: if you can have work trees inside the git dir, why are some programs complaining that they need a work tree? IOW it is allowed to call $ git --git-dir=../ --work-tree=. bla when you really want to. In this case, you are both in the git directory and in the working tree. So, programs have to actually test for the right thing, namely if they are inside a working tree, and not if they are inside a git directory. Also, GIT_DIR=../.git should behave the same as if no GIT_DIR was specified, unless there is a repository in the current working directory. It does now. The logic to determine if a repository is bare, or has a work tree (tertium non datur), is this: --work-tree=bla overrides GIT_WORK_TREE, which overrides core.bare = true, which overrides core.worktree, which overrides GIT_DIR/.. when GIT_DIR ends in /.git, which overrides the directory in which .git/ was found. In related news, a long standing bug was fixed: when in .git/bla/x.git/, which is a bare repository, git formerly assumed ../.. to be the appropriate git dir. This problem was reported by Shawn Pearce to have caused much pain, where a colleague mistakenly ran "git init" in "/" a long time ago, and bare repositories just would not work. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Aug 1, 2007 at 01:30 UTC e90fdc39b6903502192b2dd11e5503cea721a1ad
10 files changed +216 -221
builtin-init-db.c
+11 -37
@@ -174,36 +174,7 @@ static void copy_templates(const char *git_dir, int len, const char *template_di
174 closedir(dir);
175 }
176
177 -/*
178 - * Get the full path to the working tree specified in $GIT_WORK_TREE
179 - * or NULL if no working tree is specified.
180 - */
181 -static const char *get_work_tree(void)
182 -{
183 - const char *git_work_tree;
184 - char cwd[PATH_MAX];
185 - static char worktree[PATH_MAX];
186 -
187 - git_work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
188 - if (!git_work_tree)
189 - return NULL;
190 - if (!getcwd(cwd, sizeof(cwd)))
191 - die("Unable to read current working directory");
192 - if (chdir(git_work_tree))
193 - die("Cannot change directory to specified working tree '%s'",
194 - git_work_tree);
195 - if (git_work_tree[0] != '/') {
196 - if (!getcwd(worktree, sizeof(worktree)))
197 - die("Unable to read current working directory");
198 - git_work_tree = worktree;
199 - }
200 - if (chdir(cwd))
201 - die("Cannot come back to cwd");
202 - return git_work_tree;
203 -}
204 -
205 -static int create_default_files(const char *git_dir, const char *git_work_tree,
206 - const char *template_path)
177 +static int create_default_files(const char *git_dir, const char *template_path)
178 {
179 unsigned len = strlen(git_dir);
180 static char path[PATH_MAX];
@@ -282,16 +253,16 @@ static int create_default_files(const char *git_dir, const char *git_work_tree,
253 }
254 git_config_set("core.filemode", filemode ? "true" : "false");
255
285 - if (is_bare_repository() && !git_work_tree) {
256 + if (is_bare_repository())
257 git_config_set("core.bare", "true");
287 - }
258 else {
259 + const char *work_tree = get_git_work_tree();
260 git_config_set("core.bare", "false");
261 /* allow template config file to override the default */
262 if (log_all_ref_updates == -1)
263 git_config_set("core.logallrefupdates", "true");
293 - if (git_work_tree)
294 - git_config_set("core.worktree", git_work_tree);
264 + if (work_tree != git_work_tree_cfg)
265 + git_config_set("core.worktree", work_tree);
266 }
267 return reinit;
268 }
@@ -308,7 +279,6 @@ static const char init_db_usage[] =
279 int cmd_init_db(int argc, const char **argv, const char *prefix)
280 {
281 const char *git_dir;
311 - const char *git_work_tree;
282 const char *sha1_dir;
283 const char *template_dir = NULL;
284 char *path;
@@ -329,7 +299,11 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
299 usage(init_db_usage);
300 }
301
332 - git_work_tree = get_work_tree();
302 + git_work_tree_cfg = xcalloc(PATH_MAX, 1);
303 + if (!getcwd(git_work_tree_cfg, PATH_MAX))
304 + die ("Cannot access current working directory.");
305 + if (access(get_git_work_tree(), X_OK))
306 + die ("Cannot access work tree '%s'", get_git_work_tree());
307
308 /*
309 * Set up the default .git directory contents
@@ -346,7 +320,7 @@ int cmd_init_db(int argc, const char **argv, const char *prefix)
320 */
321 check_repository_format();
322
349 - reinit = create_default_files(git_dir, git_work_tree, template_dir);
323 + reinit = create_default_files(git_dir, template_dir);
324
325 /*
326 * And set up the object store.
builtin-ls-files.c
+5 -3
@@ -469,9 +469,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
469 break;
470 }
471
472 - if (require_work_tree &&
473 - (!is_inside_work_tree() || is_inside_git_dir()))
474 - die("This operation must be run in a work tree");
472 + if (require_work_tree && !is_inside_work_tree()) {
473 + const char *work_tree = get_git_work_tree();
474 + if (!work_tree || chdir(work_tree))
475 + die("This operation must be run in a work tree");
476 + }
477
478 pathspec = get_pathspec(prefix, argv + i);
479
builtin-rev-parse.c
+7
@@ -321,6 +321,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
321 }
322 if (!strcmp(arg, "--show-cdup")) {
323 const char *pfx = prefix;
324 + if (!is_inside_work_tree()) {
325 + const char *work_tree =
326 + get_git_work_tree();
327 + if (work_tree)
328 + printf("%s\n", work_tree);
329 + continue;
330 + }
331 while (pfx) {
332 pfx = strchr(pfx, '/');
333 if (pfx) {
cache.h
+2
@@ -208,6 +208,7 @@ enum object_type {
208 extern int is_bare_repository_cfg;
209 extern int is_bare_repository(void);
210 extern int is_inside_git_dir(void);
211 +extern char *git_work_tree_cfg;
212 extern int is_inside_work_tree(void);
213 extern const char *get_git_dir(void);
214 extern char *get_object_directory(void);
@@ -215,6 +216,7 @@ extern char *get_refs_directory(void);
216 extern char *get_index_file(void);
217 extern char *get_graft_file(void);
218 extern int set_git_dir(const char *path);
219 +extern const char *get_git_work_tree(void);
220
221 #define ALTERNATE_DB_ENVIRONMENT "GIT_ALTERNATE_OBJECT_DIRECTORIES"
222
environment.c
+26 -9
@@ -35,6 +35,10 @@ int pager_in_use;
35 int pager_use_color = 1;
36 int auto_crlf = 0; /* 1: both ways, -1: only when adding git objects */
37
38 +/* This is set by setup_git_dir_gently() and/or git_default_config() */
39 +char *git_work_tree_cfg;
40 +static const char *work_tree;
41 +
42 static const char *git_dir;
43 static char *git_object_dir, *git_index_file, *git_refs_dir, *git_graft_file;
44
@@ -62,15 +66,8 @@ static void setup_git_env(void)
66
67 int is_bare_repository(void)
68 {
65 - const char *dir, *s;
66 - if (0 <= is_bare_repository_cfg)
67 - return is_bare_repository_cfg;
68 -
69 - dir = get_git_dir();
70 - if (!strcmp(dir, DEFAULT_GIT_DIR_ENVIRONMENT))
71 - return 0;
72 - s = strrchr(dir, '/');
73 - return !s || strcmp(s + 1, DEFAULT_GIT_DIR_ENVIRONMENT);
69 + /* if core.bare is not 'false', let's see if there is a work tree */
70 + return is_bare_repository_cfg && !get_git_work_tree();
71 }
72
73 const char *get_git_dir(void)
@@ -80,6 +77,26 @@ const char *get_git_dir(void)
77 return git_dir;
78 }
79
80 +const char *get_git_work_tree(void)
81 +{
82 + static int initialized = 0;
83 + if (!initialized) {
84 + work_tree = getenv(GIT_WORK_TREE_ENVIRONMENT);
85 + /* core.bare = true overrides implicit and config work tree */
86 + if (!work_tree && is_bare_repository_cfg < 1) {
87 + work_tree = git_work_tree_cfg;
88 + /* make_absolute_path also normalizes the path */
89 + if (work_tree && !is_absolute_path(work_tree))
90 + work_tree = xstrdup(make_absolute_path(git_path(work_tree)));
91 + } else if (work_tree)
92 + work_tree = xstrdup(make_absolute_path(work_tree));
93 + initialized = 1;
94 + if (work_tree)
95 + is_bare_repository_cfg = 0;
96 + }
97 + return work_tree;
98 +}
99 +
100 char *get_object_directory(void)
101 {
102 if (!git_object_dir)
git-sh-setup.sh
+1 -2
@@ -59,8 +59,7 @@ cd_to_toplevel () {
59 }
60
61 require_work_tree () {
62 - test $(git rev-parse --is-inside-work-tree) = true &&
63 - test $(git rev-parse --is-inside-git-dir) = false ||
62 + test $(git rev-parse --is-inside-work-tree) = true ||
63 die "fatal: $0 cannot be used without a working tree."
64 }
65
git.c
+8 -3
@@ -272,9 +272,14 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)
272 prefix = setup_git_directory();
273 if (p->option & USE_PAGER)
274 setup_pager();
275 - if ((p->option & NEED_WORK_TREE) &&
276 - (!is_inside_work_tree() || is_inside_git_dir()))
277 - die("%s must be run in a work tree", p->cmd);
275 + if (p->option & NEED_WORK_TREE) {
276 + const char *work_tree = get_git_work_tree();
277 + const char *git_dir = get_git_dir();
278 + if (!is_absolute_path(git_dir))
279 + set_git_dir(make_absolute_path(git_dir));
280 + if (!work_tree || chdir(work_tree))
281 + die("%s must be run in a work tree", p->cmd);
282 + }
283 trace_argv_printf(argv, argc, "trace: built-in: git");
284
285 status = p->fn(argc, argv, prefix);
setup.c
+127 -152
@@ -1,4 +1,8 @@
1 #include "cache.h"
2 +#include "dir.h"
3 +
4 +static int inside_git_dir = -1;
5 +static int inside_work_tree = -1;
6
7 const char *prefix_path(const char *prefix, int len, const char *path)
8 {
@@ -170,100 +174,89 @@ static int is_git_directory(const char *suspect)
174 return 1;
175 }
176
173 -static int inside_git_dir = -1;
174 -
177 int is_inside_git_dir(void)
178 {
177 - if (inside_git_dir >= 0)
178 - return inside_git_dir;
179 - die("BUG: is_inside_git_dir called before setup_git_directory");
179 + if (inside_git_dir < 0)
180 + inside_git_dir = is_inside_dir(get_git_dir());
181 + return inside_git_dir;
182 }
183
182 -static int inside_work_tree = -1;
183 -
184 int is_inside_work_tree(void)
185 {
186 - if (inside_git_dir >= 0)
187 - return inside_work_tree;
188 - die("BUG: is_inside_work_tree called before setup_git_directory");
186 + if (inside_work_tree < 0)
187 + inside_work_tree = is_inside_dir(get_git_work_tree());
188 + return inside_work_tree;
189 }
190
191 -static char *gitworktree_config;
192 -
193 -static int git_setup_config(const char *var, const char *value)
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.
201 + */
202 +const char *set_work_tree(const char *dir)
203 {
195 - if (!strcmp(var, "core.worktree")) {
196 - if (gitworktree_config)
197 - strlcpy(gitworktree_config, value, PATH_MAX);
198 - return 0;
204 + char dir_buffer[PATH_MAX];
205 + static char buffer[PATH_MAX + 1], *rel = NULL;
206 + int len, postfix_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 > postfix_len && !strcmp(dir + len - postfix_len,
211 + "/" DEFAULT_GIT_DIR_ENVIRONMENT)) {
212 + strncpy(dir_buffer, dir, len - postfix_len);
213 +
214 + /* are we inside the default work tree? */
215 + rel = get_relative_cwd(buffer, sizeof(buffer), dir_buffer);
216 + }
217 + /* if rel is set, the cwd is _not_ the current working tree */
218 + if (rel && *rel) {
219 + if (!is_absolute_path(dir))
220 + set_git_dir(make_absolute_path(dir));
221 + dir = dir_buffer;
222 + chdir(dir);
223 + strcat(rel, "/");
224 + inside_git_dir = 0;
225 + } else {
226 + rel = NULL;
227 + dir = getcwd(buffer, sizeof(buffer));
228 }
200 - return git_default_config(var, value);
229 + git_work_tree_cfg = xstrdup(dir);
230 + inside_work_tree = 1;
231 +
232 + return rel;
233 }
234
235 +/*
236 + * We cannot decide in this function whether we are in the work tree or
237 + * not, since the config can only be read _after_ this function was called.
238 + */
239 const char *setup_git_directory_gently(int *nongit_ok)
240 {
241 + const char *work_tree_env = getenv(GIT_WORK_TREE_ENVIRONMENT);
242 static char cwd[PATH_MAX+1];
206 - char worktree[PATH_MAX+1], gitdir[PATH_MAX+1];
207 - const char *gitdirenv, *gitworktree;
208 - int wt_rel_gitdir = 0;
243 + const char *gitdirenv;
244 + int len, offset;
245
246 + /*
247 + * If GIT_DIR is set explicitly, we're not going
248 + * to do any discovery, but we still do repository
249 + * validation.
250 + */
251 gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
211 - if (!gitdirenv) {
212 - int len, offset;
213 -
214 - if (!getcwd(cwd, sizeof(cwd)-1))
215 - die("Unable to read current working directory");
216 -
217 - offset = len = strlen(cwd);
218 - for (;;) {
219 - if (is_git_directory(".git"))
220 - break;
221 - if (offset == 0) {
222 - offset = -1;
223 - break;
224 - }
225 - chdir("..");
226 - while (cwd[--offset] != '/')
227 - ; /* do nothing */
228 - }
229 -
230 - if (offset >= 0) {
231 - inside_work_tree = 1;
232 - git_config(git_default_config);
233 - if (offset == len) {
234 - inside_git_dir = 0;
235 - return NULL;
236 - }
237 -
238 - cwd[len++] = '/';
239 - cwd[len] = '\0';
240 - inside_git_dir = !prefixcmp(cwd + offset + 1, ".git/");
241 - return cwd + offset + 1;
242 - }
243 -
244 - if (chdir(cwd))
245 - die("Cannot come back to cwd");
246 - if (!is_git_directory(".")) {
247 - if (nongit_ok) {
248 - *nongit_ok = 1;
249 - return NULL;
250 - }
251 - die("Not a git repository");
252 - }
253 - setenv(GIT_DIR_ENVIRONMENT, cwd, 1);
254 - gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
255 - if (!gitdirenv)
256 - die("getenv after setenv failed");
257 - }
258 -
259 - if (PATH_MAX - 40 < strlen(gitdirenv)) {
260 - if (nongit_ok) {
261 - *nongit_ok = 1;
252 + if (gitdirenv) {
253 + if (PATH_MAX - 40 < strlen(gitdirenv))
254 + die("'$%s' too big", GIT_DIR_ENVIRONMENT);
255 + if (is_git_directory(gitdirenv)) {
256 + if (!work_tree_env)
257 + return set_work_tree(gitdirenv);
258 return NULL;
259 }
264 - die("$%s too big", GIT_DIR_ENVIRONMENT);
265 - }
266 - if (!is_git_directory(gitdirenv)) {
260 if (nongit_ok) {
261 *nongit_ok = 1;
262 return NULL;
@@ -273,92 +266,53 @@ const char *setup_git_directory_gently(int *nongit_ok)
266
267 if (!getcwd(cwd, sizeof(cwd)-1))
268 die("Unable to read current working directory");
276 - if (chdir(gitdirenv)) {
277 - if (nongit_ok) {
278 - *nongit_ok = 1;
279 - return NULL;
280 - }
281 - die("Cannot change directory to $%s '%s'",
282 - GIT_DIR_ENVIRONMENT, gitdirenv);
283 - }
284 - if (!getcwd(gitdir, sizeof(gitdir)-1))
285 - die("Unable to read current working directory");
286 - if (chdir(cwd))
287 - die("Cannot come back to cwd");
269
270 /*
290 - * In case there is a work tree we may change the directory,
291 - * therefore make GIT_DIR an absolute path.
271 + * Test in the following order (relative to the cwd):
272 + * - .git/
273 + * - ./ (bare)
274 + * - ../.git/
275 + * - ../ (bare)
276 + * - ../../.git/
277 + * etc.
278 */
293 - if (gitdirenv[0] != '/') {
294 - setenv(GIT_DIR_ENVIRONMENT, gitdir, 1);
295 - gitdirenv = getenv(GIT_DIR_ENVIRONMENT);
296 - if (!gitdirenv)
297 - die("getenv after setenv failed");
298 - if (PATH_MAX - 40 < strlen(gitdirenv)) {
299 - if (nongit_ok) {
300 - *nongit_ok = 1;
301 - return NULL;
302 - }
303 - die("$%s too big after expansion to absolute path",
304 - GIT_DIR_ENVIRONMENT);
305 - }
306 - }
307 -
308 - strcat(cwd, "/");
309 - strcat(gitdir, "/");
310 - inside_git_dir = !prefixcmp(cwd, gitdir);
311 -
312 - gitworktree = getenv(GIT_WORK_TREE_ENVIRONMENT);
313 - if (!gitworktree) {
314 - gitworktree_config = worktree;
315 - worktree[0] = '\0';
316 - }
317 - git_config(git_setup_config);
318 - if (!gitworktree) {
319 - gitworktree_config = NULL;
320 - if (worktree[0])
321 - gitworktree = worktree;
322 - if (gitworktree && gitworktree[0] != '/')
323 - wt_rel_gitdir = 1;
324 - }
325 -
326 - if (wt_rel_gitdir && chdir(gitdirenv))
327 - die("Cannot change directory to $%s '%s'",
328 - GIT_DIR_ENVIRONMENT, gitdirenv);
329 - if (gitworktree && chdir(gitworktree)) {
330 - if (nongit_ok) {
331 - if (wt_rel_gitdir && chdir(cwd))
332 - die("Cannot come back to cwd");
333 - *nongit_ok = 1;
279 + offset = len = strlen(cwd);
280 + for (;;) {
281 + if (is_git_directory(DEFAULT_GIT_DIR_ENVIRONMENT))
282 + break;
283 + if (is_git_directory(".")) {
284 + inside_git_dir = 1;
285 + if (!work_tree_env)
286 + inside_work_tree = 0;
287 + setenv(GIT_DIR_ENVIRONMENT, ".", 1);
288 return NULL;
289 }
336 - if (wt_rel_gitdir)
337 - die("Cannot change directory to working tree '%s'"
338 - " from $%s", gitworktree, GIT_DIR_ENVIRONMENT);
339 - else
340 - die("Cannot change directory to working tree '%s'",
341 - gitworktree);
342 - }
343 - if (!getcwd(worktree, sizeof(worktree)-1))
344 - die("Unable to read current working directory");
345 - strcat(worktree, "/");
346 - inside_work_tree = !prefixcmp(cwd, worktree);
347 -
348 - if (gitworktree && inside_work_tree && !prefixcmp(worktree, gitdir) &&
349 - strcmp(worktree, gitdir)) {
350 - inside_git_dir = 0;
290 + chdir("..");
291 + do {
292 + if (!offset) {
293 + if (nongit_ok) {
294 + if (chdir(cwd))
295 + die("Cannot come back to cwd");
296 + *nongit_ok = 1;
297 + return NULL;
298 + }
299 + die("Not a git repository");
300 + }
301 + } while (cwd[--offset] != '/');
302 }
303
353 - if (!inside_work_tree) {
354 - if (chdir(cwd))
355 - die("Cannot come back to cwd");
304 + inside_git_dir = 0;
305 + if (!work_tree_env)
306 + inside_work_tree = 1;
307 + git_work_tree_cfg = xstrndup(cwd, offset);
308 + if (offset == len)
309 return NULL;
357 - }
310
359 - if (!strcmp(cwd, worktree))
360 - return NULL;
361 - return cwd+strlen(worktree);
311 + /* Make "offset" point to past the '/', and add a '/' at the end */
312 + offset++;
313 + cwd[len++] = '/';
314 + cwd[len] = 0;
315 + return cwd + offset;
316 }
317
318 int git_config_perm(const char *var, const char *value)
@@ -386,6 +340,16 @@ int check_repository_format_version(const char *var, const char *value)
340 repository_format_version = git_config_int(var, value);
341 else if (strcmp(var, "core.sharedrepository") == 0)
342 shared_repository = git_config_perm(var, value);
343 + else if (strcmp(var, "core.bare") == 0) {
344 + is_bare_repository_cfg = git_config_bool(var, value);
345 + if (is_bare_repository_cfg == 1)
346 + inside_work_tree = -1;
347 + } else if (strcmp(var, "core.worktree") == 0) {
348 + if (git_work_tree_cfg)
349 + free(git_work_tree_cfg);
350 + git_work_tree_cfg = xstrdup(value);
351 + inside_work_tree = -1;
352 + }
353 return 0;
354 }
355
@@ -402,5 +366,16 @@ const char *setup_git_directory(void)
366 {
367 const char *retval = setup_git_directory_gently(NULL);
368 check_repository_format();
369 +
370 + /* If the work tree is not the default one, recompute prefix */
371 + if (inside_work_tree < 0) {
372 + static char buffer[PATH_MAX + 1];
373 + char *rel;
374 + if (retval && chdir(retval))
375 + die ("Could not jump back into original cwd");
376 + rel = get_relative_cwd(buffer, PATH_MAX, get_git_work_tree());
377 + return rel && *rel ? strcat(rel, "/") : NULL;
378 + }
379 +
380 return retval;
381 }
t/t1500-rev-parse.sh
+10 -10
@@ -31,9 +31,9 @@ test_rev_parse() {
31 test_rev_parse toplevel false false true ''
32
33 cd .git || exit 1
34 -test_rev_parse .git/ false true true .git/
34 +test_rev_parse .git/ true true false ''
35 cd objects || exit 1
36 -test_rev_parse .git/objects/ false true true .git/objects/
36 +test_rev_parse .git/objects/ true true false ''
37 cd ../.. || exit 1
38
39 mkdir -p sub/dir || exit 1
@@ -42,7 +42,7 @@ test_rev_parse subdirectory false false true sub/dir/
42 cd ../.. || exit 1
43
44 git config core.bare true
45 -test_rev_parse 'core.bare = true' true false true
45 +test_rev_parse 'core.bare = true' true false false
46
47 git config --unset core.bare
48 test_rev_parse 'core.bare undefined' false false true
@@ -50,28 +50,28 @@ test_rev_parse 'core.bare undefined' false false true
50 mkdir work || exit 1
51 cd work || exit 1
52 export GIT_DIR=../.git
53 -export GIT_CONFIG="$GIT_DIR"/config
53 +export GIT_CONFIG="$(pwd)"/../.git/config
54
55 git config core.bare false
56 -test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true ''
56 +test_rev_parse 'GIT_DIR=../.git, core.bare = false' false false true work/
57
58 git config core.bare true
59 -test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false true ''
59 +test_rev_parse 'GIT_DIR=../.git, core.bare = true' true false false ''
60
61 git config --unset core.bare
62 -test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true ''
62 +test_rev_parse 'GIT_DIR=../.git, core.bare undefined' false false true work/
63
64 mv ../.git ../repo.git || exit 1
65 export GIT_DIR=../repo.git
66 -export GIT_CONFIG="$GIT_DIR"/config
66 +export GIT_CONFIG="$(pwd)"/../repo.git/config
67
68 git config core.bare false
69 test_rev_parse 'GIT_DIR=../repo.git, core.bare = false' false false true ''
70
71 git config core.bare true
72 -test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false true ''
72 +test_rev_parse 'GIT_DIR=../repo.git, core.bare = true' true false false ''
73
74 git config --unset core.bare
75 -test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' true false true ''
75 +test_rev_parse 'GIT_DIR=../repo.git, core.bare undefined' false false true ''
76
77 test_done
t/t1501-worktree.sh
+19 -5
@@ -33,17 +33,17 @@ mv .git repo.git || exit 1
33
34 say "core.worktree = relative path"
35 export GIT_DIR=repo.git
36 -export GIT_CONFIG=$GIT_DIR/config
36 +export GIT_CONFIG="$(pwd)"/$GIT_DIR/config
37 unset GIT_WORK_TREE
38 git config core.worktree ../work
39 test_rev_parse 'outside' false false false
40 cd work || exit 1
41 export GIT_DIR=../repo.git
42 -export GIT_CONFIG=$GIT_DIR/config
42 +export GIT_CONFIG="$(pwd)"/$GIT_DIR/config
43 test_rev_parse 'inside' false false true ''
44 cd sub/dir || exit 1
45 export GIT_DIR=../../../repo.git
46 -export GIT_CONFIG=$GIT_DIR/config
46 +export GIT_CONFIG="$(pwd)"/$GIT_DIR/config
47 test_rev_parse 'subdirectory' false false true sub/dir/
48 cd ../../.. || exit 1
49
@@ -84,9 +84,23 @@ test_rev_parse 'in repo.git' false true false
84 cd objects || exit 1
85 test_rev_parse 'in repo.git/objects' false true false
86 cd ../work || exit 1
87 -test_rev_parse 'in repo.git/work' false false true ''
87 +test_rev_parse 'in repo.git/work' false true true ''
88 cd sub/dir || exit 1
89 -test_rev_parse 'in repo.git/sub/dir' false false true sub/dir/
89 +test_rev_parse 'in repo.git/sub/dir' false true true sub/dir/
90 cd ../../../.. || exit 1
91
92 +test_expect_success 'repo finds its work tree' '
93 + (cd repo.git &&
94 + : > work/sub/dir/untracked &&
95 + test sub/dir/untracked = "$(git ls-files --others)")
96 +'
97 +
98 +test_expect_success 'repo finds its work tree from work tree, too' '
99 + (cd repo.git/work/sub/dir &&
100 + : > tracked &&
101 + git --git-dir=../../.. add tracked &&
102 + cd ../../.. &&
103 + test sub/dir/tracked = "$(git ls-files)")
104 +'
105 +
106 test_done