Skip to content

test(core): stabilize dirty worktree removal on macOS #474

Description

@LeXwDeX

Why

packages/core/src/git.ts (worktreeRun, refusal classification) decides whether a refused git worktree remove requires --force by regex-matching hardcoded English prose against git's localized human-readable stderr. On this macOS host (Homebrew git 2.55.0 shipping a zh_CN translation catalog, LANG/LC_MESSAGES=zh_CN.UTF-8 inherited by the child process), git refuses with 致命错误:'…' 包含修改或未跟踪的文件,使用 --force 删除; the regex misses and clients receive forceRequired: false for a dirty worktree — wrong safety/remediation metadata. Proven by a single-variable reproduction matrix (same binary/fixture, locale flip → classification flip; LC_ALL=C and Apple git without catalog both classify correctly). Machine-readable worktree list --porcelain output is byte-identical across locales (cmp clean), making it the stable seam.

Scope

  • packages/core/src/git.ts — refusal classification only.
  • packages/core/test/project-copy.test.ts — regression coverage for tracked + untracked dirtiness.
  • No change to the force: true removal path; no gate weakened; clean-worktree removal unchanged.

Approach

Recompute forceRequired in worktreeRun from locale-stable signals only: operation === "remove" + refusal exit code 128 + dirtiness of the target worktree confirmed via porcelain output. The localized stderr prose is removed from classification entirely.

Acceptance

  • ProjectCopy > requires force to remove a dirty git worktree passes on a machine where the old code failed (ambient zh_CN locale), with regressions independently covering tracked-file and untracked-file dirtiness.
  • Full Core suite, typecheck, and lint green on macOS.
  • forceRequired: true contract intact: dirty worktree still reported as requiring force; clean worktree still removes without force.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions