noirbizarre / noirbizarre/git-wipe
Skip worktrees with a live process inside them
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 5
- Forks
- 0
- Avg merge
- 2d 9m
- Merged PRs (30d)
- 1
Description
Problem
git sync decides a worktree is safe to remove from git state alone: is the branch merged, is the
tree dirty (Git::worktree_dirty, src/git.rs:829), does it have unmerged commits
(branch_has_unmerged_commits, src/git.rs:845), is it locked or too young
(worktree_guard, src/cleaner.rs:990).
None of that says whether someone is working in it right now. A worktree can be perfectly merged
and perfectly clean while a coding agent, a dev server, a test watcher or a build is running inside
it with uncommitted work still in memory. git sync -y removes it, and that work is gone.
This is increasingly common: agent harnesses create a worktree per session, commit and push, and
keep running. The branch reads merged, the tree reads clean, and we delete the ground from under
the session.
Proposal
Add a "busy" guard: a worktree whose path is the current working directory of a live process is
never removed, regardless of merge state, and regardless of --yes.
Whether to consult the process table at all is the user's decision, so this ships as a flag
plus a git-config setting rather than as unconditional behaviour:
--check-busy/--no-check-busy, mutuallyoverrides_witheach other — the same shape as the
existing--worktrunk/--no-worktrunkpair (src/cli.rs).sync.checkbusy(bool) in git-config.- Enabled by default. Precedence follows
resolve_worktrunk/resolve_effort
(src/main.rs:424-449): CLI flag > git config > default (true). Add aresolve_check_busy
next to them, exposesync.checkbusythroughgit sync config setand the config listing, and
offer it in the setup wizard only if it proves worth a question — otherwise leave it to config. - With
--no-check-busythe scan is skipped entirely, so users who do not want the process-table
read pay nothing and get exactly today's behaviour.
Detection:
- One process-table scan per run, not one per worktree, and only when the check is enabled.
- Linux: walk
/proc/*/cwdsymlinks. - macOS/BSD:
lsof -a -d cwd -Fnfallback. - Neither available: the guard simply never fires; classification carries on as today, without
an error (same degradation contract as the git >= 2.38merge_adds_nothingstrategy).
- Linux: walk
- Exclude interactive shells (
bash,zsh,fish,sh,nu, ...) — a terminal tab parked in a
finished worktree must not pin it forever. - Exclude
git-sync's own process ancestry, otherwise runninggit syncfrom inside a linked
worktree pins that worktree. - Add
WorktreeGuard::Busynext toLocked/TooYoung(src/cleaner.rs:963) with a skip
message naming the offending process (pid, comm) so the user can act. - Report it in JSON: a new
ItemStatus/ skip reason insrc/report.rs. --forcemay override it, consistent with the dirty/unmerged path — but plain--yesmust not.
Acceptance
- Busy worktree is skipped by
git sync -y, with a message identifying the process. -
--no-check-busyskips the scan entirely and restores today's behaviour. -
sync.checkbusy = falsehas the same effect;--check-busyoverrides it back on. - Absent flag and absent config → check is enabled.
- An idle
zshsitting in the worktree does not mark it busy. - Running
git syncfrom inside the worktree does not mark it busy. - Platform without
/procand withoutlsof: no error, no behaviour change. - Cost is one scan per invocation; measured on a repo with 20+ worktrees.
- Unit tests (spawn a
sleepwith cwd in a fixture worktree) + integration test + README
(usage flags table, configuration option table,git sync configdocs, man page).
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by tracing the existing flag and configuration resolution in src/cli.rs and src/main.rs:424-449, then inspect WorktreeGuard in src/cleaner.rs:963 and status reporting in src/report.rs. Run the existing unit and integration tests before adding platform-specific process detection and configuration coverage. Done means busy worktrees are skipped with process details, overrides behave as specified, unsupported platforms degrade silently, and the README and man page document the option.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- git, rust
- Domain
- cli, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100