From: Max Kirillov <max@max630.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Nguyễn Thái Ngọc Duy" <pclouds@gmail.com>,
"Jonathan Nieder" <jrnieder@gmail.com>,
git@vger.kernel.org, "Max Kirillov" <max@max630.net>
Subject: [PATCH] setup.c: set workdir when gitdir is not default
Date: Thu, 4 Sep 2014 01:42:00 +0300 [thread overview]
Message-ID: <1409784120-2228-1-git-send-email-max@max630.net> (raw)
When gitfile is used, git sets GIT_DIR environment variable for
subsequent commands, and that commands start working in mode "GIT_DIR
set, workdir current", which is incorrect for the case when git runs
from subdirectory of repository. This can be observed at least for
running aliases - git fails with message "internal error: work tree has
already been set"
Fix by setting GIT_WORK_TREE environment also.
Add test which demonstrates problem with alias.
Signed-off-by: Max Kirillov <max@max630.net>
---
setup.c | 4 +++-
t/t0002-gitfile.sh | 7 +++++++
2 files changed, 10 insertions(+), 1 deletion(-)
diff --git a/setup.c b/setup.c
index 0a22f8b..bcf4e31 100644
--- a/setup.c
+++ b/setup.c
@@ -508,8 +508,10 @@ static const char *setup_discovered_git_dir(const char *gitdir,
/* #0, #1, #5, #8, #9, #12, #13 */
set_git_work_tree(".");
- if (strcmp(gitdir, DEFAULT_GIT_DIR_ENVIRONMENT))
+ if (strcmp(gitdir, DEFAULT_GIT_DIR_ENVIRONMENT)) {
set_git_dir(gitdir);
+ setenv(GIT_WORK_TREE_ENVIRONMENT, get_git_work_tree(), 1);
+ }
inside_git_dir = 0;
inside_work_tree = 1;
if (offset == len)
diff --git a/t/t0002-gitfile.sh b/t/t0002-gitfile.sh
index 37e9396..428cfdc 100755
--- a/t/t0002-gitfile.sh
+++ b/t/t0002-gitfile.sh
@@ -99,4 +99,11 @@ test_expect_success 'check rev-list' '
test "$SHA" = "$(git rev-list HEAD)"
'
+test_expect_success 'check alias call from subdirectory' '
+ git config alias.testalias "rev-parse HEAD" &&
+ mkdir -p subdir &&
+ cd subdir &&
+ git testalias
+'
+
test_done
--
2.0.1.1697.g73c6810
next reply other threads:[~2014-09-03 22:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-03 22:42 Max Kirillov [this message]
2014-09-04 10:44 ` [PATCH] setup.c: set workdir when gitdir is not default Eric Sunshine
2014-09-04 14:23 ` Max Kirillov
2014-09-04 10:53 ` Duy Nguyen
2014-09-04 14:20 ` Max Kirillov
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1409784120-2228-1-git-send-email-max@max630.net \
--to=max@max630.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=jrnieder@gmail.com \
--cc=pclouds@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).