refactor(git_utils): shared git-error panel printer + cwd= over chdir guards#596
refactor(git_utils): shared git-error panel printer + cwd= over chdir guards#596mattmillerai wants to merge 2 commits into
Conversation
Add `_print_git_error` and use it from both `git_checkout_tag` and `checkout_pr` except blocks, deduplicating the two structurally-identical rich error panels. Replace the `os.getcwd`/`os.chdir`/`finally` scaffolding in both functions with `cwd=repo_path` on every `subprocess.run` call. This removes process-global cwd mutation (safer for any future threaded/concurrent use) and drops the `import os` that only existed for the chdir dance.
|
Warning Review limit reachedYou’ve reached a temporary PR review limit under our Fair Usage Limits Policy. Next review available in: 32 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (2)
✨ Finishing Touches🧪 Generate unit tests (beta)
✨ Simplify code
Comment |
There was a problem hiding this comment.
🔍 Cursor Review — Consolidated panel
Triggered by @mattmillerai.
Found 1 finding(s).
| Severity | Count |
|---|---|
| 🟡 Medium | 1 |
Panel: 5/8 reviewers contributed findings.
Reviewers that did not contribute: kimi-k2.5:adversarial (empty), claude-opus-4-8-thinking-xhigh:edge-case (parse_error), kimi-k2.5:edge-case (empty)
…nt injection The fork-controlled PR head branch name (pr_info.head_branch, from the GitHub API and controllable by the PR author) was passed positionally to 'git fetch' on both the fork and non-fork paths. A name beginning with '-' would be parsed as a git option; 'comfy install --pr' runs against untrusted forks. Add a '--' end-of-options separator before the refspec and lock it in with regression assertions. Addresses cursor-review panel Medium finding (BE-4357). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
ELI-5
Two functions in
git_utils.py—git_checkout_tagandcheckout_pr— each did the same two clunky things: (1) built a nearly-identical fancy red error box by hand, and (2)cd-ed the whole process into the repo folder to run git, thencd-ed back in afinally. This PR pulls the error box into one shared helper, and tells eachgitcommand which folder to run in (cwd=) instead of changing the whole process's working directory. Same behavior, ~20 fewer lines per function, and no more globalcdthat could trip up concurrent use.What changed
_print_git_error(title, panel_title, context, details, exc)helper renders the shared rich errorPanel(bold-red title, bold-yellow context line, italic detail lines, optionalstderrblock). Bothexcept subprocess.CalledProcessErrorblocks now call it.cwd=repo_pathon everysubprocess.runcall in both functions, replacing theos.getcwd()/os.chdir(repo_path)/finally: os.chdir(original_dir)scaffolding.import osis now unused and removed.Why the
cwd=change matters (beyond dedup)os.chdirmutates process-global state. Passingcwd=per-call:os.chdir(repo_path)itself throws (e.g. missing dir) — there's no global state left to restore.Behavior is otherwise preserved: git commands still execute against
repo_path, and each function still returnsFalseon a git failure.Behavior note (judgment call)
The
checkout_prerror panel is byte-identical to before. Thegit_checkout_tagpanel has minor cosmetic differences on the failure path, which I consider a net improvement:Text.append(f"[cyan]{tag}[/cyan]"), butText.appenddoes not parse console markup — so users literally saw[cyan]v1.2.3[/cyan](brackets and all). It now shows a cleanv1.2.3in the header line.If exact byte-for-byte preservation of the old (buggy) tag panel is preferred, I can special-case it — but the current output reads better.
Testing
tests/comfy_cli/command/github/test_pr.py— the four mockedcheckout_prtests dropped their now-dead@patch("os.chdir")/@patch("os.getcwd")decorators and now assertcwd=repo_pathis passed to everysubprocess.run.TestGitCheckoutTag(real git repos, no chdir mocking) already exercises thecwd=path end-to-end.ruff checkclean.