All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1 0/3] worktree: add post-worktree-add and post-worktree-remove hooks
@ 2026-07-09 23:36 Domen Kožar
  2026-07-10  9:34 ` Phillip Wood
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: Domen Kožar @ 2026-07-09 23:36 UTC (permalink / raw)
  To: git
  Cc: Eric Sunshine, Patrick Steinhardt,
	Ævar Arnfjörð Bjarmason, Caleb White,
	Junio C Hamano, Domen Kožar

Hi everyone,

I maintain devenv, a developer environment manager, and lately the
workflow we see most is people letting AI coding agents loose on a
repository, one linked worktree per task, created and discarded at a
pace no human would type. Each of those worktrees expects a working
environment: processes, sockets, and stateful services such as a
database seeded from a dump.

Today there is no reliable trigger to set that up when a worktree
appears: post-checkout does not fire for --no-checkout or --orphan
and cannot be told apart from a plain checkout. Nothing at all fires
when a worktree goes away, so stale databases and services pile up
after "git worktree remove" or a manual rm followed by "git worktree
prune". Wrapping the worktree commands only helps when every tool,
human or agent, goes through the wrapper.

Patch 1 adds a post-worktree-add hook that fires after the working
tree is fully set up. Patch 2 adds post-worktree-remove for "git
worktree remove". Patch 3 extends it to "git worktree prune" so that
manually deleted worktrees are also observed.

Two design points I would especially appreciate feedback on:

 * post-worktree-add runs after post-checkout and is skipped when
   post-checkout fails. An argument could be made that it should run
   whenever the worktree was created, regardless of the earlier
   hook's exit status, since tooling registering worktrees would
   otherwise miss one that does exist.

 * for entries pruned because their gitdir file points to a location
   that no longer exists, the hook receives the recorded path; when
   the path cannot be determined at all (missing or corrupt gitdir
   file) it receives an empty string.

Thanks,
Domen

Domen Kožar (3):
  worktree: add post-worktree-add hook
  worktree: add post-worktree-remove hook
  worktree: run post-worktree-remove hook when pruning

 Documentation/githooks.adoc |  41 +++++++++++++
 builtin/worktree.c          |  73 ++++++++++++++++++-----
 t/t2400-worktree-add.sh     | 113 ++++++++++++++++++++++++++++++++++++
 t/t2401-worktree-prune.sh   |  88 ++++++++++++++++++++++++++++
 t/t2403-worktree-move.sh    |  44 ++++++++++++++
 worktree.c                  |   1 -
 worktree.h                  |   6 +-
 7 files changed, 347 insertions(+), 19 deletions(-)


base-commit: f85a7e662054a7b0d9070e432508831afa214b47
-- 
2.54.0

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: [PATCH v2 0/4] worktree: add lifecycle hooks
@ 2026-08-11 20:26 <Alexander G. Riccio>
  0 siblings, 0 replies; 12+ messages in thread
From: <Alexander G. Riccio> @ 2026-08-11 20:26 UTC (permalink / raw)
  To: gitster; +Cc: git, domen, cdwhite3, phillip.wood123, ps, sunshine, avarab

(Apologies for replying out of thread -- I have never commented on the
git mailing list before, and I found this discussion in the archive
while looking into options for my own worktree hook needs)

I have a concrete example of a motivating workflow, indeed using
agentic development and proliferous worktrees. I figure it's worth
writing in to add support for this - I'm sure I'm not the only one out
there bumping into this problem in this current era, but git
developers can only know about it if we volunteer the information!

For me, I have disk space issues that relate from the interaction of
XCode derived data and worktrees. It apparently uses the absolute path
of the worktree for the per-project build state cache by default, and
of course it by default stores a lot of this data out-of-worktree. I
think I can change this configuration, but it's worth also noting that
about a half dozen other related tools do similar things, and none of
them have any way to know when the concomitant worktree is removed or
pruned. When I remove a worktree manually, I already have a dedicated
shell script to do cleanup like this, my script does a lot of very
useful things when it gets used!! The root problem remains, that we
cannot reliably count on agents to remember to do things we tell them
to do.

Currently, this means many gigabytes need to be cleaned up manually or
agentically every day, which is annoying, time consuming, and wastes
SSD writes.

Sadly, it seems like none of the third party tools will emit events
when someone or some-thing calls `git worktree remove` or `git
worktree prune`, so there's no solid way to implement this outside
native hooks expansions.

Sincerely,
Alexander Riccio
--
"Change the world or go home."

If left to my own devices, I will build more.

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

end of thread, other threads:[~2026-08-11 20:27 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
     [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>

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.