Git development
 help / color / mirror / Atom feed
From: Maciej Ciemborowicz <maciej.ciemborowicz@gmail.com>
To: git@vger.kernel.org
Cc: Maciej Ciemborowicz <maciej.ciemborowicz@gmail.com>
Subject: [RFC] worktree: add lifecycle hooks
Date: Sun, 20 Sep 2026 19:33:33 +0200	[thread overview]
Message-ID: <20260920173333.1606-1-maciej.ciemborowicz@gmail.com> (raw)

Hello,

I'd like to discuss adding native hooks for worktree lifecycle events.

Git currently invokes `post-checkout` after `git worktree add` when a
checkout is performed. This makes it possible to detect some worktree
creation cases indirectly. There does not appear to be a native hook for
other worktree lifecycle operations such as:

    git worktree add
    git worktree remove
    git worktree move
    git worktree lock
    git worktree unlock
    git worktree prune

As a result, tools which want to react to these operations have to wrap
`git worktree` or compare the worktree state before and after a command.
They cannot observe an invocation which bypasses their wrapper.

One concrete use case is git-hooks-ext, which provides higher-level events
for Git operations. It currently has to implement worktree events by
wrapping `git worktree` and comparing the output of `git worktree list
--porcelain` before and after the command.

Would it make sense for Git to expose worktree lifecycle events directly?

One possibility would be separate post-operation hooks such as:

    post-worktree-add
    post-worktree-remove
    post-worktree-move
    post-worktree-lock
    post-worktree-unlock

Another possibility would be a single hook, similar in spirit to
`reference-transaction`, which reports worktree lifecycle changes. An
illustrative payload could look like:

    add    <path>
    remove <path>
    move   <old-path> <new-path>
    lock   <path>
    unlock <path>
    prune  <path>

A single hook may be useful for operations such as `git worktree prune`,
where one command can remove multiple administrative entries. It could
also leave room for `git worktree repair`, although I am unsure whether
repair belongs to the same interface.

For the use case I have in mind, these hooks would only need to notify
observers after a successful operation. They would not need to veto the
operation.

Before attempting an implementation, I'd like to know whether this would
fit Git's hook model, and whether a single lifecycle hook or individual
operation hooks would be preferable. I would also appreciate guidance on
whether a stable worktree identifier should be exposed in addition to the
path.

Thanks,
Maciej Ciemborowicz

             reply	other threads:[~2026-09-20 17:33 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-20 17:33 Maciej Ciemborowicz [this message]
2026-09-20 18:25 ` [RFC] worktree: add lifecycle hooks Kristoffer Haugsbakk
  -- strict thread matches above, loose matches on Subject: below --
2026-09-22 16:54 Michał Papis

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=20260920173333.1606-1-maciej.ciemborowicz@gmail.com \
    --to=maciej.ciemborowicz@gmail.com \
    --cc=git@vger.kernel.org \
    /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