Thread (9 messages) 9 messages, 4 authors, 2016-06-15

Re: Git 1.8.4.2: 'git-rev-parse --is-inside-git-dir' wrong output!

flat view

From: Ville Walveranta <hidden>
Date: 2016-06-15 22:59:10

Yes, stderr redirection in a subshell seems to work ok.  Since I'm
creating a small git utility script I ended up doing:

--
#!/bin/bash

(git rev-parse --git-dir >/dev/null 2>&1)

if [ $? -ne 0 ] ; then
  echo "Not in a git repo"
else
  echo "Git repo; proceeding.."
  # more logic..
fi
-- 

That works! Thanks for your help!

Ville

On Sat, Nov 2, 2013 at 3:20 PM, John Keeping [off-list ref] wrote:
On Sat, Nov 02, 2013 at 02:42:04PM -0500, Ville Walveranta wrote:
quoted
Without the functionality such as that 1.7.9.5 still offered, it is
now not possible to use "git-rev-parse --is-inside-work-tree" to
detect whether the current location is controlled by a git repository
without emitting the "fatal: Not a git
repository (or any of the parent directories): .git" error message,
when it is not. There is no functional "--quiet" switch, and the usual
error/std redirection to /dev/null doesn't seem to work to squelch the
output.
How doesn't redirection work?  The message is printed to stderr; the
snippet I posted below does indeed squelch the output.
quoted
If "--is-inside-git-dir" and "--is-inside-work-tree" are indeed not
supposed to emit "false" when outside of a git repository, perhaps
there is another way I can use (in a bash script) to cleanly detect
whether a specific path is part of a git repo or not?
Something like this, maybe?

    (cd "$dir" && git rev-parse --git-dir >/dev/null 2>&1)
quoted
On Sat, Nov 2, 2013 at 12:03 PM, Philip Oakley [off-list ref] wrote:
quoted
From: "John Keeping" <redacted>
Sent: Saturday, November 02, 2013 2:06 PM
quoted
On Sat, Nov 02, 2013 at 01:47:02PM -0000, Philip Oakley wrote:
quoted
From: "John Keeping" <redacted>
Sent: Saturday, November 02, 2013 10:58 AM
quoted
On Fri, Nov 01, 2013 at 06:19:51PM -0500, Ville Walveranta wrote:
quoted
"git-rev-parse --is-inside-git-dir" outputs "fatal: Not a git
repository (or any of the parent directories): .git", instead of
"false" when outside of a git directory.  "--is-inside-work-tree"
behaves the same way. Both commands work correctly (i.e. output
"true") when inside a git directory, or inside a work tree,
respectively.
I think that's intentional - and it looks like the behaviour has
not
changed since these options were added.  With the current behaviour
you
get three possible outcomes from "git
rev-parse --is-inside-work-tree":

   if worktree=$(git rev-parse --is-inside-work-tree 2>/dev/null)
   then
       if test "$worktree" = true
       then
           echo 'inside work tree'
       else
           echo 'in repository, but not in work tree'
       fi
   else
       echo 'not in repository'
   fi
--
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help