Skip to content

feat(gitutils): add git_clean to remove untracked files#1229

Merged
smoparth merged 1 commit into
python-wheel-build:mainfrom
tiran:git-clean
Jul 7, 2026
Merged

feat(gitutils): add git_clean to remove untracked files#1229
smoparth merged 1 commit into
python-wheel-build:mainfrom
tiran:git-clean

Conversation

@tiran

@tiran tiran commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator

Pull Request Description

What

add git_clean to remove untracked files from a working tree

Why

Some projects write files when the PEP 517 hook prepare_metadata_for_build_wheel is called, e.g. projects that unconditionally compile code in setup.py. Add a git_clean wrapper that runs git clean -xdf to restore a working tree to a pristine state after such hooks.

@tiran
tiran requested a review from a team as a code owner July 6, 2026 08:20
@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@tiran, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 43501c04-debd-45a2-82e9-d6cca5fe9ed6

📥 Commits

Reviewing files that changed from the base of the PR and between 96ab708 and 2c7f54b.

📒 Files selected for processing (2)
  • src/fromager/gitutils.py
  • tests/test_gitutils.py
📝 Walkthrough

Walkthrough

This pull request adds a new git_clean function to gitutils.py that removes untracked and ignored files from a git working tree by running git clean -xdf via external_commands.run, with a debug log statement. A corresponding unit test is added to test_gitutils.py, verifying the command invocation and working directory. No existing functionality is modified.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Related PRs

None identified.

Suggested labels: enhancement, tests

Suggested reviewers: None identified.

Poem
A rabbit hops through git's own den,
Sweeping stray files, now and then,
clean -xdf, quick and neat,
Untracked cruft swept off its feet,
A tidy warren, tests pass clean —
The tidiest burrow you've ever seen! 🐇

🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly matches the main change: adding git_clean to remove untracked files.
Description check ✅ Passed The description accurately describes the new git_clean helper and its purpose in restoring a pristine working tree.

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@mergify mergify Bot added the ci label Jul 6, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/fromager/gitutils.py (1)

143-152: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add a versionadded directive to the new public function's docstring.

git_clean is a new public API; per coding guidelines, user-facing changes should carry a Sphinx versionadded directive so it's tracked in the changelog/docs.

📝 Proposed docstring update
 def git_clean(source_dir: pathlib.Path) -> None:
     """Remove untracked files and directories from a git working tree.
 
     Runs ``git clean -xdf`` in *source_dir* to remove all untracked and
     ignored files, restoring the working tree to a pristine state.
+
+    .. versionadded:: <next-version>
     """
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/fromager/gitutils.py` around lines 143 - 152, Add a Sphinx versionadded
directive to the git_clean function docstring, since this new public API needs
to be documented as user-facing. Update the docstring in git_clean to include
the appropriate versionadded note alongside the existing summary and behavior
description, keeping the public API documentation consistent with the project’s
guidelines.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/fromager/gitutils.py`:
- Around line 143-152: Add a Sphinx versionadded directive to the git_clean
function docstring, since this new public API needs to be documented as
user-facing. Update the docstring in git_clean to include the appropriate
versionadded note alongside the existing summary and behavior description,
keeping the public API documentation consistent with the project’s guidelines.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 5e2030ee-11c4-4662-ad4b-b031edad18be

📥 Commits

Reviewing files that changed from the base of the PR and between c9ddc51 and 96ab708.

📒 Files selected for processing (2)
  • src/fromager/gitutils.py
  • tests/test_gitutils.py

…ing tree

Some projects write files when the PEP 517 hook
`prepare_metadata_for_build_wheel` is called, e.g. projects that
unconditionally compile code in setup.py. Add a `git_clean` wrapper
that runs `git clean -xdf` to restore a working tree to a pristine
state after such hooks.

Co-Authored-By: Claude <claude@anthropic.com>
Signed-off-by: Christian Heimes <cheimes@redhat.com>

@smoparth smoparth left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

Comment thread src/fromager/gitutils.py

@rd4398 rd4398 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM!

@mergify

mergify Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

@smoparth
smoparth merged commit e831624 into python-wheel-build:main Jul 7, 2026
39 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants