Re: Running 'git worktree add' in 'pre-commit' hook
- From
Duy Nguyen <pclouds@gmail.com>
- Date
- May 16, 2019, 11:41 UTC
- Message-ID
- <CACsJy8BXxVggL7CWA5Q0d7U4B+encfZ85NshxLJ=VvHhf_LUYg@mail.gmail.com>
- In-Reply-To
- <CAPig+cTQrF1W4LEgOiEoKn4f69OEygFat=4V8aTzf0Rxom2hEw@mail.gmail.com>
On Thu, May 16, 2019 at 6:33 PM Eric Sunshine <sunshine@sunshineco.com> wrote:
Show 13 quoted lines
> I researched this also and concluded that it's a bug in git-commit. > You run afoul of it in other situations, as well. For instance, say > you have your index file in a non-standard location: > > $ export GIT_INDEX_FILE=../storage/index > $ git worktree add --detach other > Preparing worktree (detached HEAD c9156d2) > fatal: Unable to create '/.../foo/other/../storage/index.lock': No > such file or directory > $ > > I think the correct fix is for git-commit to assign GIT_INDEX_FILE > with the absolute path to the index file, not a relative path.
Oh if it's relative $GIT_INDEX_FILE then I think its our environment.c code that does not work so well when we chdir() away. I vaguely recall something about this when discussing Jeff's chdir-notify series. But it turns out that's about chdir() in run-command.c [1]. But the idea is still the same, all variables are supposed to be relative to $CWD. Whenever you move $CWD you should reparent all of them, including $GIT_INDEX_FILE.
[1] https://public-inbox.org/git/CACsJy8CdqpNOw+zdMyugX-902Z=gLNij5_xcmE4jGLRBTqiO1g@mail.gmail.com/
-- Duy