{"thread":{"id":"66357","subject":"[RFC] worktree: add lifecycle hooks","startedAt":"2026-09-20T17:33:36Z","lastAt":"2026-09-20T18:26:10Z","messageCount":2,"participants":["Maciej Ciemborowicz","Kristoffer Haugsbakk"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"552914","messageId":"20260920173333.1606-1-maciej.ciemborowicz@gmail.com","threadId":"66357","inReplyTo":null,"subject":"[RFC] worktree: add lifecycle hooks","fromName":"Maciej Ciemborowicz","fromEmail":"maciej.ciemborowicz@gmail.com","sentAt":"2026-09-20T17:33:33Z","receivedAt":"2026-09-20T17:33:36Z","isPatch":false,"body":"Hello,\n\nI'd like to discuss adding native hooks for worktree lifecycle events.\n\nGit currently invokes `post-checkout` after `git worktree add` when a\ncheckout is performed. This makes it possible to detect some worktree\ncreation cases indirectly. There does not appear to be a native hook for\nother worktree lifecycle operations such as:\n\n    git worktree add\n    git worktree remove\n    git worktree move\n    git worktree lock\n    git worktree unlock\n    git worktree prune\n\nAs a result, tools which want to react to these operations have to wrap\n`git worktree` or compare the worktree state before and after a command.\nThey cannot observe an invocation which bypasses their wrapper.\n\nOne concrete use case is git-hooks-ext, which provides higher-level events\nfor Git operations. It currently has to implement worktree events by\nwrapping `git worktree` and comparing the output of `git worktree list\n--porcelain` before and after the command.\n\nWould it make sense for Git to expose worktree lifecycle events directly?\n\nOne possibility would be separate post-operation hooks such as:\n\n    post-worktree-add\n    post-worktree-remove\n    post-worktree-move\n    post-worktree-lock\n    post-worktree-unlock\n\nAnother possibility would be a single hook, similar in spirit to\n`reference-transaction`, which reports worktree lifecycle changes. An\nillustrative payload could look like:\n\n    add    <path>\n    remove <path>\n    move   <old-path> <new-path>\n    lock   <path>\n    unlock <path>\n    prune  <path>\n\nA single hook may be useful for operations such as `git worktree prune`,\nwhere one command can remove multiple administrative entries. It could\nalso leave room for `git worktree repair`, although I am unsure whether\nrepair belongs to the same interface.\n\nFor the use case I have in mind, these hooks would only need to notify\nobservers after a successful operation. They would not need to veto the\noperation.\n\nBefore attempting an implementation, I'd like to know whether this would\nfit Git's hook model, and whether a single lifecycle hook or individual\noperation hooks would be preferable. I would also appreciate guidance on\nwhether a stable worktree identifier should be exposed in addition to the\npath.\n\nThanks,\nMaciej Ciemborowicz\n"},{"id":"552915","messageId":"dd6815f4-30ac-4cc6-882e-e8c4eb0936cf@app.fastmail.com","threadId":"66357","inReplyTo":"20260920173333.1606-1-maciej.ciemborowicz@gmail.com","subject":"Re: [RFC] worktree: add lifecycle hooks","fromName":"Kristoffer Haugsbakk","fromEmail":"kristofferhaugsbakk@fastmail.com","sentAt":"2026-09-20T18:25:45Z","receivedAt":"2026-09-20T18:26:10Z","isPatch":false,"body":"On Sun, Sep 20, 2026, at 19:33, Maciej Ciemborowicz wrote:\n> Hello,\n>\n> I'd like to discuss adding native hooks for worktree lifecycle events.\n>\n> Git currently invokes `post-checkout` after `git worktree add` when a\n> checkout is performed. This makes it possible to detect some worktree\n> creation cases indirectly. There does not appear to be a native hook for\n> other worktree lifecycle operations such as:\n>\n>     git worktree add\n>     git worktree remove\n>     git worktree move\n>     git worktree lock\n>     git worktree unlock\n>     git worktree prune\n>[snip]\n\nSee https://lore.kernel.org/git/7c8b4673-37ac-45fa-ad8c-a1dc09afe5fe@mtasv.net/\n"}]}