]> git.ipfire.org Git - thirdparty/git.git/commitdiff
Merge branch 'sg/maint-gitdir-in-subdir'
authorJunio C Hamano <gitster@pobox.com>
Thu, 22 Jan 2009 00:51:25 +0000 (16:51 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Jan 2009 00:51:25 +0000 (16:51 -0800)
* sg/maint-gitdir-in-subdir:
  Fix gitdir detection when in subdir of gitdir

1  2 
setup.c
t/t1501-worktree.sh

diff --combined setup.c
index 6b277b6a11d3d8419d79a93628b9923001a065a6,dd7c039f0d3a18103c1fd322964b0ddac014d0e6..dfda532adc16f5e6d25d7cfc5add3e0e2b6a5209
+++ b/setup.c
@@@ -456,7 -456,11 +456,11 @@@ const char *setup_git_directory_gently(
                        inside_git_dir = 1;
                        if (!work_tree_env)
                                inside_work_tree = 0;
-                       setenv(GIT_DIR_ENVIRONMENT, ".", 1);
+                       if (offset != len) {
+                               cwd[offset] = '\0';
+                               setenv(GIT_DIR_ENVIRONMENT, cwd, 1);
+                       } else
+                               setenv(GIT_DIR_ENVIRONMENT, ".", 1);
                        check_repository_format_gently(nongit_ok);
                        return NULL;
                }
                                *nongit_ok = 1;
                                return NULL;
                        }
 -                      die("Not a git repository");
 +                      die("Not a git repository (or any of the parent directories): %s", DEFAULT_GIT_DIR_ENVIRONMENT);
                }
 -              chdir("..");
 +              if (chdir(".."))
 +                      die("Cannot change to %s/..: %s", cwd, strerror(errno));
        }
  
        inside_git_dir = 0;
diff --combined t/t1501-worktree.sh
index f6a6f839a18de4c3775ea965f164d0d20f2bbe9b,1bcadf3eb6f1e5fdb7e5bcf20836c1a463042458..27dc6c55d5f50a7fd30388b60230482bad6be2d8
@@@ -92,6 -92,13 +92,13 @@@ cd sub/dir || exit 
  test_rev_parse 'in repo.git/sub/dir' false true true sub/dir/
  cd ../../../.. || exit 1
  
+ test_expect_success 'detecting gitdir when cwd is in a subdir of gitdir' '
+       (expected=$(pwd)/repo.git &&
+        cd repo.git/refs &&
+        unset GIT_DIR &&
+        test "$expected" = "$(git rev-parse --git-dir)")
+ '
  test_expect_success 'repo finds its work tree' '
        (cd repo.git &&
         : > work/sub/dir/untracked &&
@@@ -171,7 -178,7 +178,7 @@@ test_expect_success 'git diff' 
  
  test_expect_success 'git grep' '
        (cd repo.git/work/sub &&
 -      GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep -q dir/tracked)
 +      GIT_DIR=../.. GIT_WORK_TREE=.. git grep -l changed | grep dir/tracked)
  '
  
  test_done