git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[bug report] git diff --relative not doing well with worktree in hooks

From
ABAntoine Bolvy <antoine.bolvy@gmail.com>
Date
May 31, 2024, 11:38 UTC
Message-ID
<CADg0FA_9shzJKN=dBfnavu5eTDNhbz=g0WP2sehAjSqHP4WFkA@mail.gmail.com>
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: Eric Sunshine
Message 1 of 5 in “[bug report] git diff --relative not doing well with worktree in hooks”
  1. Antoine BolvyMay 31, 2024
  2. Eric SunshineMay 31, 2024
  3. Antoine BolvyJun 3, 2024
  4. Phillip WoodJun 3, 2024
  5. Eric SunshineJun 3, 2024

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.