From: "SZEDER Gábor" <szeder@ira.uka.de>
To: git@vger.kernel.org
Cc: "SZEDER Gábor" <szeder@ira.uka.de>
Subject: [RFC PATCH] Fix gitdir detection when in subdir of gitdir
Date: Fri, 16 Jan 2009 16:37:33 +0100 [thread overview]
Message-ID: <1232120253-1551-1-git-send-email-szeder@ira.uka.de> (raw)
If the current working directory is a subdirectory of the gitdir (e.g.
<repo>/.git/refs/), then setup_git_directory_gently() will climb its
parent directories until it finds itself in a gitdir. However, no
matter how many parent directories it climbs, it sets
'GIT_DIR_ENVIRONMENT' to ".", which is obviously wrong.
This behaviour affected at least 'git rev-parse --git-dir' and hence
caused some errors in bash completion (e.g. customized command prompt
when on a detached head and completion of refs).
To fix this, we set the absolute path of the found gitdir instead.
Signed-off-by: SZEDER Gábor <szeder@ira.uka.de>
---
I'm not sure about setting an absolut path instead of a relative one
(hence the RFC), although I think it should not make any difference.
Of course I could have count the number of chdir("..") calls and then
construct a "../../..", but that would have been more intrusive than
this two-liner.
setup.c | 3 ++-
t/t1501-worktree.sh | 7 +++++++
2 files changed, 9 insertions(+), 1 deletions(-)
diff --git a/setup.c b/setup.c
index 6b277b6..b787a54 100644
--- a/setup.c
+++ b/setup.c
@@ -456,7 +456,8 @@ const char *setup_git_directory_gently(int *nongit_ok)
inside_git_dir = 1;
if (!work_tree_env)
inside_work_tree = 0;
- setenv(GIT_DIR_ENVIRONMENT, ".", 1);
+ cwd[offset] = '\0';
+ setenv(GIT_DIR_ENVIRONMENT, cwd, 1);
check_repository_format_gently(nongit_ok);
return NULL;
}
diff --git a/t/t1501-worktree.sh b/t/t1501-worktree.sh
index f6a6f83..27dc6c5 100755
--- a/t/t1501-worktree.sh
+++ b/t/t1501-worktree.sh
@@ -92,6 +92,13 @@ cd sub/dir || exit 1
test_rev_parse 'in repo.git/sub/dir' false true true sub/dir/
cd ../../../.. || exit 1
+test_expect_success 'detecting gitdir when cwd is in a subdir of gitdir' '
+ (expected=$(pwd)/repo.git &&
+ cd repo.git/refs &&
+ unset GIT_DIR &&
+ test "$expected" = "$(git rev-parse --git-dir)")
+'
+
test_expect_success 'repo finds its work tree' '
(cd repo.git &&
: > work/sub/dir/untracked &&
--
1.6.1.153.g15508
next reply other threads:[~2009-01-16 15:39 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-16 15:37 SZEDER Gábor [this message]
2009-01-16 16:29 ` [RFC PATCH] Fix gitdir detection when in subdir of gitdir Johannes Schindelin
2009-01-16 16:47 ` Johannes Sixt
2009-01-16 16:50 ` Johannes Sixt
2009-01-16 17:23 ` SZEDER Gábor
2009-01-16 18:07 ` Junio C Hamano
2009-01-16 20:55 ` Johannes Schindelin
2009-01-18 21:27 ` Junio C Hamano
2009-01-19 2:03 ` SZEDER Gábor
2009-01-19 3:15 ` Junio C Hamano
2009-01-19 7:17 ` Johannes Sixt
2009-01-19 2:08 ` [PATCH] t1500: extend with tests of 'git rev-parse --git-dir' SZEDER Gábor
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=1232120253-1551-1-git-send-email-szeder@ira.uka.de \
--to=szeder@ira.uka.de \
--cc=git@vger.kernel.org \
/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).