CX2 [CRIT]: repo rename was clobbering unrelated CWD origins#2
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Data-loss-adjacent CRIT bug. Running
shithub repo rename foo -R owner/barfrom inside any git working tree with anoriginremote silently overwrote that origin to point atowner/bar, regardless of whether the CWD's origin had anything to do with the repo being renamed.Discovered by the C-audit subagent: its scratch-repo flow mutated
~/GithubOrgs/.../shithub-cli/.git/configwhile it ran, pointing my localoriginfromgit@github.com:tenseleyFlow/shithub-cli.gittohttps://shithub.sh/mfwolffe/cli-audit-1779046542-a.git. The auditor's findings doc (C7) recorded the symptom on its scratch end (Updated origin -> <old name>after a server-side no-op rename) but didn't connect it to host-side state corruption.Reproducer (pre-fix, clobbers origin):
Post-fix output:
Fix
In
pkg/cmd/repo/rename/rename.go, before callingSetRemoteURL, resolve the CWD's current origin and verify it points at the sameowner/namewe just renamed (case-insensitive). On mismatch, print anote:line explaining we skipped the rotation. Existing "origin matches → rotate" path is preserved.Test plan
TestRenameDoesNotClobberUnrelatedOrigin— regression test: real git tree withgit@example.com:other/unrelated.gitorigin surviveso/old → o/newnamerename, stderr explains.TestRenameRotatesMatchingOrigin— happy path: tree with origin matchingo/oldcorrectly rotates too/newname.TestRenamePatchesName+TestRenameRejectsSameNamestill pass.make cigreen locally.Notes for follow-up
This PR fixes the bug; it does NOT add the broader protection that should also exist:
pr checkoutadds a remote named after the fork owner in the CWD (line 213) — safer because it doesn't clobberorigin, but still mutates.git/configof whatever tree the user ran the command in. Worth a separate audit.repo renamereturning 200 unchanged on invalid names) is still open in the D1 server-side sub-sprint.