noirbizarre / noirbizarre/git-wipe

Skip worktrees with a live process inside them

Open
#66 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement
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, mutually overrides_with each other — the same shape as the
    existing --worktrunk / --no-worktrunk pair (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 a resolve_check_busy
    next to them, expose sync.checkbusy through git sync config set and 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-busy the 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/*/cwd symlinks.
    • macOS/BSD: lsof -a -d cwd -Fn fallback.
    • Neither available: the guard simply never fires; classification carries on as today, without
      an error (same degradation contract as the git >= 2.38 merge_adds_nothing strategy).
  • 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 running git sync from inside a linked
    worktree pins that worktree.
  • Add WorktreeGuard::Busy next to Locked / 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 in src/report.rs.
  • --force may override it, consistent with the dirty/unmerged path — but plain --yes must not.

Acceptance

  • Busy worktree is skipped by git sync -y, with a message identifying the process.
  • --no-check-busy skips the scan entirely and restores today's behaviour.
  • sync.checkbusy = false has the same effect; --check-busy overrides it back on.
  • Absent flag and absent config → check is enabled.
  • An idle zsh sitting in the worktree does not mark it busy.
  • Running git sync from inside the worktree does not mark it busy.
  • Platform without /proc and without lsof: no error, no behaviour change.
  • Cost is one scan per invocation; measured on a repo with 20+ worktrees.
  • Unit tests (spawn a sleep with cwd in a fixture worktree) + integration test + README
    (usage flags table, configuration option table, git sync config docs, man page).

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.