File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -456,7 +456,11 @@ const char *setup_git_directory_gently(int *nongit_ok)
456456 inside_git_dir = 1 ;
457457 if (!work_tree_env )
458458 inside_work_tree = 0 ;
459- setenv (GIT_DIR_ENVIRONMENT , "." , 1 );
459+ if (offset != len ) {
460+ cwd [offset ] = '\0' ;
461+ setenv (GIT_DIR_ENVIRONMENT , cwd , 1 );
462+ } else
463+ setenv (GIT_DIR_ENVIRONMENT , "." , 1 );
460464 check_repository_format_gently (nongit_ok );
461465 return NULL ;
462466 }
Original file line number Diff line number Diff line change @@ -92,6 +92,13 @@ cd sub/dir || exit 1
9292test_rev_parse ' in repo.git/sub/dir' false true true sub/dir/
9393cd ../../../.. || exit 1
9494
95+ test_expect_success ' detecting gitdir when cwd is in a subdir of gitdir' '
96+ (expected=$(pwd)/repo.git &&
97+ cd repo.git/refs &&
98+ unset GIT_DIR &&
99+ test "$expected" = "$(git rev-parse --git-dir)")
100+ '
101+
95102test_expect_success ' repo finds its work tree' '
96103 (cd repo.git &&
97104 : > work/sub/dir/untracked &&
You can’t perform that action at this time.
0 commit comments