From: Antoine Bolvy <antoine.bolvy@gmail.com>
To: git@vger.kernel.org
Subject: [bug report] git diff --relative not doing well with worktree in hooks
Date: Fri, 31 May 2024 13:38:40 +0200 [thread overview]
Message-ID: <CADg0FA_9shzJKN=dBfnavu5eTDNhbz=g0WP2sehAjSqHP4WFkA@mail.gmail.com> (raw)
Hello,
I noticed a weird behavior when using git diff --relative with worktrees and
hooks. When called from a pre-commit hook from a worktree, the relative option
has no effect.
Here is how to reproduce the issue:
```bash
mkdir hook-repro && cd hook-repro
git init test && cd test
mkdir folder && touch folder/.gitkeep && git add folder
git commit -m 'init'
cat <<EOF > .git/hooks/pre-commit
#!/bin/bash
cd folder || exit
pwd # display the current working directory
git diff --cached --relative --name-only
EOF
chmod +x .git/hooks/pre-commit
```
```bash
echo "foo" > folder/bar
git add folder
git commit -m "test"
```
Displays
```
/home/arch/git/awfus/hook-repro/test/folder
bar
```
Now creating a worktree:
```bash
git worktree add ../worktree && cd ../worktree
echo "bar" > folder/foo
git add folder
git commit -m "worktree"
```
Displays
```
/home/arch/git/awfus/hook-repro/worktree/folder
folder/foo
```
The path is no longer show relative. This causes issues with more complex
scripts.
Git version: 2.45.0 (x86_64) on Arch Linux, shell is zsh (bash for the hook
script)
Let me know if you need any more information :)
next reply other threads:[~2024-05-31 11:38 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-31 11:38 Antoine Bolvy [this message]
2024-05-31 21:42 ` [bug report] git diff --relative not doing well with worktree in hooks Eric Sunshine
2024-06-03 8:38 ` Antoine Bolvy
2024-06-03 9:29 ` Phillip Wood
2024-06-03 21:59 ` Eric Sunshine
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='CADg0FA_9shzJKN=dBfnavu5eTDNhbz=g0WP2sehAjSqHP4WFkA@mail.gmail.com' \
--to=antoine.bolvy@gmail.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).