threads / discuss / 30546

git rev-parse --git-dir does report yield relative path to git directory, per documentation

Subject: git rev-parse --git-dir does report yield relative path to git directory, per documentation

## tl;dr

7 messages between May 17, 2012 and May 18, 2012.

replies: 6people: 4as markdown or json

Jon Seymour· May 17, 2012, 09:03 UTC · lore
Per this advice in git-rev-parse(1):
     Show $GIT_DIR if defined. Otherwise show the path to the .git
directory, relative to the current directory.
I had expected this:

cd /tmp && rm -rf foobar && mkdir foobar && cd foobar && git init && mkdir tmp && :> tmp/.gitignore && git add tmp && cd tmp && git rev-parse --git-dir

to report:

Initialized empty Git repository in /tmp/foobar/.git/ ../.git

but in actual fact it reports:

Initialized empty Git repository in /tmp/foobar/.git/ /tmp/foobar/.git

git version 1.7.10.1.514.ge33c7ea
Am I misunderstanding the meaning of the term "relative" in quote above?
jon.
Junio C Hamano· May 17, 2012, 16:38 UTC · re: Jon Seymour · lore

Re: git rev-parse --git-dir does report yield relative path to git directory, per documentation

Jon Seymour <jon.seymour@gmail.com> writes:
Show 5 quoted lines
> Per this advice in git-rev-parse(1):
>
>      Show $GIT_DIR if defined. Otherwise show the path to the .git
> directory, relative to the current directory.
> ...
Unfortunate.  Here is what the commit that wrote the sentence says:
    commit 80d868b068b9e68a4aac91be578a8f097f45d8da
    Author: Jonathan Nieder <jrnieder@gmail.com>
    Date:   Fri Nov 26 22:32:31 2010 +0700
        git-rev-parse.txt: clarify --git-dir
        The current behavior is often to print an absolute path rather than
        a ../../etc string, but callers must be ready to accept a relative
        path, too. The most common output is ".git" (from the toplevel of
        an ordinary work tree).
        Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
        Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
        Signed-off-by: Junio C Hamano <gitster@pobox.com>

I am not sure what we were smoking. I am guessing that it wanted to say that the path is something you can feed to chdir(2) to go there, but it should have done so without promising more than what it does.

Jonathan Nieder· May 17, 2012, 18:23 UTC · re: Junio C Hamano · lore

Re: git rev-parse --git-dir does report yield relative path to git directory, per documentation

Hi,
Junio C Hamano wrote:
> Jon Seymour <jon.seymour@gmail.com> writes:
Show 5 quoted lines
>> Per this advice in git-rev-parse(1):
>>
>>      Show $GIT_DIR if defined. Otherwise show the path to the .git
>> directory, relative to the current directory.
>> ...
[...]
> I am not sure what we were smoking.
Yeah, that text is pretty confusing.  Thanks for finding it.
The intent was:
	Show the path to the git repository database (usually $GIT_DIR or
	".git").  When relative, this path is relative to the current
	directory.

The point of that last part is that this is relative to the cwd when rev-parse is called and not relative to the top level of the worktree.

Jon Seymour· May 18, 2012, 09:23 UTC · re: Jonathan Nieder · lore

[PATCH v1] Documentation: git-rev-parse: clarify that --git-dir does not necessarily show relative paths

The previous documentation was misleading because it lead the reader to believe that --git-dir would always show a relative path when, in fact, the actual behaviour does not guarantee this.

Rather, it was intended that the advice be given that if a relative path is shown, then the path is relative to the current working directory and not some other directory (for example, the root of the working tree).

Signed-off-by: Jon Seymour <jon.seymour@gmail.com>
---
 Documentation/git-rev-parse.txt | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt
index f63b81a..4cc3e95 100644
--- a/Documentation/git-rev-parse.txt
+++ b/Documentation/git-rev-parse.txt
@@ -137,7 +137,8 @@ shown.  If the pattern does not contain a globbing character (`?`,
 
 --git-dir::
 	Show `$GIT_DIR` if defined. Otherwise show the path to
-	the .git directory, relative to the current directory.
+	the .git directory. The path shown, when relative, is
+	relative to the current working directory.
 +
 If `$GIT_DIR` is not defined and the current directory
 is not detected to lie in a git repository or work tree
-- 
1.7.10.1.514.ge33c7ea
Jonathan Nieder· May 18, 2012, 09:31 UTC · re: Jon Seymour · lore

Re: [PATCH v1] Documentation: git-rev-parse: clarify that --git-dir does not necessarily show relative paths

Jon Seymour wrote:
Show 12 quoted lines
> --- a/Documentation/git-rev-parse.txt
> +++ b/Documentation/git-rev-parse.txt
> @@ -137,7 +137,8 @@ shown.  If the pattern does not contain a globbing character (`?`,
>  
>  --git-dir::
>  	Show `$GIT_DIR` if defined. Otherwise show the path to
> -	the .git directory, relative to the current directory.
> +	the .git directory. The path shown, when relative, is
> +	relative to the current working directory.
>  +
>  If `$GIT_DIR` is not defined and the current directory
>  is not detected to lie in a git repository or work tree
Thanks for taking care of it.

I suppose I'd have used a subject line like the following for brevity.

	rev-parse doc: --git-dir does not always show a relative path
For what it's worth, with or without that change,
Acked-by: Jonathan Nieder <jrnieder@gmail.com>
Nguyen Thai Ngoc Duy· May 18, 2012, 10:23 UTC · re: Jon Seymour · lore

Re: [PATCH v1] Documentation: git-rev-parse: clarify that --git-dir does not necessarily show relative paths

On Fri, May 18, 2012 at 4:23 PM, Jon Seymour <jon.seymour@gmail.com> wrote:
Show 10 quoted lines
> @@ -137,7 +137,8 @@ shown.  If the pattern does not contain a globbing character (`?`,
>
>  --git-dir::
>        Show `$GIT_DIR` if defined. Otherwise show the path to
> -       the .git directory, relative to the current directory.
> +       the .git directory. The path shown, when relative, is
> +       relative to the current working directory.
>  +
>  If `$GIT_DIR` is not defined and the current directory
>  is not detected to lie in a git repository or work tree
Definitely an improvement. Thanks.
-- 
Duy

← back to recent threads