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

Git hooks don't run while commiting in worktree via git-gui

From
ИМИван Могиш <ivan.mogish@playrix.com>
Date
Dec 18, 2018, 13:46 UTC
Message-ID
<CACu3VMWJ_otp2D6Tu_2adq=J2wcj0nsYhsW5oWxmbidb3afuyg@mail.gmail.com>

Hello. There is a little difference in behavior when you are committing to the worktree from CLI or some git client (tortoisegit/sourcetree) and embedded git gui.

If you configure git hooks in your repository and then add a worktree (via git worktree add), hooks from main repository works well both in main directory and in worktree, if you are using CLI/third-party GUI. Committing in the main directory via embedded git-gui works fine too, hooks are running. But when you try to commit in the worktree directory from git-gui, hooks don't work.

I think I've found the cause of this: https://github.com/git/git/blob/master/git-gui/lib/commit.tcl#L238 variable fd equals {} because proc githook_read calls proc gitdir to determine path to hooks. https://github.com/git/git/blob/master/git-gui/git-gui.sh#L626 This proc use variable _gitdir for calculating result. This var equals the result of executing git rev-parse --git-dir https://github.com/git/git/blob/master/git-gui/git-gui.sh#L1245 So, the path to hooks for worktree is path_to_main_repo/.git/worktrees/my_worktree/hooks, but there are no hooks. Hooks are in path_to_main_repo/.git/hooks, from where they are correctly (or not?) executed by git cli, while running from worktree directory.

If we put hooks to path_to_main_repo/.git/worktrees/my_worktree/hooks too, they will work both in git citool and CLI/third-party GUI. But they will execute different files, and it may cause some problems.

-- 
Ivan Mogish
Support Engineer
Phone: +9115212057
Next: Johannes Schindelin
Message 1 of 3 in “Git hooks don't run while commiting in worktree via git-gui”
  1. Иван МогишDec 18, 2018
  2. Johannes SchindelinDec 18, 2018
  3. Stephen P. SmithDec 19, 2018

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.