From: Johannes Schindelin <Johannes.Schindelin@gmx.de>
To: git@vger.kernel.org, gitster@pobox.com
Subject: [PATCH 5/5] With work-trees possibly inside git-dir, be more generous
Date: Thu, 26 Jul 2007 07:32:49 +0100 (BST) [thread overview]
Message-ID: <Pine.LNX.4.64.0707260732360.14781@racer.site> (raw)
The earlier work-tree behaviour was seriously bogus. For regular working
tree operations, it checked if inside git dir. That makes no sense, of
course, since the check should be for a work tree, and nothing else.
Fix that.
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
Please consider giving this a real hard beating. I think the
old series was so bad only because nobody cared (including me).
builtin-ls-files.c | 8 +++++---
builtin-rev-parse.c | 6 ++++++
git-sh-setup.sh | 3 +--
git.c | 7 +++++--
4 files changed, 17 insertions(+), 7 deletions(-)
diff --git a/builtin-ls-files.c b/builtin-ls-files.c
index 61577ea..d36181a 100644
--- a/builtin-ls-files.c
+++ b/builtin-ls-files.c
@@ -469,9 +469,11 @@ int cmd_ls_files(int argc, const char **argv, const char *prefix)
break;
}
- if (require_work_tree &&
- (!is_inside_work_tree() || is_inside_git_dir()))
- die("This operation must be run in a work tree");
+ if (require_work_tree && !is_inside_work_tree()) {
+ const char *work_tree = get_git_work_tree();
+ if (!work_tree || chdir(work_tree))
+ die("This operation must be run in a work tree");
+ }
pathspec = get_pathspec(prefix, argv + i);
diff --git a/builtin-rev-parse.c b/builtin-rev-parse.c
index 497903a..3804541 100644
--- a/builtin-rev-parse.c
+++ b/builtin-rev-parse.c
@@ -320,7 +320,13 @@ int cmd_rev_parse(int argc, const char **argv, const char *prefix)
continue;
}
if (!strcmp(arg, "--show-cdup")) {
+ const char *work_tree = get_git_work_tree();
const char *pfx = prefix;
+
+ if (work_tree) {
+ printf("%s\n", work_tree);
+ continue;
+ }
while (pfx) {
pfx = strchr(pfx, '/');
if (pfx) {
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index c51985e..7bef43f 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -59,8 +59,7 @@ cd_to_toplevel () {
}
require_work_tree () {
- test $(git rev-parse --is-inside-work-tree) = true &&
- test $(git rev-parse --is-inside-git-dir) = false ||
+ test $(git rev-parse --is-inside-work-tree) = true ||
die "fatal: $0 cannot be used without a working tree."
}
diff --git a/git.c b/git.c
index 5df10d3..03ce3bb 100644
--- a/git.c
+++ b/git.c
@@ -273,8 +273,11 @@ static int run_command(struct cmd_struct *p, int argc, const char **argv)
if (p->option & USE_PAGER)
setup_pager();
if ((p->option & NEED_WORK_TREE) &&
- (!is_inside_work_tree() || is_inside_git_dir()))
- die("%s must be run in a work tree", p->cmd);
+ !is_inside_work_tree()) {
+ const char *work_tree = get_git_work_tree();
+ if (!work_tree || chdir(work_tree))
+ die("%s must be run in a work tree", p->cmd);
+ }
trace_argv_printf(argv, argc, "trace: built-in: git");
status = p->fn(argc, argv, prefix);
--
1.5.3.rc2.42.gda8d-dirty
reply other threads:[~2007-07-26 6:32 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=Pine.LNX.4.64.0707260732360.14781@racer.site \
--to=johannes.schindelin@gmx.de \
--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).