{"thread":{"id":"54918","subject":"git-dir requires work-tree; documentation improvements for working directory","startedAt":"2021-01-02T14:42:12Z","lastAt":"2021-01-04T23:48:02Z","messageCount":7,"participants":["Yaroslav Nikitenko","Felipe Contreras","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"413310","messageId":"CA+RLzGCtp2T=8DG74geBs67X5vUvhwRP4FMZ6MJv+E+Pj=YbWw@mail.gmail.com","threadId":"54918","inReplyTo":null,"subject":"git-dir requires work-tree; documentation improvements for working directory","fromName":"Yaroslav Nikitenko","fromEmail":"metst13@gmail.com","sentAt":"2021-01-02T14:40:56Z","receivedAt":"2021-01-02T14:42:12Z","isPatch":false,"sender":{"key":"metst13@gmail.com","avatar":null},"body":"Dear git users and maintainers,\n\nI use git to manage my dotfiles with this command:\n\n    git --git-dir=/home/yaroslav/.cfg/ --work-tree=/home/yaroslav\n\nWhen reading documentation, I noticed two issues.\n\n1) The command doesn't work without --work-tree (even from the top\nlevel directory, which is my home directory).\n\n    [~]$ git --git-dir=/home/yaroslav/.cfg/ status\n    fatal: this operation must be run in a work tree\n\nI don't have any configuration or environment variables for work-tree\n(as warned here,\nhttps://lore.kernel.org/git/CAPig+cRqkzPzNX8UN4OcgEOOKbtZRLCjNNiZsOVkGBy0pvsEkQ@mail.gmail.com/).\n\nIn `man git` for git-dir it says \"If you are not at the top-level\ndirectory of the working tree, you should tell Git where the top-level\nof the working tree is\" (\"If\"), the same is quoted in a recent thread\n(https://lore.kernel.org/git/88D2A179-806F-4321-828A-359692E646B1@gmail.com/)\n\nI'm using git version 2.30.0 on the most recent Arch Linux.\n\n2) In the man documentation for git > git-dir it's written\n\"It can be an absolute path or relative path to current working directory.\"\nI think this can be confused with work-tree. I suggest removing the\nword 'working' (and probably add an article 'the' before the\n'current', but I'm not a native speaker).\n\nI can see that the expression \"working directory\" is used throughout\nthe man page of git, and it is used ambiguously (sometimes it means\nthe current directory, sometimes git working directory).\n\nI don't subscribe to the mailing list but hope that I'll receive the replies.\n\nThank you and Happy New Year!\n\nBest regards,\nYaroslav Nikitenko\n"},{"id":"413315","messageId":"5ff0c58422038_90dc208ea@natae.notmuch","threadId":"54918","inReplyTo":"CA+RLzGCtp2T=8DG74geBs67X5vUvhwRP4FMZ6MJv+E+Pj=YbWw@mail.gmail.com","subject":"RE: git-dir requires work-tree; documentation improvements for working directory","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-02T19:12:04Z","receivedAt":"2021-01-02T19:13:16Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Yaroslav Nikitenko wrote:\n> I use git to manage my dotfiles with this command:\n> \n>     git --git-dir=/home/yaroslav/.cfg/ --work-tree=/home/yaroslav\n\nI do precisely the same thing.\n\n> When reading documentation, I noticed two issues.\n> \n> 1) The command doesn't work without --work-tree (even from the top\n> level directory, which is my home directory).\n> \n>     [~]$ git --git-dir=/home/yaroslav/.cfg/ status\n>     fatal: this operation must be run in a work tree\n\nThat's weird. It works fine here (although I don't see why I would want\nthat).\n\nIf you remove all your configuration does it still fail?\n\n> 2) In the man documentation for git > git-dir it's written\n> \"It can be an absolute path or relative path to current working directory.\"\n> I think this can be confused with work-tree. I suggest removing the\n> word 'working' (and probably add an article 'the' before the\n> 'current', but I'm not a native speaker).\n\nYes, the article is missing, as for the rest I have no opinion.\n\n> I don't subscribe to the mailing list but hope that I'll receive the replies.\n\nDon't worry. The git mailing list doesn't munge the Reply-To header, so\nany decent MUA will keep you in Cc.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"413317","messageId":"CA+RLzGArUrxC-Kbng3qGpRZUrZXKZj3zD3Hcut=XrUY-i-eYAw@mail.gmail.com","threadId":"54918","inReplyTo":"5ff0c58422038_90dc208ea@natae.notmuch","subject":"Re: git-dir requires work-tree; documentation improvements for working directory","fromName":"Yaroslav Nikitenko","fromEmail":"metst13@gmail.com","sentAt":"2021-01-02T19:44:12Z","receivedAt":"2021-01-02T19:45:10Z","isPatch":false,"sender":{"key":"metst13@gmail.com","avatar":null},"body":"2021-01-02 22:12 GMT+03:00, Felipe Contreras <felipe.contreras@gmail.com>:\n> Yaroslav Nikitenko wrote:\n>> I use git to manage my dotfiles with this command:\n>>\n>>     git --git-dir=/home/yaroslav/.cfg/ --work-tree=/home/yaroslav\n>\n> I do precisely the same thing.\n>\n>> When reading documentation, I noticed two issues.\n>>\n>> 1) The command doesn't work without --work-tree (even from the top\n>> level directory, which is my home directory).\n>>\n>>     [~]$ git --git-dir=/home/yaroslav/.cfg/ status\n>>     fatal: this operation must be run in a work tree\n>\n> That's weird. It works fine here (although I don't see why I would want\n> that).\n\nBTW, how do you do that in your case?\n\n> If you remove all your configuration does it still fail?\n\nIt starts to work when I remove my .cfg/config. I've no idea why it\nhappens. Here is its contents:\n\n$ more .cfg/config\n[core]\n\trepositoryformatversion = 0\n\tfilemode = true\n\tbare = true\n[remote \"origin\"]\n\turl = me@myserver:my_working_path\n[branch \"master\"]\n\tremote = origin\n\tmerge = refs/heads/master\n\n\n>> 2) In the man documentation for git > git-dir it's written\n>> \"It can be an absolute path or relative path to current working\n>> directory.\"\n>> I think this can be confused with work-tree. I suggest removing the\n>> word 'working' (and probably add an article 'the' before the\n>> 'current', but I'm not a native speaker).\n>\n> Yes, the article is missing, as for the rest I have no opinion.\n>\n>> I don't subscribe to the mailing list but hope that I'll receive the\n>> replies.\n>\n> Don't worry. The git mailing list doesn't munge the Reply-To header, so\n> any decent MUA will keep you in Cc.\n\nI noted that, thanks.\n\n> Cheers.\n>\n> --\n> Felipe Contreras\n>\n"},{"id":"413320","messageId":"5ff0ed59489bd_a76d2082f@natae.notmuch","threadId":"54918","inReplyTo":"CA+RLzGArUrxC-Kbng3qGpRZUrZXKZj3zD3Hcut=XrUY-i-eYAw@mail.gmail.com","subject":"Re: git-dir requires work-tree; documentation improvements for working directory","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-02T22:02:01Z","receivedAt":"2021-01-02T22:03:01Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Yaroslav Nikitenko wrote:\n> 2021-01-02 22:12 GMT+03:00, Felipe Contreras <felipe.contreras@gmail.com>:\n> > Yaroslav Nikitenko wrote:\n> >> I use git to manage my dotfiles with this command:\n> >>\n> >>     git --git-dir=/home/yaroslav/.cfg/ --work-tree=/home/yaroslav\n> >\n> > I do precisely the same thing.\n> >\n> >> When reading documentation, I noticed two issues.\n> >>\n> >> 1) The command doesn't work without --work-tree (even from the top\n> >> level directory, which is my home directory).\n> >>\n> >>     [~]$ git --git-dir=/home/yaroslav/.cfg/ status\n> >>     fatal: this operation must be run in a work tree\n> >\n> > That's weird. It works fine here (although I don't see why I would want\n> > that).\n> \n> BTW, how do you do that in your case?\n\nI have an alias:\n\n  alias config='git --git-dir=$HOME/.config/dotfiles/.git/ --work-tree=$HOME'\n\nSo, when I'm in my $HOME, I can do:\n\n  config status\n\n> > If you remove all your configuration does it still fail?\n> \n> It starts to work when I remove my .cfg/config. I've no idea why it\n> happens. Here is its contents:\n> \n> $ more .cfg/config\n> [core]\n> \trepositoryformatversion = 0\n> \tfilemode = true\n> \tbare = true\n\nThat's the difference: my core.bare is false.\n\nI do have a checked out work-tree because that's the only way I could\nget some commands to work, for example `git rebase`, even though I don't\nuse that work-tree.\n\nI'm not sure if it makes sense to not assume '.' is the work-tree when\n'core.bare=true', but I think it does make sense, so maybe just turn\nthat off.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"413329","messageId":"CA+RLzGCfqNdup1cmz3W4iBzbsxe9SD7E+Ju4svNFvhe6ohJqjA@mail.gmail.com","threadId":"54918","inReplyTo":"5ff0ed59489bd_a76d2082f@natae.notmuch","subject":"Re: git-dir requires work-tree; documentation improvements for working directory","fromName":"Yaroslav Nikitenko","fromEmail":"metst13@gmail.com","sentAt":"2021-01-03T09:12:22Z","receivedAt":"2021-01-03T09:16:43Z","isPatch":false,"sender":{"key":"metst13@gmail.com","avatar":null},"body":"2021-01-03 1:02 GMT+03:00, Felipe Contreras <felipe.contreras@gmail.com>:\n> Yaroslav Nikitenko wrote:\n>> 2021-01-02 22:12 GMT+03:00, Felipe Contreras\n>> <felipe.contreras@gmail.com>:\n>> > Yaroslav Nikitenko wrote:\n>> >> I use git to manage my dotfiles with this command:\n>> >>\n>> >>     git --git-dir=/home/yaroslav/.cfg/ --work-tree=/home/yaroslav\n>> >\n>> > I do precisely the same thing.\n>> >\n>> >> When reading documentation, I noticed two issues.\n>> >>\n>> >> 1) The command doesn't work without --work-tree (even from the top\n>> >> level directory, which is my home directory).\n>> >>\n>> >>     [~]$ git --git-dir=/home/yaroslav/.cfg/ status\n>> >>     fatal: this operation must be run in a work tree\n>> >\n>> > That's weird. It works fine here (although I don't see why I would want\n>> > that).\n>>\n>> BTW, how do you do that in your case?\n>\n> I have an alias:\n>\n>   alias config='git --git-dir=$HOME/.config/dotfiles/.git/\n> --work-tree=$HOME'\n>\n> So, when I'm in my $HOME, I can do:\n>\n>   config status\n\nThanks.\n\n>> > If you remove all your configuration does it still fail?\n>>\n>> It starts to work when I remove my .cfg/config. I've no idea why it\n>> happens. Here is its contents:\n>>\n>> $ more .cfg/config\n>> [core]\n>> \trepositoryformatversion = 0\n>> \tfilemode = true\n>> \tbare = true\n>\n> That's the difference: my core.bare is false.\n>\n> I do have a checked out work-tree because that's the only way I could\n> get some commands to work, for example `git rebase`, even though I don't\n> use that work-tree.\n>\n> I'm not sure if it makes sense to not assume '.' is the work-tree when\n> 'core.bare=true', but I think it does make sense, so maybe just turn\n> that off.\n>\n> Cheers.\n>\n> --\n> Felipe Contreras\n>\n\nThanks for the suggestion. I'd rather not change my config at the\nmoment. It's not difficult to provide work-tree in the alias.\n\nHowever, I think that this is a bug in the implementation or the\ndocumentation. It's not highlighted anywhere that the repository must\nbe non-bare for git-dir to work without explicit work-tree (an\nopposite is stated in general).\n\nShould I write a letter with [BUG] in its header for that to be noticed?\nI'm surprised why there is no issue tracker for git.\n\nCheers,\nYaroslav Nikitenko\n"},{"id":"413335","messageId":"5ff1b137e3eab_1c01e208a5@natae.notmuch","threadId":"54918","inReplyTo":"CA+RLzGCfqNdup1cmz3W4iBzbsxe9SD7E+Ju4svNFvhe6ohJqjA@mail.gmail.com","subject":"Re: git-dir requires work-tree; documentation improvements for working directory","fromName":"Felipe Contreras","fromEmail":"felipe.contreras@gmail.com","sentAt":"2021-01-03T11:57:43Z","receivedAt":"2021-01-03T11:58:44Z","isPatch":false,"sender":{"key":"felipe.contreras@gmail.com","avatar":"https://avatars.githubusercontent.com/u/8358?v=4"},"body":"Yaroslav Nikitenko wrote:\n> However, I think that this is a bug in the implementation or the\n> documentation. It's not highlighted anywhere that the repository must\n> be non-bare for git-dir to work without explicit work-tree (an\n> opposite is stated in general).\n\ncore.bare=true means no work-tree, so to me that behavior follows from\nthe documentation. But others might disagree.\n\n> Should I write a letter with [BUG] in its header for that to be noticed?\n\nThe mailing list is a little more quite than usual, probably due to the\nholidays.\n\nIf nobody else responds in a week, try again.\n\nCheers.\n\n-- \nFelipe Contreras\n"},{"id":"413390","messageId":"xmqqmtxo464l.fsf@gitster.c.googlers.com","threadId":"54918","inReplyTo":"CA+RLzGArUrxC-Kbng3qGpRZUrZXKZj3zD3Hcut=XrUY-i-eYAw@mail.gmail.com","subject":"Re: git-dir requires work-tree; documentation improvements for working directory","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2021-01-04T23:47:06Z","receivedAt":"2021-01-04T23:48:02Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Yaroslav Nikitenko <metst13@gmail.com> writes:\n\n> It starts to work when I remove my .cfg/config. I've no idea why it\n> happens. Here is its contents:\n>\n> $ more .cfg/config\n> [core]\n> \trepositoryformatversion = 0\n> \tfilemode = true\n> \tbare = true\n\nAs Felipe notes downthread, with \"core.bare=true\", the repository is\ntelling Git that it does not have a worktree.  The \"assume that $CWD\nis the top of the worktree\" default would have no room to kick in.\n\nWith --worktree=<there> option or GIT_WORK_TREE environment\nvariable, you can tell Git to pretend that there is a worktree there\nat the specified location.  Or perhaps \"git -c core.bare=false\", you\nmay be able to force the \"assume that $CWD is the top of the worktree\"\ndefault to kick in.\n\n\"git help git\" has this in --git-dir=<path>\n\n    Specifying the location of the \".git\" directory using this\n    option (or `GIT_DIR` environment variable) turns off the\n    repository discovery that tries to find a directory with\n    \".git\" subdirectory (which is how the repository and the\n    top-level of the working tree are discovered), and tells Git\n    that you are at the top level of the working tree.  If you\n    are not at the top-level directory of the working tree, you\n    should tell Git where the top-level of the working tree is,\n    with the `--work-tree=<path>` option (or `GIT_WORK_TREE`\n    environment variable)\n\nbut apparently the description forgets that there are repositories\nwith core.bare explicitly set to true.  There is a room for doc\nimprovement here.\n\nPerhaps something like this?\n\n Documentation/git.txt | 13 ++++++++-----\n 1 file changed, 8 insertions(+), 5 deletions(-)\n\ndiff --git c/Documentation/git.txt w/Documentation/git.txt\nindex c463b937a8..6f8225e3ef 100644\n--- c/Documentation/git.txt\n+++ w/Documentation/git.txt\n@@ -118,12 +118,15 @@ Specifying the location of the \".git\" directory using this\n option (or `GIT_DIR` environment variable) turns off the\n repository discovery that tries to find a directory with\n \".git\" subdirectory (which is how the repository and the\n-top-level of the working tree are discovered), and tells Git\n-that you are at the top level of the working tree.  If you\n-are not at the top-level directory of the working tree, you\n-should tell Git where the top-level of the working tree is,\n+top-level of the working tree are discovered), and if the\n+repository has a working tree, i.e. `core.bare` is `false`,\n+tells Git that you are at the top level of the working tree. If you\n+are not at the top-level directory of the working tree, or\n+if `core.bare` is set to `true` and you are trying to pretend\n+there is a working tree associated with the repository, you\n+can tell Git where the top-level of the working tree is,\n with the `--work-tree=<path>` option (or `GIT_WORK_TREE`\n-environment variable)\n+environment variable).\n +\n If you just want to run git as if it was started in `<path>` then use\n `git -C <path>`.\n"}]}