Repository navigation
fix(dg): pr diff runs outside a clone; pr checkout says it needs one - #672
Conversation
dg pr diff outside a git repository failed with E101 "report it", because git fetch had no repository to fetch into. It now fetches into a scratch repository when the current directory is not in one, as gh pr diff runs anywhere. dg pr checkout outside a repository now fails with E206 and says to clone first, instead of E101. Co-Authored-By: Claude Opus 5.5 <[email protected]>
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 17 minutes. View limit details
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. |
PastaPastaPasta
left a comment
There was a problem hiding this comment.
Verdict: approve
The fix is correct and small. dg pr diff now works outside a clone, and dg pr checkout fails with a clear E206 instead of E101. I built and ran pr::tests::diff_workdir_uses_the_repository_it_is_in_or_a_scratch_one at f46d76a: it passes.
Correctness of git rev-parse --git-dir (crates/dg/src/pr/mod.rs:4542, :4779). I checked it by hand. It succeeds in a subdirectory, in a linked worktree, in a bare repo, inside .git, and with GIT_DIR set from a non-repository directory. It fails only in a plain non-repository directory. That is the right test for diff, because git diff base...head works in a bare repo too. GIT_DIR reaches every git call that follows, so with it set dg uses that repository rather than a scratch one, as before.
Scratch lifetime. let (cwd, _scratch) = … is a named binding, not _, so the TempDir lives until diff returns. That covers both fetches, the final git diff and ctx.emit. Every ? path drops it as well.
Private repos. Nothing new is exposed. The key still goes to git only through read_env(ctx, private), the same way scratch_with_pr already sends it into a scratch bare repo for other commands. tempfile creates the directory 0700. One pre-existing gap: a SIGINT mid-fetch skips the drop, so the fetched objects stay in $TMPDIR. That already happens with scratch_with_pr and is not introduced here.
Nits (none blocking):
crates/dg/src/pr/mod.rs:5026: the new test sits betweencheckout_fixture's///doc comment and itsfn. The comment ("A repository onmain… returns the repository and the head oid") now documents the test, andcheckout_fixturehas none. Move the test above the comment or below the fixture.docs/errors.md:136-140(E206): the docs don't listdg pr checkoutoutside a repository as a cause, and "What to do" saysgit init/cd, while the new fix saysdg repo clone. One sentence would align them, for example: "dg pr checkoutoutside a git repository: clone the repository first (dg repo clone <repo>)."crates/dg/src/pr/mod.rs:4542: in a repository git rejects for dubious ownership (safe.directory),rev-parsefails. Checkout then says "needs a git repository" in a directory that is one, anddiffquietly falls back to a scratch repo. This is rare and the scratch fallback is harmless, but checkout could carry.cause()with git's stderr (git::git(...)instead ofgit_ok) so the real reason shows.- Optional: the checkout guard runs after
locate(), so a typo'd PR number outside a repo still costs the Platform reads first. Moving the cwd check abovelocatewould fail faster, and "nothing was fetched" would still hold.
The CHANGELOG Fixed entry is accurate. The diff is minimal and scoped, and leaving the merged-PR empty diff to #670 is reasonable.
🤖 Posted autonomously by Claude (claude-opus-5-5) on behalf of pasta.
…ck on its fn Co-Authored-By: Claude Opus 5.5 <[email protected]>
dg pr diff <repo> <n>run anywhere but inside a git repository failed with the "report it" error:gh pr diffworks from any directory, and reading a diff shouldn't need a clone.dg pr diff: when the current directory isn't in a git repository, it fetches into a scratch bare repository (the existingscratch_repo(), removed on drop). Inside a clone it still fetches there, so the objects are kept for next time.dg pr checkout: it does need a repository. Outside one it now fails with E206 and says to clone first, instead of E101.Live on testnet with this branch's build (
AyvEsSQ…/ux5-browse, PR #1), from an empty directory that isn't a repository:The directory is still empty afterwards. Unit test
diff_workdir_uses_the_repository_it_is_in_or_a_scratch_onecovers both cases. clippy-D warningsis clean, and the CHANGELOG has a Fixed entry.Not in scope: a merged PR's
dg pr diffis empty, because the base now contains the head. That is tracked in #670.Found in UX wave 5's CLI probe.
🤖 Generated with Claude Code