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

Re: [PATCH v2 0/4] worktree: add lifecycle hooks

From
Domen Kožar <domen@cachix.org>
Date
Aug 30, 2026, 17:21 UTC
Message-ID
<8bd3a684-51a0-4a2a-b70d-3981cfe10e9a@mtasv.net>
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

Previous: Junio C HamanoNext: Domen Kožar
Message 6 of 21 in “worktree: add post-worktree-add and post-worktree-remove hooks”
  1. 0/3 worktree: add post-worktree-add and post-worktree-remove hooksDomen Kožar, Jul 9, 2026
  2. Phillip WoodJul 10, 2026
  3. 0/4 worktree: add lifecycle hooksDomen Kožar, Aug 4, 2026
  4. Caleb WhiteAug 4, 2026
  5. Junio C HamanoAug 4, 2026
  6. Domen KožarAug 30, 2026
  7. Domen KožarSep 7, 2026
  8. Kristoffer HaugsbakkSep 7, 2026
  9. Domen KožarSep 7, 2026
  10. Maciej CiemborowiczOct 3, 2026
  11. 0/2 worktree: add post-worktree lifecycle hookDomen Kožar, Oct 4, 2026
  12. Junio C HamanoOct 5, 2026
  13. Phillip WoodJul 13, 2026
  14. 1/4 worktree: add post-worktree-add hookDomen Kožar, Aug 4, 2026
  15. Caleb WhiteAug 4, 2026
  16. 4/4 worktree: add post-worktree-move hookDomen Kožar, Aug 4, 2026
  17. 2/4 worktree: add post-worktree-remove hookDomen Kožar, Aug 4, 2026
  18. 3/4 worktree: run post-worktree-remove hook when pruningDomen Kožar, Aug 4, 2026
  19. 1/2 worktree: add post-worktree lifecycle hookDomen Kožar, Oct 4, 2026
  20. Phillip WoodOct 6, 2026
  21. 2/2 worktree: notify post-worktree hook when pruningDomen Kožar, Oct 4, 2026

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.