# bug report

2 messages from 2022-12-25 to 2022-12-25. Participants: Eyal Post, Eric Sunshine.
Thread: https://gitlist.dev/t/59002

## Eyal Post, 2022-12-25 17:26

Subject: bug report
Message-ID: <CAL_N1vv1KqojvaS7TSeJ1JnUfO=cSzfUNMhGzgLi2pLUrmMWxQ@mail.gmail.com>
URL: https://gitlist.dev/e/CAL_N1vv1KqojvaS7TSeJ1JnUfO%3DcSzfUNMhGzgLi2pLUrmMWxQ%40mail.gmail.com

```
What did you do before the bug happened? (Steps to reproduce your issue)
1. I have a script which creates a git worktree and checks out a few
files from the master branch
2. When this script runs "stand alone" - everything works fine
3. When this script runs from a "pre-commit" hook it fails with an
error: "fatal: Unable to create '/tmp/wt-1/.git/index.lock': Not a
directory"

The content of the script is (simplified example):
git worktree add /tmp/wt-1 master --no-checkout --detach
cd /tmp/wt-1
git checkout master .


What did you expect to happen? (Expected behavior)
I would expect the script to run just fine as part of the pre-commit hook

What happened instead? (Actual behavior)
An error about .git not being a directory is shown

What's different between what you expected and what actually happened?
An error instead of completing successfully

Anything else you want to add:

Please review the rest of the bug report below.
You can delete any lines you don't wish to share.


[System Info]
git version:
git version 2.39.0
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
feature: fsmonitor--daemon
uname: Darwin 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:25:27
PDT 2022; root:xnu-8020.141.5~2/RELEASE_X86_64 x86_64
compiler info: clang: 14.0.0 (clang-1400.0.29.202)
libc info: no libc information available
$SHELL (typically, interactive shell): /bin/zsh


[Enabled Hooks]
pre-commit

```

## Eric Sunshine, 2022-12-25 18:12

Subject: Re: bug report
Message-ID: <CAPig+cQEC6CAV-Es9Ok96s8Cj=Dj76PRyOt4qKQus+rppswuyA@mail.gmail.com>
URL: https://gitlist.dev/e/CAPig%2BcQEC6CAV-Es9Ok96s8Cj%3DDj76PRyOt4qKQus%2BrppswuyA%40mail.gmail.com
In-Reply-To: <CAL_N1vv1KqojvaS7TSeJ1JnUfO=cSzfUNMhGzgLi2pLUrmMWxQ@mail.gmail.com>

```
On Sun, Dec 25, 2022 at 12:48 PM Eyal Post <eyalpost@gmail.com> wrote:
> 1. I have a script which creates a git worktree and checks out a few
> files from the master branch
> 2. When this script runs "stand alone" - everything works fine
> 3. When this script runs from a "pre-commit" hook it fails with an
> error: "fatal: Unable to create '/tmp/wt-1/.git/index.lock': Not a
> directory"
>
> The content of the script is (simplified example):
> git worktree add /tmp/wt-1 master --no-checkout --detach

This was previously reported[1]. Based upon a quick scan of that old
email thread, I'm not sure we ever came to a final conclusion about
whether Git could address this case itself[2] without breaking
existing workflows or if it should be the hook's responsibility[3].
Perhaps try having your hook script unset environment variables as
explained in [3], or at minimum unset GIT_INDEX_FILE. Also, perhaps
this advice[4] applies and you can take a simpler, less heavyweight
approach to whatever your hook is doing.

[1]: https://lore.kernel.org/git/CAJFQqN+Z9eX6onaj8vVSqpvf-nOC7-Y0Un4NLUie6x6bGfmvZA@mail.gmail.com/
[2]: https://lore.kernel.org/git/20190517011941.GA30372@sigill.intra.peff.net/
[3]: https://lore.kernel.org/git/20190516221702.GA11784@sigill.intra.peff.net/
[4]: https://lore.kernel.org/git/CAGyf7-GtnCqfqPWVpBAELB4xAE6syn7+DfKXgfhL0UoMfvbn4A@mail.gmail.com/

```
