[PATCH] require_work_tree broken with NONGIT_OK

Subsystems: the rest

DORMANTno replies

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

[PATCH] require_work_tree broken with NONGIT_OK

From: Gabriel Filion <hidden>
Date: 2016-06-15 22:48:15

When sourcing git-sh-setup after having set NONGIT_OK, calling the
function require_work_tree while outside of a git repository shows a
syntax error.

This is caused by the call to "git rev-parse --is-inside-work-tree"
printing a sentence when it is called outside of a git repository.
Relying on the return code is better.
---
 git-sh-setup.sh |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
diff --git a/git-sh-setup.sh b/git-sh-setup.sh
index d56426d..8de2f03 100755
--- a/git-sh-setup.sh
+++ b/git-sh-setup.sh
@@ -128,7 +128,7 @@ cd_to_toplevel () {
 }
  require_work_tree () {
-	test $(git rev-parse --is-inside-work-tree) = true ||
+	test git rev-parse --is-inside-work-tree >/dev/null 2>&1 ||
 	die "fatal: $0 cannot be used without a working tree."
 }
 -- 1.6.6

Re: [PATCH] require_work_tree broken with NONGIT_OK

From: Jeff King <hidden>
Date: 2016-06-15 22:48:15

On Sun, Feb 14, 2010 at 10:51:47PM -0500, Gabriel Filion wrote:
When sourcing git-sh-setup after having set NONGIT_OK, calling the
function require_work_tree while outside of a git repository shows a
syntax error.

This is caused by the call to "git rev-parse --is-inside-work-tree"
printing a sentence when it is called outside of a git repository.
Relying on the return code is better.
I think your fix is fine, but your analysis is slightly wrong. If we are
not in a work tree, the sentence goes to stderr, and nothing goes to
stdout (which is what makes "test" unhappy).

This is not just a nitpick of your commit message, but I was worried
given some other recent discussion that we were accidentally sending
that message to stdout, which would be a bug. But we're not.

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help