{"thread":{"id":"50056","subject":"Git hooks don't run while commiting in worktree via git-gui","startedAt":"2018-12-18T13:47:09Z","lastAt":"2018-12-19T18:09:38Z","messageCount":3,"participants":["Иван Могиш","Johannes Schindelin","Stephen P. Smith"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"365533","messageId":"CACu3VMWJ_otp2D6Tu_2adq=J2wcj0nsYhsW5oWxmbidb3afuyg@mail.gmail.com","threadId":"50056","inReplyTo":null,"subject":"Git hooks don't run while commiting in worktree via git-gui","fromName":"Иван Могиш","fromEmail":"ivan.mogish@playrix.com","sentAt":"2018-12-18T13:46:56Z","receivedAt":"2018-12-18T13:47:09Z","isPatch":false,"sender":{"key":"ivan.mogish@playrix.com","avatar":null},"body":"Hello.\nThere is a little difference in behavior when you are committing to\nthe worktree from CLI or some git client (tortoisegit/sourcetree) and\nembedded git gui.\n\nIf you configure git hooks in your repository and then add a worktree\n(via git worktree add), hooks from main repository works well both in\nmain directory and in worktree, if you are using CLI/third-party GUI.\nCommitting in the main directory via embedded git-gui works fine too,\nhooks are running. But when you try to commit in the worktree\ndirectory from git-gui, hooks don't work.\n\nI think I've found the cause of this:\nhttps://github.com/git/git/blob/master/git-gui/lib/commit.tcl#L238\nvariable fd equals {} because proc githook_read calls proc gitdir to\ndetermine path to hooks.\nhttps://github.com/git/git/blob/master/git-gui/git-gui.sh#L626\nThis proc use variable _gitdir for calculating result. This var equals\nthe result of executing git rev-parse --git-dir\nhttps://github.com/git/git/blob/master/git-gui/git-gui.sh#L1245\nSo, the path to hooks for worktree is\npath_to_main_repo/.git/worktrees/my_worktree/hooks, but there are no\nhooks. Hooks are in path_to_main_repo/.git/hooks, from where they are\ncorrectly (or not?) executed by git cli, while running from worktree\ndirectory.\n\nIf we put hooks to path_to_main_repo/.git/worktrees/my_worktree/hooks\ntoo, they will work both in git citool and CLI/third-party GUI. But\nthey will execute different files, and it may cause some problems.\n-- \nIvan Mogish\nSupport Engineer\nPhone: +9115212057\n"},{"id":"365556","messageId":"nycvar.QRO.7.76.6.1812182254250.43@tvgsbejvaqbjf.bet","threadId":"50056","inReplyTo":"CACu3VMWJ_otp2D6Tu_2adq=J2wcj0nsYhsW5oWxmbidb3afuyg@mail.gmail.com","subject":"Re: Git hooks don't run while commiting in worktree via git-gui","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-12-18T21:56:43Z","receivedAt":"2018-12-18T21:57:02Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Ivan,\n\nOn Tue, 18 Dec 2018, Иван Могиш wrote:\n\n> Hello.\n> There is a little difference in behavior when you are committing to\n> the worktree from CLI or some git client (tortoisegit/sourcetree) and\n> embedded git gui.\n> \n> If you configure git hooks in your repository and then add a worktree\n> (via git worktree add), hooks from main repository works well both in\n> main directory and in worktree, if you are using CLI/third-party GUI.\n> Committing in the main directory via embedded git-gui works fine too,\n> hooks are running. But when you try to commit in the worktree\n> directory from git-gui, hooks don't work.\n> \n> I think I've found the cause of this:\n> https://github.com/git/git/blob/master/git-gui/lib/commit.tcl#L238\n> variable fd equals {} because proc githook_read calls proc gitdir to\n> determine path to hooks.\n> https://github.com/git/git/blob/master/git-gui/git-gui.sh#L626\n> This proc use variable _gitdir for calculating result. This var equals\n> the result of executing git rev-parse --git-dir\n> https://github.com/git/git/blob/master/git-gui/git-gui.sh#L1245\n> So, the path to hooks for worktree is\n> path_to_main_repo/.git/worktrees/my_worktree/hooks, but there are no\n> hooks. Hooks are in path_to_main_repo/.git/hooks, from where they are\n> correctly (or not?) executed by git cli, while running from worktree\n> directory.\n> \n> If we put hooks to path_to_main_repo/.git/worktrees/my_worktree/hooks\n> too, they will work both in git citool and CLI/third-party GUI. But\n> they will execute different files, and it may cause some problems.\n\nSounds like you need https://github.com/git-for-windows/git/pull/1757\n(we do not currently have a responsive maintainer for Git GUI,\nunfortunately, otherwise this patch would have made it into an official\nGit version already).\n\nThat patch also has the benefit of heeding core.hooksPath.\n\nCiao,\nJohannes\n\n> -- \n> Ivan Mogish\n> Support Engineer\n> Phone: +9115212057\n> "},{"id":"365586","messageId":"49862352.x4qs2Yizgb@thunderbird","threadId":"50056","inReplyTo":"nycvar.QRO.7.76.6.1812182254250.43@tvgsbejvaqbjf.bet","subject":"Re: Git hooks don't run while commiting in worktree via git-gui","fromName":"Stephen P. Smith","fromEmail":"ischis2@cox.net","sentAt":"2018-12-19T18:09:34Z","receivedAt":"2018-12-19T18:09:38Z","isPatch":false,"sender":{"key":"ishchis2@gmail.com","avatar":null},"body":"On Tuesday, December 18, 2018 2:56:43 PM MST Johannes Schindelin wrote:\n> Sounds like you need https://github.com/git-for-windows/git/pull/1757\n> (we do not currently have a responsive maintainer for Git GUI,\n> unfortunately, otherwise this patch would have made it into an official\n> Git version already).\n\nAre you talking about the version that is shipped with git for windows or the \nversion that is shipped with the main (Junio's) version?   \n\nToo bad I only get bits and pieces of time to contribute\n\n\n\n\n"}]}