Git development
 help / color / mirror / Atom feed
From: "Domen Kožar" <domen@cachix.org>
To: Junio C Hamano <gitster@pobox.com>
Cc: "Domen Kožar" <domen@cachix.org>,
	git@vger.kernel.org, "Caleb White" <cdwhite3@pm.me>,
	"Phillip Wood" <phillip.wood123@gmail.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Patrick Steinhardt" <ps@pks.im>,
	avarab@gmail.com, "Alexander G . Riccio" <test35965@gmail.com>
Subject: Re: [PATCH v2 0/4] worktree: add lifecycle hooks
Date: Sun, 30 Aug 2026 17:21:41 +0000	[thread overview]
Message-ID: <8bd3a684-51a0-4a2a-b70d-3981cfe10e9a@mtasv.net> (raw)
In-Reply-To: <xmqqtsp9tyu0.fsf@gitster.g>

Hi Junio,

Thanks for laying out the criteria for adding hooks.

> But for the hooks proposed in this topic, I do not think such an
> exception applies.

I agree that a wrapper is sufficient when all callers are under the
user's control. The problem I am trying to solve is that the component
which needs the notification does not control the component invoking
Git.

For example, devenv may register lifecycle handling for a repository,
but worktrees can subsequently be created or removed by an IDE, a
coding agent, another worktree tool, a script, or the user directly.
Requiring each of those callers to discover and use the same wrapper
makes the notification optional in practice. A repository hook provides
one place where that lifecycle behavior can be registered regardless of
which caller invokes Git.

"git worktree prune" is also difficult to reproduce reliably in a
wrapper. One invocation can remove zero or many administrative entries,
and Git knows exactly which entries it actually removes. A wrapper could
compare "git worktree list" before and after the command, but that is
not an authoritative event stream, can race another worktree operation,
and has limited information when an entry is already damaged.

Alexander provided another concrete example later in the thread: Xcode
and several related tools keep substantial path-keyed state outside the
worktree. Agents invoking "git worktree remove" or "git worktree prune"
directly leave many gigabytes of state behind even though a cleanup
wrapper exists. Phillip also mentioned having an unpublished add-hook
patch for copying per-worktree files such as config.mak.

That said, I take the point about avoiding a proliferation of hooks.
Instead of adding three separate hook names, would a single
"post-worktree" hook address that concern? It could use a fixed
interface such as:

    post-worktree add    <id> ""         <new-path>
    post-worktree move   <id> <old-path> <new-path>
    post-worktree remove <id> <old-path> ""

All paths would be absolute. Pruning would issue one "remove" event for
each entry actually pruned, and none under --dry-run. As with the
current series, the hook would only report an operation that has taken
effect and could not undo it.

This would also address Caleb's comment about passing information Git
already has rather than requiring the hook to query it, and it avoids
using the argument count to distinguish events.

Would that narrower interface, together with the need to observe
operations from callers that cannot be required to use a wrapper, meet
the bar for a native hook? If not, I would appreciate guidance before
spending time on a reroll.

Thanks,
Domen

  reply	other threads:[~2026-08-30 17:24 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 23:36 [PATCH v1 0/3] worktree: add post-worktree-add and post-worktree-remove hooks Domen Kožar
2026-07-10  9:34 ` Phillip Wood
     [not found]   ` <CAMvcdZS=ZYbLmjKaGJvjQ_fWYhVbOzwMvYq+MMENWPYi_RiqvQ@mail.gmail.com>
2026-07-13 13:19     ` Phillip Wood
2026-08-04 18:14 ` [PATCH v2 0/4] worktree: add lifecycle hooks Domen Kožar
2026-08-04 19:03   ` Caleb White
2026-08-04 20:28     ` Junio C Hamano
2026-08-30 17:21       ` Domen Kožar [this message]
2026-09-07 14:30         ` Domen Kožar
2026-09-07 18:18           ` Kristoffer Haugsbakk
2026-09-07 19:34             ` Domen Kožar
     [not found] ` <20260804181358.532970-1-domen@cachix.org>
2026-08-04 18:14   ` [PATCH v2 1/4] worktree: add post-worktree-add hook Domen Kožar
2026-08-04 20:03     ` Caleb White
2026-08-04 18:14   ` [PATCH v2 2/4] worktree: add post-worktree-remove hook Domen Kožar
2026-08-04 18:14   ` [PATCH v2 3/4] worktree: run post-worktree-remove hook when pruning Domen Kožar
2026-08-04 18:14   ` [PATCH v2 4/4] worktree: add post-worktree-move hook Domen Kožar
  -- strict thread matches above, loose matches on Subject: below --
2026-08-11 20:26 [PATCH v2 0/4] worktree: add lifecycle hooks <Alexander G. Riccio>

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=8bd3a684-51a0-4a2a-b70d-3981cfe10e9a@mtasv.net \
    --to=domen@cachix.org \
    --cc=avarab@gmail.com \
    --cc=cdwhite3@pm.me \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=phillip.wood123@gmail.com \
    --cc=ps@pks.im \
    --cc=sunshine@sunshineco.com \
    --cc=test35965@gmail.com \
    /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