git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* Git hooks don't run while commiting in worktree via git-gui
@ 2018-12-18 13:46 Иван Могиш
  2018-12-18 21:56 ` Johannes Schindelin
  0 siblings, 1 reply; 3+ messages in thread
From: Иван Могиш @ 2018-12-18 13:46 UTC (permalink / raw)
  To: git
  Cc: Дмитрий Яковлев

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

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Git hooks don't run while commiting in worktree via git-gui
  2018-12-18 13:46 Git hooks don't run while commiting in worktree via git-gui Иван Могиш
@ 2018-12-18 21:56 ` Johannes Schindelin
  2018-12-19 18:09   ` Stephen P. Smith
  0 siblings, 1 reply; 3+ messages in thread
From: Johannes Schindelin @ 2018-12-18 21:56 UTC (permalink / raw)
  To: Иван Могиш
  Cc: git,
	Дмитрий Яковлев

[-- Attachment #1: Type: text/plain, Size: 1941 bytes --]

Hi Ivan,

On Tue, 18 Dec 2018, Иван Могиш wrote:

> 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.

Sounds like you need https://github.com/git-for-windows/git/pull/1757
(we do not currently have a responsive maintainer for Git GUI,
unfortunately, otherwise this patch would have made it into an official
Git version already).

That patch also has the benefit of heeding core.hooksPath.

Ciao,
Johannes

> -- 
> Ivan Mogish
> Support Engineer
> Phone: +9115212057
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: Git hooks don't run while commiting in worktree via git-gui
  2018-12-18 21:56 ` Johannes Schindelin
@ 2018-12-19 18:09   ` Stephen P. Smith
  0 siblings, 0 replies; 3+ messages in thread
From: Stephen P. Smith @ 2018-12-19 18:09 UTC (permalink / raw)
  To: Johannes Schindelin
  Cc: Иван Могиш,
	git,
	Дмитрий Яковлев

On Tuesday, December 18, 2018 2:56:43 PM MST Johannes Schindelin wrote:
> Sounds like you need https://github.com/git-for-windows/git/pull/1757
> (we do not currently have a responsive maintainer for Git GUI,
> unfortunately, otherwise this patch would have made it into an official
> Git version already).

Are you talking about the version that is shipped with git for windows or the 
version that is shipped with the main (Junio's) version?   

Too bad I only get bits and pieces of time to contribute





^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2018-12-19 18:09 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-12-18 13:46 Git hooks don't run while commiting in worktree via git-gui Иван Могиш
2018-12-18 21:56 ` Johannes Schindelin
2018-12-19 18:09   ` Stephen P. Smith

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).