@matheusbsbs / matheus-bagliano / commits / 8fc0ae80f6
Fork 0

setup: do not forget working dir from subdir of gitdir

v1.6.1.3~4^2 (Fix gitdir detection when in subdir of gitdir, 2009-01-16) did not go far enough: when a git directory is an ancestor of the original working directory, not only should GIT_DIR be set to point to the .git directory, but the original working directory should be restored before carrying out the relevant command. This way, the effect of running a git command from a subdir of .git will be the same whether or not GIT_DIR is explicitly set. Noticed while investigating v1.6.0.3~1 (rehabilitate 'git index-pack' inside the object store, 2008-10-20). Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com> Signed-off-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Nguyễn Thái Ngọc Duy committed Jul 24, 2010 at 06:29 UTC 8fc0ae80f6938e409e0efa45d6d504c6137744e3
2 files changed +3 -1
setup.c
+2
@@ -369,6 +369,8 @@ static const char *setup_bare_git_dir(const char *work_tree_env,
369 if (!work_tree_env)
370 inside_work_tree = 0;
371 if (offset != len) {
372 + if (chdir(cwd))
373 + die_errno("Cannot come back to cwd");
374 root_len = offset_1st_component(cwd);
375 cwd[offset > root_len ? offset : root_len] = '\0';
376 set_git_dir(cwd);
t/t4111-apply-subdir.sh
+1 -1
@@ -97,7 +97,7 @@ test_expect_success 'apply from .git dir' '
97 test_cmp expected .git/file
98 '
99
100 -test_expect_failure 'apply from subdir of .git dir' '
100 +test_expect_success 'apply from subdir of .git dir' '
101 cp postimage expected &&
102 cp preimage .git/file &&
103 cp preimage .git/objects/file