threads / patch / 52681

patchgit: update documentation for --git-dir

Subject: [PATCH] git: update documentation for --git-dir

## tl;dr

17 messages between Jan 23, 2020 and Jan 30, 2020. Diffs are folded; open one to read it.

replies: 16people: 5as markdown or json

Heba Waly via GitGitGadget· Jan 23, 2020, 02:16 UTC · lore
From: Heba Waly <heba.waly@gmail.com>

git --git-dir <path> is a bit confusing and sometimes doesn't work as the user would expect it to.

For example, if the user runs `git --git-dir=<path> status`, git will not be able to figure out the work tree path on its own and will assign the work tree to the user's current work directory. When this assignment is wrong, then the output will not match the user's expectations.

This patch updates the documentation to make it clearer.
Signed-off-by: Heba Waly <heba.waly@gmail.com>
---
    [Outreachy] git: update documentation for --git-dir
    
    git --git-dir is a bit confusing and sometimes doesn't work as the user
    would expect it to.
    
    For example, if the user runs git --git-dir=<path> status, git will not
    be able to figure out the work tree path on its own and will assign the
    work tree to the user's current work directory. When this assignment is
    wrong, then the output will not match the user's expectations.
    
    This patch updates the documentation to make it clearer.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-537%2FHebaWaly%2Fgit_dir_doc-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-537/HebaWaly/git_dir_doc-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/537
 Documentation/git.txt | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
Show changes to Documentation/git.txt +9 −4
diff --git a/Documentation/git.txt b/Documentation/git.txt
index b1597ac002..3b9402c742 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -110,10 +110,15 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
 	Do not pipe Git output into a pager.
 
 --git-dir=<path>::
-	Set the path to the repository. This can also be controlled by
-	setting the `GIT_DIR` environment variable. It can be an absolute
-	path or relative path to current working directory.
-
+	Set the path to the repository (i.e. the .git folder). This can also be
+	controlled by setting the `GIT_DIR` environment variable. It can be
+	an absolute path or relative path to current working directory.
+
+	Note that --git-dir=<path> is not the same as -C=<path>.
+	It's preferrable to set --work-tree=<path> as well when setting
+	--git-dir to make sure Git will run your command across the correct
+	work tree.
+	
 --work-tree=<path>::
 	Set the path to the working tree. It can be an absolute path
 	or a path relative to the current working directory.

base-commit: 232378479ee6c66206d47a9be175e3a39682aea6
-- 
gitgitgadget
Heba Waly· Jan 23, 2020, 02:35 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH] git: update documentation for --git-dir

On Thu, Jan 23, 2020 at 3:16 PM Heba Waly via GitGitGadget <gitgitgadget@gmail.com> wrote:

Show 56 quoted lines
>
> From: Heba Waly <heba.waly@gmail.com>
>
> git --git-dir <path> is a bit confusing and sometimes doesn't work as
> the user would expect it to.
>
> For example, if the user runs `git --git-dir=<path> status`, git
> will not be able to figure out the work tree path on its own and
> will assign the work tree to the user's current work directory.
> When this assignment is wrong, then the output will not match the
> user's expectations.
>
> This patch updates the documentation to make it clearer.
>
> Signed-off-by: Heba Waly <heba.waly@gmail.com>
> ---
>     [Outreachy] git: update documentation for --git-dir
>
>     git --git-dir is a bit confusing and sometimes doesn't work as the user
>     would expect it to.
>
>     For example, if the user runs git --git-dir=<path> status, git will not
>     be able to figure out the work tree path on its own and will assign the
>     work tree to the user's current work directory. When this assignment is
>     wrong, then the output will not match the user's expectations.
>
>     This patch updates the documentation to make it clearer.
>
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-537%2FHebaWaly%2Fgit_dir_doc-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-537/HebaWaly/git_dir_doc-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/537
>
>  Documentation/git.txt | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
>
> diff --git a/Documentation/git.txt b/Documentation/git.txt
> index b1597ac002..3b9402c742 100644
> --- a/Documentation/git.txt
> +++ b/Documentation/git.txt
> @@ -110,10 +110,15 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
>         Do not pipe Git output into a pager.
>
>  --git-dir=<path>::
> -       Set the path to the repository. This can also be controlled by
> -       setting the `GIT_DIR` environment variable. It can be an absolute
> -       path or relative path to current working directory.
> -
> +       Set the path to the repository (i.e. the .git folder). This can also be
> +       controlled by setting the `GIT_DIR` environment variable. It can be
> +       an absolute path or relative path to current working directory.
> +
> +       Note that --git-dir=<path> is not the same as -C=<path>.
> +       It's preferrable to set --work-tree=<path> as well when setting
> +       --git-dir to make sure Git will run your command across the correct
> +       work tree.
> +

I just noticed the whitespace on the last line, will wait for the patch to be reviewed then include its fix.

Show 7 quoted lines
>  --work-tree=<path>::
>         Set the path to the working tree. It can be an absolute path
>         or a path relative to the current working directory.
>
> base-commit: 232378479ee6c66206d47a9be175e3a39682aea6
> --
> gitgitgadget
Emily Shaffer· Jan 23, 2020, 02:55 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH] git: update documentation for --git-dir

On Thu, Jan 23, 2020 at 02:16:51AM +0000, Heba Waly via GitGitGadget wrote:
Show 12 quoted lines
> From: Heba Waly <heba.waly@gmail.com>
> 
> git --git-dir <path> is a bit confusing and sometimes doesn't work as
> the user would expect it to.
> 
> For example, if the user runs `git --git-dir=<path> status`, git
> will not be able to figure out the work tree path on its own and
> will assign the work tree to the user's current work directory.
> When this assignment is wrong, then the output will not match the
> user's expectations.
> 
> This patch updates the documentation to make it clearer.

One thing Heba doesn't mention here is the effort she spent looking into how to give a similar hint in the form of an advise() call in cases when --git-dir is specified but --work-tree is not. While it's possible to show that kind of hint, it turns out to be tricky to decide whether the call in question actually wants the worktree. There was also some concern from Jonathan Tan around whether the hint would interfere with pre-existing user scripts which use --git-dir; since hints show on stderr, that interference is likely cosmetic, but still not great.

That left me with a couple questions:
 - Is there a reason the advice library can't check whether it's
   pointing to an interactive shell, along the same lines as deciding
   whether to color output or not?
 - How do we generally worry about changes to stderr output in regard to
   user scripts? Is this as concerning as changes to stdout and return
   code, that is, for plumbing we do not change the format?
Show 42 quoted lines
> 
> Signed-off-by: Heba Waly <heba.waly@gmail.com>
> ---
>     [Outreachy] git: update documentation for --git-dir
>     
>     git --git-dir is a bit confusing and sometimes doesn't work as the user
>     would expect it to.
>     
>     For example, if the user runs git --git-dir=<path> status, git will not
>     be able to figure out the work tree path on its own and will assign the
>     work tree to the user's current work directory. When this assignment is
>     wrong, then the output will not match the user's expectations.
>     
>     This patch updates the documentation to make it clearer.
> 
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-537%2FHebaWaly%2Fgit_dir_doc-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-537/HebaWaly/git_dir_doc-v1
> Pull-Request: https://github.com/gitgitgadget/git/pull/537
> 
>  Documentation/git.txt | 13 +++++++++----
>  1 file changed, 9 insertions(+), 4 deletions(-)
> 
> diff --git a/Documentation/git.txt b/Documentation/git.txt
> index b1597ac002..3b9402c742 100644
> --- a/Documentation/git.txt
> +++ b/Documentation/git.txt
> @@ -110,10 +110,15 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
>  	Do not pipe Git output into a pager.
>  
>  --git-dir=<path>::
> -	Set the path to the repository. This can also be controlled by
> -	setting the `GIT_DIR` environment variable. It can be an absolute
> -	path or relative path to current working directory.
> -
> +	Set the path to the repository (i.e. the .git folder). This can also be
> +	controlled by setting the `GIT_DIR` environment variable. It can be
> +	an absolute path or relative path to current working directory.
> +
> +	Note that --git-dir=<path> is not the same as -C=<path>.
> +	It's preferrable to set --work-tree=<path> as well when setting
> +	--git-dir to make sure Git will run your command across the correct
> +	work tree.

I feel biased. I want to say, "In many cases, -C=<path> is easier to understand than --git-dir" instead. :) But my goal with sending this task to you was "convince people to use -C instead of --git-dir unless they're really sure" - which may or may not align with the sentiment of the rest of the list.

 - Emily
Junio C Hamano· Jan 23, 2020, 06:44 UTC · re: Emily Shaffer · lore

Re: [PATCH] git: update documentation for --git-dir

Emily Shaffer <emilyshaffer@google.com> writes:
Show 5 quoted lines
> I feel biased. I want to say, "In many cases, -C=<path> is easier to
> understand than --git-dir" instead. :) But my goal with sending this
> task to you was "convince people to use -C instead of --git-dir unless
> they're really sure" - which may or may not align with the sentiment of
> the rest of the list.
Ahh, OK.  

These two are options for completely different purposes, and I tend to agree with you that most users when they misuse --git-dir the do want -C instead.

Junio C Hamano· Jan 23, 2020, 06:21 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH] git: update documentation for --git-dir

"Heba Waly via GitGitGadget" <gitgitgadget@gmail.com> writes:
> For example, if the user runs `git --git-dir=<path> status`, git
> will not be able to figure out the work tree path on its own 

It is not "not be able to figure out". Specifying GIT_DIR (either with environment or the --git-dir option) tells Git that the $cwd is the top of the working tree unless otherwise specified (e.g. with GIT_WORK_TREE environment). If you have to say something, saying "When GIT_DIR is specified, the usual repository discovery is skipped and the current directory is taken as the top level of the working tree unless otherwise speciffied" is probably OK.

Junio C Hamano· Jan 23, 2020, 06:41 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH] git: update documentation for --git-dir

"Heba Waly via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 6 quoted lines
>  --git-dir=<path>::
> -	Set the path to the repository. This can also be controlled by
> -	setting the `GIT_DIR` environment variable. It can be an absolute
> -	path or relative path to current working directory.
> -
> +	Set the path to the repository (i.e. the .git folder). This can also be

I suspect (i.e. ".git") may be clear enough, but if you must, say ".git directory", not ".git folder", as you mention "current working directory" later.

> +	controlled by setting the `GIT_DIR` environment variable. It can be
> +	an absolute path or relative path to current working directory.
> +
> +	Note that --git-dir=<path> is not the same as -C=<path>.
Surely, of course.
> +	It's preferrable to set --work-tree=<path> as well when setting
> +	--git-dir to make sure Git will run your command across the correct
> +	work tree.

It does not help the readers that much to say "It's preferrable" without saying what negative implications there are if they don't use it, or what positive effect they would observe if they do.

If I were writing it, I'd drop "Note that..." and rewrite the three lines more like...

	Specifying the location of the ".git" directory using this
	option (or GIT_DIR environment variable) turns off the
	repository discovery that tries to find a directory with
	".git" subdirectory (which is how the repository and the
	top-level of the working tree are discovered), and tells Git
	that you are at the top level of the working tree.  If you
	are not at the top-level directory of the working tree, you
	should tell Git where the top-level of the working tree is,
	with the --work-tree=<path> option (or GIT_WORK_TREE
	environment variable)
perhaps.
Show 5 quoted lines
>  --work-tree=<path>::
>  	Set the path to the working tree. It can be an absolute path
>  	or a path relative to the current working directory.
>
> base-commit: 232378479ee6c66206d47a9be175e3a39682aea6

I do not know if GGG users have control over this, but I'd prefer to see a "-- " divider before this "base-commit: ..." footer material.

Heba Waly· Jan 27, 2020, 02:22 UTC · re: Junio C Hamano · lore

Re: [PATCH] git: update documentation for --git-dir

On Thu, Jan 23, 2020 at 7:41 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 11 quoted lines
>
> "Heba Waly via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> It is not "not be able to figure out".  Specifying GIT_DIR (either
> with environment or the --git-dir option) tells Git that the $cwd is
> the top of the working tree unless otherwise specified (e.g. with
> GIT_WORK_TREE environment).  If you have to say something, saying
> "When GIT_DIR is specified, the usual repository discovery is
> skipped and the current directory is taken as the top level of the
> working tree unless otherwise speciffied" is probably OK.
>
Ok, I didn't understand it as intentional before, will update that.
Show 6 quoted lines
> > +     Set the path to the repository (i.e. the .git folder). This can also be
>
> I suspect (i.e. ".git") may be clear enough, but if you must, say
> ".git directory", not ".git folder", as you mention "current working
> directory" later.
>
Fair enough.
Show 7 quoted lines
> > +     It's preferrable to set --work-tree=<path> as well when setting
> > +     --git-dir to make sure Git will run your command across the correct
> > +     work tree.
>
> It does not help the readers that much to say "It's preferrable"
> without saying what negative implications there are if they don't
> use it, or what positive effect they would observe if they do.
I agree, I couldn't find enough information on the matter to elaborate more.
Show 15 quoted lines
> If I were writing it, I'd drop "Note that..." and rewrite the three
> lines more like...
>
>         Specifying the location of the ".git" directory using this
>         option (or GIT_DIR environment variable) turns off the
>         repository discovery that tries to find a directory with
>         ".git" subdirectory (which is how the repository and the
>         top-level of the working tree are discovered), and tells Git
>         that you are at the top level of the working tree.  If you
>         are not at the top-level directory of the working tree, you
>         should tell Git where the top-level of the working tree is,
>         with the --work-tree=<path> option (or GIT_WORK_TREE
>         environment variable)
>
> perhaps.
That helped me understand it better also, will use this, thanks.
Show 9 quoted lines
>
> >  --work-tree=<path>::
> >       Set the path to the working tree. It can be an absolute path
> >       or a path relative to the current working directory.
> >
> > base-commit: 232378479ee6c66206d47a9be175e3a39682aea6
>
> I do not know if GGG users have control over this, but I'd prefer to
> see a "-- " divider before this "base-commit: ..." footer material.
No I don't think I can change this one.

Thanks, Heba

Heba Waly via GitGitGadget· Jan 27, 2020, 02:24 UTC · re: Heba Waly via GitGitGadget · lore

[PATCH v2] git: update documentation for --git-dir

From: Heba Waly <heba.waly@gmail.com>

git --git-dir <path> is a bit confusing and sometimes doesn't work as the user would expect it to.

For example, if the user runs `git --git-dir=<path> status`, git will skip the repository discovery algorithm and will assign the work tree to the user's current work directory unless otherwise specified. When this assignment is wrong, the output will not match the user's expectations.

This patch updates the documentation to make it clearer.
Signed-off-by: Heba Waly <heba.waly@gmail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
---
    [Outreachy] git: update documentation for --git-dir
    
    git --git-dir is a bit confusing and sometimes doesn't work as the user
    would expect it to.
    
    For example, if the user runs git --git-dir=<path> status, git will not
    be able to figure out the work tree path on its own and will assign the
    work tree to the user's current work directory. When this assignment is
    wrong, then the output will not match the user's expectations.
    
    This patch updates the documentation to make it clearer.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-537%2FHebaWaly%2Fgit_dir_doc-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-537/HebaWaly/git_dir_doc-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/537
Range-diff vs v1:
 1:  3ac4b85cdb ! 1:  8a69eecb97 git: update documentation for --git-dir
     @@ -6,14 +6,15 @@
          the user would expect it to.
      
          For example, if the user runs `git --git-dir=<path> status`, git
     -    will not be able to figure out the work tree path on its own and
     -    will assign the work tree to the user's current work directory.
     -    When this assignment is wrong, then the output will not match the
     -    user's expectations.
     +    will skip the repository discovery algorithm and will assign the
     +    work tree to the user's current work directory unless otherwise
     +    specified. When this assignment is wrong, the output will not match
     +    the user's expectations.
      
          This patch updates the documentation to make it clearer.
      
          Signed-off-by: Heba Waly <heba.waly@gmail.com>
     +    Helped-by: Junio C Hamano <gitster@pobox.com>
      
       diff --git a/Documentation/git.txt b/Documentation/git.txt
       --- a/Documentation/git.txt
     @@ -25,16 +26,23 @@
      -	Set the path to the repository. This can also be controlled by
      -	setting the `GIT_DIR` environment variable. It can be an absolute
      -	path or relative path to current working directory.
     --
     -+	Set the path to the repository (i.e. the .git folder). This can also be
     ++	Set the path to the repository (".git" directory). This can also be
      +	controlled by setting the `GIT_DIR` environment variable. It can be
      +	an absolute path or relative path to current working directory.
      +
     -+	Note that --git-dir=<path> is not the same as -C=<path>.
     -+	It's preferrable to set --work-tree=<path> as well when setting
     -+	--git-dir to make sure Git will run your command across the correct
     -+	work tree.
     -+	
     ++	Specifying the location of the ".git" directory using this
     ++	option (or GIT_DIR environment variable) turns off the
     ++	repository discovery that tries to find a directory with
     ++	".git" subdirectory (which is how the repository and the
     ++	top-level of the working tree are discovered), and tells Git
     ++	that you are at the top level of the working tree.  If you
     ++	are not at the top-level directory of the working tree, you
     ++	should tell Git where the top-level of the working tree is,
     ++	with the --work-tree=<path> option (or GIT_WORK_TREE
     ++	environment variable)
     ++
     ++	If you just want to run git as if it was started in <path> then use
     ++	git -C.
     + 
       --work-tree=<path>::
       	Set the path to the working tree. It can be an absolute path
     - 	or a path relative to the current working directory.
 Documentation/git.txt | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
Show changes to Documentation/git.txt +17 −3
diff --git a/Documentation/git.txt b/Documentation/git.txt
index b1597ac002..cf73f501b6 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -110,9 +110,23 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
 	Do not pipe Git output into a pager.
 
 --git-dir=<path>::
-	Set the path to the repository. This can also be controlled by
-	setting the `GIT_DIR` environment variable. It can be an absolute
-	path or relative path to current working directory.
+	Set the path to the repository (".git" directory). This can also be
+	controlled by setting the `GIT_DIR` environment variable. It can be
+	an absolute path or relative path to current working directory.
+
+	Specifying the location of the ".git" directory using this
+	option (or GIT_DIR environment variable) turns off the
+	repository discovery that tries to find a directory with
+	".git" subdirectory (which is how the repository and the
+	top-level of the working tree are discovered), and tells Git
+	that you are at the top level of the working tree.  If you
+	are not at the top-level directory of the working tree, you
+	should tell Git where the top-level of the working tree is,
+	with the --work-tree=<path> option (or GIT_WORK_TREE
+	environment variable)
+
+	If you just want to run git as if it was started in <path> then use
+	git -C.
 
 --work-tree=<path>::
 	Set the path to the working tree. It can be an absolute path

base-commit: 232378479ee6c66206d47a9be175e3a39682aea6
-- 
gitgitgadget
Johannes Sixt· Jan 27, 2020, 06:28 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH v2] git: update documentation for --git-dir

Am 27.01.20 um 03:24 schrieb Heba Waly via GitGitGadget:
Show 28 quoted lines
> diff --git a/Documentation/git.txt b/Documentation/git.txt
> index b1597ac002..cf73f501b6 100644
> --- a/Documentation/git.txt
> +++ b/Documentation/git.txt
> @@ -110,9 +110,23 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
>  	Do not pipe Git output into a pager.
>  
>  --git-dir=<path>::
> -	Set the path to the repository. This can also be controlled by
> -	setting the `GIT_DIR` environment variable. It can be an absolute
> -	path or relative path to current working directory.
> +	Set the path to the repository (".git" directory). This can also be
> +	controlled by setting the `GIT_DIR` environment variable. It can be
> +	an absolute path or relative path to current working directory.
> +
> +	Specifying the location of the ".git" directory using this
> +	option (or GIT_DIR environment variable) turns off the
> +	repository discovery that tries to find a directory with
> +	".git" subdirectory (which is how the repository and the
> +	top-level of the working tree are discovered), and tells Git
> +	that you are at the top level of the working tree.  If you
> +	are not at the top-level directory of the working tree, you
> +	should tell Git where the top-level of the working tree is,
> +	with the --work-tree=<path> option (or GIT_WORK_TREE
> +	environment variable)
> +
> +	If you just want to run git as if it was started in <path> then use
> +	git -C.

Does this render well? Judging by the precedent set by the descriptions of -C and -c options earlier in this file, continuation paragraphs should not be indented and separated by a line with just a plus sign instead of an empty line.

-- Hannes
Heba Waly· Jan 28, 2020, 04:17 UTC · re: Johannes Sixt · lore

Re: [PATCH v2] git: update documentation for --git-dir

On Mon, Jan 27, 2020 at 7:29 PM Johannes Sixt <j6t@kdbg.org> wrote:
Show 5 quoted lines
>
> Does this render well? Judging by the precedent set by the descriptions
> of -C and -c options earlier in this file, continuation paragraphs
> should not be indented and separated by a line with just a plus sign
> instead of an empty line.

It doesn't render well, thanks for pointing it out, will send an updated version.

Thanks, Heba

Jeff King· Jan 28, 2020, 07:33 UTC · re: Heba Waly · lore

Re: [PATCH v2] git: update documentation for --git-dir

On Tue, Jan 28, 2020 at 05:17:49PM +1300, Heba Waly wrote:
Show 9 quoted lines
> On Mon, Jan 27, 2020 at 7:29 PM Johannes Sixt <j6t@kdbg.org> wrote:
> >
> > Does this render well? Judging by the precedent set by the descriptions
> > of -C and -c options earlier in this file, continuation paragraphs
> > should not be indented and separated by a line with just a plus sign
> > instead of an empty line.
> 
> It doesn't render well, thanks for pointing it out, will send an
> updated version.

One tool that might help as you do documentation patches: there's a doc-diff script that shows the rendered differences.

Try:
  cd Documentation
  ./doc-diff HEAD^ HEAD

(on a branch with your patch at the tip). It was originally written to investigate changes to the markup, etc, but I find it's useful just for looking at any documentation patch, because it takes you right to the part that changed. :)

-Peff
Heba Waly· Jan 28, 2020, 10:40 UTC · re: Jeff King · lore

Re: [PATCH v2] git: update documentation for --git-dir

On Tue, Jan 28, 2020 at 8:33 PM Jeff King <peff@peff.net> wrote:
Show 14 quoted lines
>
> One tool that might help as you do documentation patches: there's a
> doc-diff script that shows the rendered differences.
>
> Try:
>
>   cd Documentation
>   ./doc-diff HEAD^ HEAD
>
> (on a branch with your patch at the tip). It was originally written to
> investigate changes to the markup, etc, but I find it's useful just for
> looking at any documentation patch, because it takes you right to the
> part that changed. :)
>
Nice, thank you for the tip :)
Heba
Heba Waly via GitGitGadget· Jan 28, 2020, 04:24 UTC · re: Heba Waly via GitGitGadget · lore

[PATCH v3] git: update documentation for --git-dir

From: Heba Waly <heba.waly@gmail.com>

git --git-dir <path> is a bit confusing and sometimes doesn't work as the user would expect it to.

For example, if the user runs `git --git-dir=<path> status`, git will skip the repository discovery algorithm and will assign the work tree to the user's current work directory unless otherwise specified. When this assignment is wrong, the output will not match the user's expectations.

This patch updates the documentation to make it clearer.
Signed-off-by: Heba Waly <heba.waly@gmail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
---
    [Outreachy] git: update documentation for --git-dir
    
    git --git-dir is a bit confusing and sometimes doesn't work as the user
    would expect it to.
    
    For example, if the user runs git --git-dir=<path> status, git will not
    be able to figure out the work tree path on its own and will assign the
    work tree to the user's current work directory. When this assignment is
    wrong, then the output will not match the user's expectations.
    
    This patch updates the documentation to make it clearer.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-537%2FHebaWaly%2Fgit_dir_doc-v3
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-537/HebaWaly/git_dir_doc-v3
Pull-Request: https://github.com/gitgitgadget/git/pull/537
Range-diff vs v2:
 1:  8a69eecb97 ! 1:  2a1404f1b3 git: update documentation for --git-dir
     @@ -29,20 +29,20 @@
      +	Set the path to the repository (".git" directory). This can also be
      +	controlled by setting the `GIT_DIR` environment variable. It can be
      +	an absolute path or relative path to current working directory.
     -+
     -+	Specifying the location of the ".git" directory using this
     -+	option (or GIT_DIR environment variable) turns off the
     -+	repository discovery that tries to find a directory with
     -+	".git" subdirectory (which is how the repository and the
     -+	top-level of the working tree are discovered), and tells Git
     -+	that you are at the top level of the working tree.  If you
     -+	are not at the top-level directory of the working tree, you
     -+	should tell Git where the top-level of the working tree is,
     -+	with the --work-tree=<path> option (or GIT_WORK_TREE
     -+	environment variable)
     -+
     -+	If you just want to run git as if it was started in <path> then use
     -+	git -C.
     +++
     ++Specifying the location of the ".git" directory using this
     ++option (or GIT_DIR environment variable) turns off the
     ++repository discovery that tries to find a directory with
     ++".git" subdirectory (which is how the repository and the
     ++top-level of the working tree are discovered), and tells Git
     ++that you are at the top level of the working tree.  If you
     ++are not at the top-level directory of the working tree, you
     ++should tell Git where the top-level of the working tree is,
     ++with the --work-tree=<path> option (or GIT_WORK_TREE
     ++environment variable)
     +++
     ++If you just want to run git as if it was started in <path> then use
     ++git -C.
       
       --work-tree=<path>::
       	Set the path to the working tree. It can be an absolute path
 Documentation/git.txt | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
Show changes to Documentation/git.txt +17 −3
diff --git a/Documentation/git.txt b/Documentation/git.txt
index b1597ac002..c21e33aa10 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -110,9 +110,23 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
 	Do not pipe Git output into a pager.
 
 --git-dir=<path>::
-	Set the path to the repository. This can also be controlled by
-	setting the `GIT_DIR` environment variable. It can be an absolute
-	path or relative path to current working directory.
+	Set the path to the repository (".git" directory). This can also be
+	controlled by setting the `GIT_DIR` environment variable. It can be
+	an absolute path or relative path to current working directory.
++
+Specifying the location of the ".git" directory using this
+option (or GIT_DIR environment variable) turns off the
+repository discovery that tries to find a directory with
+".git" subdirectory (which is how the repository and the
+top-level of the working tree are discovered), and tells Git
+that you are at the top level of the working tree.  If you
+are not at the top-level directory of the working tree, you
+should tell Git where the top-level of the working tree is,
+with the --work-tree=<path> option (or GIT_WORK_TREE
+environment variable)
++
+If you just want to run git as if it was started in <path> then use
+git -C.
 
 --work-tree=<path>::
 	Set the path to the working tree. It can be an absolute path

base-commit: 232378479ee6c66206d47a9be175e3a39682aea6
-- 
gitgitgadget
Junio C Hamano· Jan 28, 2020, 19:22 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH v3] git: update documentation for --git-dir

"Heba Waly via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 10 quoted lines
>  --git-dir=<path>::
> -	Set the path to the repository. This can also be controlled by
> -	setting the `GIT_DIR` environment variable. It can be an absolute
> -	path or relative path to current working directory.
> +	Set the path to the repository (".git" directory). This can also be
> +	controlled by setting the `GIT_DIR` environment variable. It can be
> +	an absolute path or relative path to current working directory.
> ++
> +Specifying the location of the ".git" directory using this
> +option (or GIT_DIR environment variable) turns off the
Consistently quote, like `GIT_DIR`, here?
Show 7 quoted lines
> +repository discovery that tries to find a directory with
> +".git" subdirectory (which is how the repository and the
> +top-level of the working tree are discovered), and tells Git
> +that you are at the top level of the working tree.  If you
> +are not at the top-level directory of the working tree, you
> +should tell Git where the top-level of the working tree is,
> +with the --work-tree=<path> option (or GIT_WORK_TREE

Likewise. We may probably want to say `--work-tree=<path>` inside a bq pair, and definitely `GIT_WORK_TREE` inside a bq pair.

> +environment variable)
> ++
> +If you just want to run git as if it was started in <path> then use
> +git -C.

This is the best part of this patch, I would think. But you said <path> in the "if" part of this "if--then", so (unless your Git magically can read users' minds some magic), I'd expect to see the same <path> to appear somewhere in the "then" part.

	If you just want to run git as if it was started in `<path>`
	then use `git -C <path>`.
perhaps?
Heba Waly· Jan 29, 2020, 12:10 UTC · re: Junio C Hamano · lore

Re: [PATCH v3] git: update documentation for --git-dir

On Wed, Jan 29, 2020 at 8:22 AM Junio C Hamano <gitster@pobox.com> wrote:
Show 16 quoted lines
>
> "Heba Waly via GitGitGadget" <gitgitgadget@gmail.com> writes:
>
> >  --git-dir=<path>::
> > -     Set the path to the repository. This can also be controlled by
> > -     setting the `GIT_DIR` environment variable. It can be an absolute
> > -     path or relative path to current working directory.
> > +     Set the path to the repository (".git" directory). This can also be
> > +     controlled by setting the `GIT_DIR` environment variable. It can be
> > +     an absolute path or relative path to current working directory.
> > ++
> > +Specifying the location of the ".git" directory using this
> > +option (or GIT_DIR environment variable) turns off the
>
> Consistently quote, like `GIT_DIR`, here?
>
Ok
Show 11 quoted lines
> > +repository discovery that tries to find a directory with
> > +".git" subdirectory (which is how the repository and the
> > +top-level of the working tree are discovered), and tells Git
> > +that you are at the top level of the working tree.  If you
> > +are not at the top-level directory of the working tree, you
> > +should tell Git where the top-level of the working tree is,
> > +with the --work-tree=<path> option (or GIT_WORK_TREE
>
> Likewise.  We may probably want to say `--work-tree=<path>` inside a
> bq pair, and definitely `GIT_WORK_TREE` inside a bq pair.
>
Ok
Show 10 quoted lines
> > +environment variable)
> > ++
> > +If you just want to run git as if it was started in <path> then use
> > +git -C.
>
> This is the best part of this patch, I would think.  But you said
> <path> in the "if" part of this "if--then", so (unless your Git
> magically can read users' minds some magic), I'd expect to see the
> same <path> to appear somewhere in the "then" part.
>

By <path> here I'm referring to the path parameter of git --git-dir=<path>. And by mentioning `git -C` without any parameters, my intention is to point the user to scroll up and read about git -C and its parameters. Given that was confusing to you, I don't mind stating the command in its simplest form as you suggested: `git -C <path>`

>         If you just want to run git as if it was started in `<path>`
>         then use `git -C <path>`.
>
> perhaps?

Thanks, Heba

Heba Waly via GitGitGadget· Jan 30, 2020, 01:14 UTC · re: Heba Waly via GitGitGadget · lore

[PATCH v4] git: update documentation for --git-dir

From: Heba Waly <heba.waly@gmail.com>

git --git-dir <path> is a bit confusing and sometimes doesn't work as the user would expect it to.

For example, if the user runs `git --git-dir=<path> status`, git will skip the repository discovery algorithm and will assign the work tree to the user's current work directory unless otherwise specified. When this assignment is wrong, the output will not match the user's expectations.

This patch updates the documentation to make it clearer.
Signed-off-by: Heba Waly <heba.waly@gmail.com>
Helped-by: Junio C Hamano <gitster@pobox.com>
---
    [Outreachy] git: update documentation for --git-dir
    
    git --git-dir is a bit confusing and sometimes doesn't work as the user
    would expect it to.
    
    For example, if the user runs git --git-dir=<path> status, git will skip
    the repository discovery algorithm and will assign the work tree to the
    user's current work directory unless otherwise specified. When this
    assignment is wrong, the output will not match the user's expectations.
    
    This patch updates the documentation to make it clearer.
Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-537%2FHebaWaly%2Fgit_dir_doc-v4
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-537/HebaWaly/git_dir_doc-v4
Pull-Request: https://github.com/gitgitgadget/git/pull/537
Range-diff vs v3:
 1:  2a1404f1b3 ! 1:  e27f150c4b git: update documentation for --git-dir
     @@ -31,18 +31,18 @@
      +	an absolute path or relative path to current working directory.
      ++
      +Specifying the location of the ".git" directory using this
     -+option (or GIT_DIR environment variable) turns off the
     ++option (or `GIT_DIR` environment variable) turns off the
      +repository discovery that tries to find a directory with
      +".git" subdirectory (which is how the repository and the
      +top-level of the working tree are discovered), and tells Git
      +that you are at the top level of the working tree.  If you
      +are not at the top-level directory of the working tree, you
      +should tell Git where the top-level of the working tree is,
     -+with the --work-tree=<path> option (or GIT_WORK_TREE
     ++with the `--work-tree=<path>` option (or `GIT_WORK_TREE`
      +environment variable)
      ++
     -+If you just want to run git as if it was started in <path> then use
     -+git -C.
     ++If you just want to run git as if it was started in `<path>` then use
     ++`git -C <path>`.
       
       --work-tree=<path>::
       	Set the path to the working tree. It can be an absolute path
 Documentation/git.txt | 20 +++++++++++++++++---
 1 file changed, 17 insertions(+), 3 deletions(-)
Show changes to Documentation/git.txt +17 −3
diff --git a/Documentation/git.txt b/Documentation/git.txt
index b1597ac002..41374f24fa 100644
--- a/Documentation/git.txt
+++ b/Documentation/git.txt
@@ -110,9 +110,23 @@ foo.bar= ...`) sets `foo.bar` to the empty string which `git config
 	Do not pipe Git output into a pager.
 
 --git-dir=<path>::
-	Set the path to the repository. This can also be controlled by
-	setting the `GIT_DIR` environment variable. It can be an absolute
-	path or relative path to current working directory.
+	Set the path to the repository (".git" directory). This can also be
+	controlled by setting the `GIT_DIR` environment variable. It can be
+	an absolute path or relative path to current working directory.
++
+Specifying the location of the ".git" directory using this
+option (or `GIT_DIR` environment variable) turns off the
+repository discovery that tries to find a directory with
+".git" subdirectory (which is how the repository and the
+top-level of the working tree are discovered), and tells Git
+that you are at the top level of the working tree.  If you
+are not at the top-level directory of the working tree, you
+should tell Git where the top-level of the working tree is,
+with the `--work-tree=<path>` option (or `GIT_WORK_TREE`
+environment variable)
++
+If you just want to run git as if it was started in `<path>` then use
+`git -C <path>`.
 
 --work-tree=<path>::
 	Set the path to the working tree. It can be an absolute path

base-commit: 232378479ee6c66206d47a9be175e3a39682aea6
-- 
gitgitgadget
Junio C Hamano· Jan 30, 2020, 18:26 UTC · re: Heba Waly via GitGitGadget · lore

Re: [PATCH v4] git: update documentation for --git-dir

"Heba Waly via GitGitGadget" <gitgitgadget@gmail.com> writes:
Show 23 quoted lines
> Range-diff vs v3:
>
>  1:  2a1404f1b3 ! 1:  e27f150c4b git: update documentation for --git-dir
>      @@ -31,18 +31,18 @@
>       +	an absolute path or relative path to current working directory.
>       ++
>       +Specifying the location of the ".git" directory using this
>      -+option (or GIT_DIR environment variable) turns off the
>      ++option (or `GIT_DIR` environment variable) turns off the
>       +repository discovery that tries to find a directory with
>       +".git" subdirectory (which is how the repository and the
>       +top-level of the working tree are discovered), and tells Git
>       +that you are at the top level of the working tree.  If you
>       +are not at the top-level directory of the working tree, you
>       +should tell Git where the top-level of the working tree is,
>      -+with the --work-tree=<path> option (or GIT_WORK_TREE
>      ++with the `--work-tree=<path>` option (or `GIT_WORK_TREE`
>       +environment variable)
>       ++
>      -+If you just want to run git as if it was started in <path> then use
>      -+git -C.
>      ++If you just want to run git as if it was started in `<path>` then use
>      ++`git -C <path>`.
Will replace and queue.  Thanks.        

← back to recent threads