# rev-parse --show-cdup in .git

3 messages from 2009-12-04 to 2009-12-05. Participants: Michael J Gruber, Junio C Hamano.
Thread: https://gitlist.dev/t/21858

## Michael J Gruber, 2009-12-04 15:45

Subject: rev-parse --show-cdup in .git
Message-ID: <4B192EAE.8000806@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4B192EAE.8000806%40drmicha.warpmail.net

```
I'm sure this was discussed somewhere, but I can't find it:

When called from within .git, git rev-parse --show-cdup returns nothing
rather than "..", not even an error code. Is this intended?

This is all the more disturbing since the cwd of hooks seems to be
GIT_DIR. Is that something one can rely upon? In that case one can
simply use ".." for cdup.

Michael

P.S.: The use case is a simple post-receive-hook that fast forwards a
checked out branch on receiving refs in refs/remotes/incoming/, but
needs to check the worktree against the index etc. 1.7.0 may be an
opportunity to encourage usage of this rather than restoring the old
behavior through options.

```

## Junio C Hamano, 2009-12-04 17:32

Subject: Re: rev-parse --show-cdup in .git
Message-ID: <7vhbs6skzi.fsf@alter.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vhbs6skzi.fsf%40alter.siamese.dyndns.org
In-Reply-To: <4B192EAE.8000806@drmicha.warpmail.net>

```
Michael J Gruber <git@drmicha.warpmail.net> writes:

> I'm sure this was discussed somewhere, but I can't find it:
>
> When called from within .git, git rev-parse --show-cdup returns nothing
> rather than "..", not even an error code. Is this intended?

I do not think --show-cdup should be linked to --is-inside-work-tree in
any way, if that is what you are getting at by mentioning "error code".

> This is all the more disturbing since the cwd of hooks seems to be
> GIT_DIR. Is that something one can rely upon? In that case one can
> simply use ".." for cdup.

I think you will see something that is different from and is more sensible
than ".." when you use GIT_WORK_TREE environment variable (or its
corresponding configuration variable).

```

## Michael J Gruber, 2009-12-05 13:19

Subject: Re: rev-parse --show-cdup in .git
Message-ID: <4B1A5DCB.7020903@drmicha.warpmail.net>
URL: https://gitlist.dev/e/4B1A5DCB.7020903%40drmicha.warpmail.net
In-Reply-To: <7vhbs6skzi.fsf@alter.siamese.dyndns.org>

```
Junio C Hamano venit, vidit, dixit 04.12.2009 18:32:
> Michael J Gruber <git@drmicha.warpmail.net> writes:
> 
>> I'm sure this was discussed somewhere, but I can't find it:
>>
>> When called from within .git, git rev-parse --show-cdup returns nothing
>> rather than "..", not even an error code. Is this intended?
> 
> I do not think --show-cdup should be linked to --is-inside-work-tree in
> any way, if that is what you are getting at by mentioning "error code".

It's just difficult to tell from the output whether you are at the
toplevel (empty relative path) or you're within .git or somewhere else.

>> This is all the more disturbing since the cwd of hooks seems to be
>> GIT_DIR. Is that something one can rely upon? In that case one can
>> simply use ".." for cdup.
> 
> I think you will see something that is different from and is more sensible
> than ".." when you use GIT_WORK_TREE environment variable (or its
> corresponding configuration variable).

All that I want is a reliable method for a hook to cd to the toplevel of
the worktree of a non-bare repositity. cd_to_toplevel (from
git-sh-setup) does not work. I don't think I should have to set any
worktree config in a non-bare repository with standard layout, should I?

Michael

```
