Skip to content

fix(worktrees): ignore generated pre-commit config#252

Merged
Bad3r merged 2 commits into
mainfrom
fix/worktree-remove-precommit-config
May 17, 2026
Merged

fix(worktrees): ignore generated pre-commit config#252
Bad3r merged 2 commits into
mainfrom
fix/worktree-remove-precommit-config

Conversation

@Bad3r
Copy link
Copy Markdown
Owner

@Bad3r Bad3r commented May 17, 2026

Summary

  • Keep git-worktree-remove-safe.sh from refusing cleanup only because generated .pre-commit-config.yaml exists.
  • Filter exactly that generated file from ignored-status checks.
  • Preserve refusal behavior for all other dirty, untracked, or ignored worktree state.

Test plan

  • nix fmt --accept-flake-config --no-write-lock-file -- scripts/git-worktree-remove-safe.sh
  • bash -n scripts/git-worktree-remove-safe.sh
  • nix run --accept-flake-config --no-write-lock-file nixpkgs#shellcheck -- scripts/git-worktree-remove-safe.sh
  • git push pre-push hooks

git-worktree-remove-safe.sh checks ignored files before forcing submodule
worktree removal. Generated .pre-commit-config.yaml is expected in clean
worktrees and is recreated by the hook sync path, so it should not block
cleanup.

The filter is exact and leaves every other dirty, untracked, or ignored status
line visible to the refusal path.

Validation:
- nix fmt on scripts/git-worktree-remove-safe.sh
- bash -n scripts/git-worktree-remove-safe.sh
- nix run nixpkgs#shellcheck on scripts/git-worktree-remove-safe.sh
@Bad3r Bad3r added type(fix) Corrective change resolving broken behavior or wiring; mirrors fix(...) Conventional Commits. area(scripts) Operational scripts and command-line automation helpers. area(git) Repository sync, Git workflows, credentials, branches, or policy. focus(data-integrity) Sync correctness, conflict safety, durability, or integrity guarantees. labels May 17, 2026
@github-project-automation github-project-automation Bot moved this to Backlog in ❄️ NixOS May 17, 2026
@claude
Copy link
Copy Markdown
Contributor

claude Bot commented May 17, 2026

Claude finished @Bad3r's task in 2m 34s —— View job


Review

No issues found.
· fix/worktree-remove-precommit-config

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c07e5f4993

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread scripts/git-worktree-remove-safe.sh Outdated
Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the require_clean_worktree function in scripts/git-worktree-remove-safe.sh to ignore the .pre-commit-config.yaml file when determining if a worktree is dirty. The review feedback points out that this exclusion should also be applied to submodule status checks to fully achieve the intended goal. Additionally, it is recommended to export LC_ALL=C to ensure consistent Git output parsing across different environments.

Comment thread scripts/git-worktree-remove-safe.sh
The cleanup helper ignored every porcelain status for
`.pre-commit-config.yaml`. Worktrees with initialized submodules could pass the
preflight check and then hit the fallback `git worktree remove --force` path.
That could drop tracked edits reported as ` M .pre-commit-config.yaml` after
66ac9ba removed the tracked config.

Keep the exemption limited to `!! .pre-commit-config.yaml` and apply the same
filter inside submodule checks. Add a shell regression test for root ignored
configs, tracked root edits with submodules, and ignored submodule configs.

Validation:
- nix fmt --accept-flake-config --no-write-lock-file -- \
  scripts/git-worktree-remove-safe.sh tests/git-worktree-remove-safe/run.sh
- bash -n scripts/git-worktree-remove-safe.sh \
  tests/git-worktree-remove-safe/run.sh
- bash tests/git-worktree-remove-safe/run.sh
- nix run --accept-flake-config --no-write-lock-file nixpkgs#shellcheck -- \
  scripts/git-worktree-remove-safe.sh tests/git-worktree-remove-safe/run.sh
- git diff --check
@Bad3r
Copy link
Copy Markdown
Owner Author

Bad3r commented May 17, 2026

Addressed the valid review feedback in commit ec41260.

Accepted and implemented:

  • Restricted the root worktree exemption to the exact ignored porcelain status !! .pre-commit-config.yaml, so tracked edits such as M .pre-commit-config.yaml still block removal.
  • Applied the same ignored generated-file filter inside recursive submodule checks, so initialized submodules do not block cleanup solely because of generated .pre-commit-config.yaml state.
  • Added tests/git-worktree-remove-safe/run.sh to cover ignored root configs, tracked root edits in worktrees with submodules, and ignored submodule configs.

Rejected or already satisfied:

  • No extra LC_ALL=C change was needed because the helper already exports it at startup, and that environment is inherited by the git submodule foreach subprocess.

Reliability impact:

  • The helper now exempts only the generated ignored file while preserving the safety guarantee for tracked, untracked, and unrelated ignored state. The regression test exercises the force-removal fallback path that previously made the broad filter risky.

Validation run:

  • nix fmt --accept-flake-config --no-write-lock-file -- scripts/git-worktree-remove-safe.sh tests/git-worktree-remove-safe/run.sh
  • bash -n scripts/git-worktree-remove-safe.sh tests/git-worktree-remove-safe/run.sh
  • bash tests/git-worktree-remove-safe/run.sh
  • nix run --accept-flake-config --no-write-lock-file nixpkgs#shellcheck -- scripts/git-worktree-remove-safe.sh tests/git-worktree-remove-safe/run.sh
  • git diff --check

@Bad3r Bad3r merged commit fe8c33e into main May 17, 2026
1 check passed
@github-project-automation github-project-automation Bot moved this from Backlog to Done in ❄️ NixOS May 17, 2026
@Bad3r Bad3r deleted the fix/worktree-remove-precommit-config branch May 17, 2026 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area(git) Repository sync, Git workflows, credentials, branches, or policy. area(scripts) Operational scripts and command-line automation helpers. focus(data-integrity) Sync correctness, conflict safety, durability, or integrity guarantees. type(fix) Corrective change resolving broken behavior or wiring; mirrors fix(...) Conventional Commits.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant