{"thread":{"id":"37644","subject":"`git log relative_path_to_object` does not respect the --work-tree path","startedAt":"2014-09-29T16:40:06Z","lastAt":"2014-09-30T12:42:15Z","messageCount":5,"participants":["Roberto Eduardo Decurnex Gorosito","Junio C Hamano","Jonathan Nieder"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"249994","messageId":"CABj5xzc0bVfyzR5PD5K3STSvdvWEOYeMkayB=GTfKbfij+G5Zw@mail.gmail.com","threadId":"37644","inReplyTo":null,"subject":"`git log relative_path_to_object` does not respect the --work-tree path","fromName":"Roberto Eduardo Decurnex Gorosito","fromEmail":"decurnex.roberto@gmail.com","sentAt":"2014-09-29T16:40:06Z","receivedAt":"2014-09-29T16:40:06Z","isPatch":false,"sender":{"key":"decurnex.roberto@gmail.com","avatar":"https://gravatar.com/avatar/de236c01ef687a6be0f8dfce2a4f380645a4d9436a700e7e6475c533e50f7c31?d=mp&s=160"},"body":"When passing objects to the `git log`, by just naming them or using\nthe `--objects` option, relative paths are evaluated using the current\nworking directory instead of the current working tree path.\n\nEven the error message is clearly wrong.\n    \"unknown revision or path not in the working tree.\"\n\nExample:\n\nGiven a repo at \"~/path/to_repo\" containing a file such as \"README.md\"\n(\"~/path/to_repo/README.md\")\n\n~/path$ git --work-tree=~/path/to_repo log README.md\nfatal: ambiguous argument 'README.md': unknown revision or path not in\nthe working tree.\n\nAs you can see here\n(https://github.com/robertodecurnex/git/blob/master/setup.c#L147) git\nis trying to `lstat` the path as it was given when it should validate\nthe file existence within the work tree (perpending the work-tree\nbefore the file name).\n\nNote: I now several workarounds for this, I'm not looking for a\nsolution to the specific problem but to discuss the implementation and\nevaluate a change over the current behavior.\n\nRegards,\n--\nRoberto Decurnex\n"},{"id":"250002","messageId":"xmqqy4t2ti75.fsf@gitster.dls.corp.google.com","threadId":"37644","inReplyTo":"CABj5xzc0bVfyzR5PD5K3STSvdvWEOYeMkayB=GTfKbfij+G5Zw@mail.gmail.com","subject":"Re: `git log relative_path_to_object` does not respect the --work-tree path","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2014-09-29T18:06:22Z","receivedAt":"2014-09-29T18:06:22Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Roberto Eduardo Decurnex Gorosito <decurnex.roberto@gmail.com>\nwrites:\n\n> ~/path$ git --work-tree=~/path/to_repo log README.md\n\nThis does not seem to specify GIT_DIR explicitly (either with the\n$GIT_DIR environment variable or the --git-dir option), so I would\nassume that you are sitting in a directory that has \".git/\"\nsubdirectory or a subdirectory of such a directory, but that \".git/\"\nis not a real repository that controls the working tree you have at\nthe ~/path/to_repo directory.\n\nThe --work-tree option and $GIT_WORK_TREE environment were primarily\ninvented to solve this problem:\n\n    When a user gives $GIT_DIR or --git-dir to disable the\n    repository discovery (i.e. trying to see if the current\n    directory has \".git/\" that looks like a repository, and if not\n    try the parent directory until we find one), traditionally we\n    assumed that the current directory is the top-level of the\n    corresponding working tree.  This makes it cumbersome to work\n    inside a subdirectory, and by allowing $GIT_WORK_TREE or\n    --work-tree to specify the top-level of the working tree,\n    working from a subdirectory of a working tree becomes usable\n    again.\n\nThat is why it does not mix very well with repository discovery\n(i.e.  letting Git crawl upward from the current directory to find a\ndirectory with \".git/\").  It is unclear if the auto-discovered\n\".git\" is the one to be be consulted for the \"log\" operation you\nasked, or the other repository you have at ~/path/to_repo/.git (or\none of its parent directories, e.g. ~/path/.git).  I _think_ the\ncurrent implementation randomly chose to use the auto-discovered\none, but it may have been better to forbid and always require both\n--git-dir and --work-tree to be given to avoid confusion.\n"},{"id":"250003","messageId":"CABj5xzdk38_W93kQAiS191XMp826endMdL9c5heCbLo9AZwA9w@mail.gmail.com","threadId":"37644","inReplyTo":"xmqqy4t2ti75.fsf@gitster.dls.corp.google.com","subject":"Re: `git log relative_path_to_object` does not respect the --work-tree path","fromName":"Roberto Eduardo Decurnex Gorosito","fromEmail":"decurnex.roberto@gmail.com","sentAt":"2014-09-29T18:11:00Z","receivedAt":"2014-09-29T18:11:00Z","isPatch":false,"sender":{"key":"decurnex.roberto@gmail.com","avatar":"https://gravatar.com/avatar/de236c01ef687a6be0f8dfce2a4f380645a4d9436a700e7e6475c533e50f7c31?d=mp&s=160"},"body":"Sorry, I left the --git-dir out of the example. I do set the --git-dir\n(and $GIT_DIR sometimes) too.\n\nIt gives the same results. That's why I feels like it shouldn't be\nworking as it is.\n\nIn this specific case (log with object filter) the environment config\nis completely ignored.\n\nOn Mon, Sep 29, 2014 at 3:06 PM, Junio C Hamano <gitster@pobox.com> wrote:\n> Roberto Eduardo Decurnex Gorosito <decurnex.roberto@gmail.com>\n> writes:\n>\n>> ~/path$ git --work-tree=~/path/to_repo log README.md\n>\n> This does not seem to specify GIT_DIR explicitly (either with the\n> $GIT_DIR environment variable or the --git-dir option), so I would\n> assume that you are sitting in a directory that has \".git/\"\n> subdirectory or a subdirectory of such a directory, but that \".git/\"\n> is not a real repository that controls the working tree you have at\n> the ~/path/to_repo directory.\n>\n> The --work-tree option and $GIT_WORK_TREE environment were primarily\n> invented to solve this problem:\n>\n>     When a user gives $GIT_DIR or --git-dir to disable the\n>     repository discovery (i.e. trying to see if the current\n>     directory has \".git/\" that looks like a repository, and if not\n>     try the parent directory until we find one), traditionally we\n>     assumed that the current directory is the top-level of the\n>     corresponding working tree.  This makes it cumbersome to work\n>     inside a subdirectory, and by allowing $GIT_WORK_TREE or\n>     --work-tree to specify the top-level of the working tree,\n>     working from a subdirectory of a working tree becomes usable\n>     again.\n>\n> That is why it does not mix very well with repository discovery\n> (i.e.  letting Git crawl upward from the current directory to find a\n> directory with \".git/\").  It is unclear if the auto-discovered\n> \".git\" is the one to be be consulted for the \"log\" operation you\n> asked, or the other repository you have at ~/path/to_repo/.git (or\n> one of its parent directories, e.g. ~/path/.git).  I _think_ the\n> current implementation randomly chose to use the auto-discovered\n> one, but it may have been better to forbid and always require both\n> --git-dir and --work-tree to be given to avoid confusion.\n>\n>\n>\n>\n>\n"},{"id":"250007","messageId":"20140929205612.GQ1175@google.com","threadId":"37644","inReplyTo":"CABj5xzc0bVfyzR5PD5K3STSvdvWEOYeMkayB=GTfKbfij+G5Zw@mail.gmail.com","subject":"Re: `git log relative_path_to_object` does not respect the --work-tree path","fromName":"Jonathan Nieder","fromEmail":"jrnieder@gmail.com","sentAt":"2014-09-29T20:56:12Z","receivedAt":"2014-09-29T20:56:12Z","isPatch":false,"sender":{"key":"jrnieder@gmail.com","avatar":"https://avatars.githubusercontent.com/u/281595?v=4"},"body":"Hi Roberto,\n\nRoberto Eduardo Decurnex Gorosito wrote:\n\n> When passing objects to the `git log`, by just naming them or using\n> the `--objects` option, relative paths are evaluated using the current\n> working directory instead of the current working tree path.\n\nWhy should they be relative to the worktree root?  When you use\nrelative paths within a worktree, they are not relative to the\nworktree root.  For example, the following works within a clone of\ngit.git:\n\n\t$ cd Documentation\n\t$ git log git.txt\n\nYou might be looking for 'git -C <directory>', which chdirs to the\nnamed directory so paths are relative to there.\n\nHope that helps,\nJonathan\n"},{"id":"250033","messageId":"CABj5xzdXZRorQu=8CBiYFt058kVQVzfFXSYzXDYofFN06u4Hpw@mail.gmail.com","threadId":"37644","inReplyTo":"20140929205612.GQ1175@google.com","subject":"Re: `git log relative_path_to_object` does not respect the --work-tree path","fromName":"Roberto Eduardo Decurnex Gorosito","fromEmail":"decurnex.roberto@gmail.com","sentAt":"2014-09-30T12:42:15Z","receivedAt":"2014-09-30T12:42:15Z","isPatch":false,"sender":{"key":"decurnex.roberto@gmail.com","avatar":"https://gravatar.com/avatar/de236c01ef687a6be0f8dfce2a4f380645a4d9436a700e7e6475c533e50f7c31?d=mp&s=160"},"body":"Ok. Yes, it 's kind of tricky. But the `-- <path>` does both things.\n\n`-- <path>` looks for the relative path within the current directory\nbut defaults to the work-tree root if your current directory does not\nbelong to the repo.\n\nAbout `git -C <dir>`, awesome feature, I love that, but it's not my\npoint. (and I'm actually maintaining the ruby-git gem, supporting git\n>= 1.6 T_T)\n\nI really appreciate your feedback.\n\nRegards,\n--\nRoberto Decurnex\n\nOn Mon, Sep 29, 2014 at 5:56 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:\n> Hi Roberto,\n>\n> Roberto Eduardo Decurnex Gorosito wrote:\n>\n>> When passing objects to the `git log`, by just naming them or using\n>> the `--objects` option, relative paths are evaluated using the current\n>> working directory instead of the current working tree path.\n>\n> Why should they be relative to the worktree root?  When you use\n> relative paths within a worktree, they are not relative to the\n> worktree root.  For example, the following works within a clone of\n> git.git:\n>\n>         $ cd Documentation\n>         $ git log git.txt\n>\n> You might be looking for 'git -C <directory>', which chdirs to the\n> named directory so paths are relative to there.\n>\n> Hope that helps,\n> Jonathan\n"}]}