{"thread":{"id":"37492","subject":"[PATCH v2] setup.c: set workdir when gitdir is not default","startedAt":"2014-09-04T21:33:44Z","lastAt":"2014-09-04T21:33:44Z","messageCount":1,"participants":["Max Kirillov"],"isPatch":true,"patchVersion":2,"patchTotal":null},"messages":[{"id":"248875","messageId":"1409866424-19068-1-git-send-email-max@max630.net","threadId":"37492","inReplyTo":null,"subject":"[PATCH v2] setup.c: set workdir when gitdir is not default","fromName":"Max Kirillov","fromEmail":"max@max630.net","sentAt":"2014-09-04T21:33:44Z","receivedAt":"2014-09-04T21:33:44Z","isPatch":true,"sender":{"key":"max@max630.net","avatar":"https://avatars.githubusercontent.com/u/381560?v=4"},"body":"When gitfile is used, git sets GIT_DIR environment variable for\nsubsequent commands, and that commands start working in mode \"GIT_DIR\nset, workdir current\", which is incorrect for the case when git runs\nfrom subdirectory of repository. This can be observed at least for\nrunning aliases - git fails with message \"internal error: work tree has\nalready been set\"\n\nFix by setting GIT_WORK_TREE environment also.\n\nAdd test which demonstrates problem with alias.\n\nSigned-off-by: Max Kirillov <max@max630.net>\n---\n setup.c            | 4 +++-\n t/t0002-gitfile.sh | 9 +++++++++\n 2 files changed, 12 insertions(+), 1 deletion(-)\n\ndiff --git a/setup.c b/setup.c\nindex 0a22f8b..bcf4e31 100644\n--- a/setup.c\n+++ b/setup.c\n@@ -508,8 +508,10 @@ static const char *setup_discovered_git_dir(const char *gitdir,\n \n \t/* #0, #1, #5, #8, #9, #12, #13 */\n \tset_git_work_tree(\".\");\n-\tif (strcmp(gitdir, DEFAULT_GIT_DIR_ENVIRONMENT))\n+\tif (strcmp(gitdir, DEFAULT_GIT_DIR_ENVIRONMENT)) {\n \t\tset_git_dir(gitdir);\n+\t\tsetenv(GIT_WORK_TREE_ENVIRONMENT, get_git_work_tree(), 1);\n+\t}\n \tinside_git_dir = 0;\n \tinside_work_tree = 1;\n \tif (offset == len)\ndiff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh\nindex 37e9396..64d59c3 100755\n--- a/t/t0002-gitfile.sh\n+++ b/t/t0002-gitfile.sh\n@@ -99,4 +99,13 @@ test_expect_success 'check rev-list' '\n \ttest \"$SHA\" = \"$(git rev-list HEAD)\"\n '\n \n+test_expect_success 'check alias call from subdirectory' '\n+\ttest_config alias.testalias \"rev-parse HEAD\" &&\n+\tmkdir -p subdir &&\n+\t(\n+\t\tcd subdir &&\n+\t\tgit testalias\n+\t)\n+'\n+\n test_done\n-- \n2.0.1.1697.g73c6810\n"}]}