{"thread":{"id":"47352","subject":"Git stash (or git rev-parse) doesn't inherit the '--work-tree' parameter","startedAt":"2017-11-30T07:02:37Z","lastAt":"2017-12-04T10:56:04Z","messageCount":2,"participants":["marc PINHEDE","Jacob Keller"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"333836","messageId":"CAJsT1ck6dCPLLMLjgq9jrQmOAC-6jF6kFEX6aaRJGw3Hn9He=w@mail.gmail.com","threadId":"47352","inReplyTo":null,"subject":"Git stash (or git rev-parse) doesn't inherit the '--work-tree' parameter","fromName":"marc PINHEDE","fromEmail":"marc.pinhede@gmail.com","sentAt":"2017-11-30T07:02:10Z","receivedAt":"2017-11-30T07:02:37Z","isPatch":false,"sender":{"key":"marc.pinhede@gmail.com","avatar":null},"body":"Hello guys,\n\nI don't know if this is a normal behavior, so I'll just explain it here.\n\n* Behavior:\n\nfrom a directory OUTSIDE my git repo, I can run this command successfully:\n $ git --git-dir=/my/repo/path/.git --work-tree=/my/repo/path pull origin master\n\nBut this one:\n $ git --git-dir=/my/repo/path/.git --work-tree=/my/repo/path stash\nWill fails with :\n 'fatal: $program_name cannot be used without a working tree.'\n(Yes, the error message has been corrected since, but I use debian, so\nI'm at least 6 month late).\n\n* A bit of investigation:\nI don't know many about git internal functioning, but with a bit of\ngoogleing, I would point out git-sh-setup.sh:204, in function\nrequire_work_tree, called by git-stash.\nI could test (from outside my git repo, again):\n git --git-dir=/my/repo/path/.git --work-tree=/my/repo/path rev-parse\n--is-inside-work-tree\nreturn:\n false\n\nWhat surprise me is that 'git-dir' seems to be passed ok to rev-parse:\n git --git-dir=/my/repo/path/.git --work-tree=/my/repo/path rev-parse --git-dir\nreturns:\n /my/repo/path/.git\n\n* Question\nIs this a normal behavior? Stash can only be applied in current\nworking directory?\nIf yes, I'll have to change my script to\n (cd && git command)\nIf not, should I push a bug report somewhere?\n\nMarc\n"},{"id":"334038","messageId":"70EAB5BC-F04B-475D-9F82-8CFDD7817C1F@gmail.com","threadId":"47352","inReplyTo":"CAJsT1ck6dCPLLMLjgq9jrQmOAC-6jF6kFEX6aaRJGw3Hn9He=w@mail.gmail.com","subject":"Re: Git stash (or git rev-parse) doesn't inherit the '--work-tree' parameter","fromName":"Jacob Keller","fromEmail":"jacob.keller@gmail.com","sentAt":"2017-12-04T10:55:52Z","receivedAt":"2017-12-04T10:56:04Z","isPatch":false,"sender":{"key":"jacob.keller@gmail.com","avatar":"https://avatars.githubusercontent.com/u/874719?v=4"},"body":"\n\nOn November 29, 2017 11:02:10 PM PST, marc PINHEDE <marc.pinhede@gmail.com> wrote:\n>Hello guys,\n>\n>I don't know if this is a normal behavior, so I'll just explain it\n>here.\n>\n>* Behavior:\n>\n>from a directory OUTSIDE my git repo, I can run this command\n>successfully:\n>$ git --git-dir=/my/repo/path/.git --work-tree=/my/repo/path pull\n>origin master\n>\n>But this one:\n> $ git --git-dir=/my/repo/path/.git --work-tree=/my/repo/path stash\n>Will fails with :\n> 'fatal: $program_name cannot be used without a working tree.'\n>(Yes, the error message has been corrected since, but I use debian, so\n>I'm at least 6 month late).\n>\n>* A bit of investigation:\n>I don't know many about git internal functioning, but with a bit of\n>googleing, I would point out git-sh-setup.sh:204, in function\n>require_work_tree, called by git-stash.\n>I could test (from outside my git repo, again):\n> git --git-dir=/my/repo/path/.git --work-tree=/my/repo/path rev-parse\n>--is-inside-work-tree\n>return:\n> false\n\nIt's possible that is-inside-worktree is testing if current dir is inside work tree, and not if the work tree variable is... Thus I wouldn't expect this to behave as you seem to expect.\n\n>\n>What surprise me is that 'git-dir' seems to be passed ok to rev-parse:\n>git --git-dir=/my/repo/path/.git --work-tree=/my/repo/path rev-parse\n>--git-dir\n>returns:\n> /my/repo/path/.git\n>\n>* Question\n>Is this a normal behavior? Stash can only be applied in current\n>working directory?\n>If yes, I'll have to change my script to\n> (cd && git command)\n>If not, should I push a bug report somewhere?\n>\n>Marc\n\n\nIt doesn't sound like normal behavior to me... Does \"git -C\" work?\n\nEither way id expect setting the work tree and got dir to work for most commands.\n\nHowever, it may not of the command expects current dir to matter. That's where using -C comes into play. Try that and see if it fixes your problem.\n\nThat is, git -C <path to work tree> stash\n\nThanks,\nJake\n\n-- \nSent from my Android device with K-9 Mail. Please excuse my brevity.\n"}]}