setup: do not forget working dir from subdir of gitdir
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 24 Jul 2010 11:29:41 +0000 (06:29 -0500)
committerJunio C Hamano <gitster@pobox.com>
Wed, 4 Aug 2010 18:21:44 +0000 (11:21 -0700)
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>
setup.c
t/t4111-apply-subdir.sh
diff --git a/setup.c b/setup.c
index 5fb9c54ba6b21aab62b76602500ae2c408f9216d..5734a1f1c1f30bb2312db1a86c345e895948b75b 100644 (file)
--- a/setup.c
+++ b/setup.c
@@ -369,6 +369,8 @@ static const char *setup_bare_git_dir(const char *work_tree_env,
        if (!work_tree_env)
                inside_work_tree = 0;
        if (offset != len) {
+               if (chdir(cwd))
+                       die_errno("Cannot come back to cwd");
                root_len = offset_1st_component(cwd);
                cwd[offset > root_len ? offset : root_len] = '\0';
                set_git_dir(cwd);
index d6271ae34bc67c206d5d2f276696d140a4f17d9b..a52d94ae21afe8faaea31721234a912b090e2e08 100755 (executable)
@@ -97,7 +97,7 @@ test_expect_success 'apply from .git dir' '
        test_cmp expected .git/file
 '
 
-test_expect_failure 'apply from subdir of .git dir' '
+test_expect_success 'apply from subdir of .git dir' '
        cp postimage expected &&
        cp preimage .git/file &&
        cp preimage .git/objects/file