From: Jeff King <peff@peff.net>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: [PATCH] allow setting GIT_WORK_TREE to "no work tree"
Date: Wed, 6 Feb 2008 05:26:08 -0500 [thread overview]
Message-ID: <20080206102608.GA1007@coredump.intra.peff.net> (raw)
In setup_git_directory_gently, we have a special rule
that says "if GIT_DIR is set but GIT_WORK_TREE is not, then
use the current working directory as the work tree." This is
the intended behavior for the user perspective.
However, setup_git_directory_gently sets GIT_DIR itself,
meaning that further setups (either because we are executing
a command via alias, or in a subprocess) will see the
non-existent GIT_WORK_TREE and assume we fall into the
"current working directory is the working tree" codepath.
Instead, we now use a special value of GIT_WORK_TREE to
indicate that we have already checked for a worktree and
that there isn't one, setting it when we set GIT_DIR and
checking for it in the special case path.
The special value is a blank GIT_WORK_TREE; it could be any
value, but this should not conflict with any user values
(and as a bonus, you can now tell git "I don't have a work
tree" with "GIT_WORK_TREE= git", though I suspect the use
case for that is limited).
Signed-off-by: Jeff King <peff@peff.net>
---
On Sun, Feb 03, 2008 at 02:59:13AM -0800, Junio C Hamano wrote:
> * "[alias] st = status" and "cd .git && git st" (Jeff King)
This turned out to be easier than expected. Note that this patch causes
t1500 to fail; however, the test is at fault, and is already fixed in
the series I just sent out.
environment.c | 9 +++++++--
setup.c | 1 +
t/t1502-worktree-semantics.sh | 20 ++++++++++++++++++++
3 files changed, 28 insertions(+), 2 deletions(-)
create mode 100755 t/t1502-worktree-semantics.sh
diff --git a/environment.c b/environment.c
index 18a1c4e..38e8dff 100644
--- a/environment.c
+++ b/environment.c
@@ -90,8 +90,13 @@ const char *get_git_work_tree(void)
/* make_absolute_path also normalizes the path */
if (work_tree && !is_absolute_path(work_tree))
work_tree = xstrdup(make_absolute_path(git_path(work_tree)));
- } else if (work_tree)
- work_tree = xstrdup(make_absolute_path(work_tree));
+ } else if (work_tree) {
+ if (*work_tree)
+ work_tree = xstrdup(
+ make_absolute_path(work_tree));
+ else
+ work_tree = NULL;
+ }
initialized = 1;
if (work_tree)
is_bare_repository_cfg = 0;
diff --git a/setup.c b/setup.c
index adede16..85c0b48 100644
--- a/setup.c
+++ b/setup.c
@@ -309,6 +309,7 @@ const char *setup_git_directory_gently(int *nongit_ok)
if (!work_tree_env)
inside_work_tree = 0;
setenv(GIT_DIR_ENVIRONMENT, ".", 1);
+ setenv(GIT_WORK_TREE_ENVIRONMENT, "", 1);
check_repository_format_gently(nongit_ok);
return NULL;
}
diff --git a/t/t1502-worktree-semantics.sh b/t/t1502-worktree-semantics.sh
new file mode 100755
index 0000000..fbc355b
--- /dev/null
+++ b/t/t1502-worktree-semantics.sh
@@ -0,0 +1,20 @@
+#!/bin/sh
+
+test_description='semantics of GIT_WORK_TREE variable'
+. ./test-lib.sh
+
+test_expect_success 'setup working tree' 'touch file'
+
+test_expect_success 'setup alias' 'git config alias.a add'
+
+test_expect_success 'blank GIT_WORK_TREE disallows work-tree commands' '
+ ! GIT_WORK_TREE= git add .
+'
+
+test_expect_success 'alias inside working tree works' 'git a .'
+
+test_expect_success 'alias inside .git complains about working tree' '
+ cd .git && ! GIT_CONFIG=config git a .
+'
+
+test_done
--
1.5.4.26.g301fb
next reply other threads:[~2008-02-06 10:26 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-02-06 10:26 Jeff King [this message]
2008-02-06 10:42 ` [PATCH] allow setting GIT_WORK_TREE to "no work tree" Johannes Sixt
2008-02-06 11:01 ` Jeff King
2008-02-06 20:54 ` Junio C Hamano
2008-02-06 20:59 ` Junio C Hamano
2008-02-07 5:13 ` Jeff King
2008-02-07 7:13 ` Jay Soffian
2008-02-07 12:33 ` Johannes Schindelin
2008-02-07 18:06 ` Jay Soffian
2008-02-07 9:10 ` Junio C Hamano
2008-02-07 19:02 ` Johannes Schindelin
2008-02-08 7:21 ` Johannes Sixt
2008-02-08 12:05 ` Johannes Schindelin
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=20080206102608.GA1007@coredump.intra.peff.net \
--to=peff@peff.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.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).