Repository navigation
Warn when the upstream remote isn't origin - #24299
Conversation
MikeMcQuaid
left a comment
There was a problem hiding this comment.
This seems potentially a bit error-prone than the existing status quo. This assumption is baked all over the place in the app. I'd suggest just using origin for Homebrew/brew instead?
Maybe, or we change all the assumed My acute problem can be solved easily now that I actually identified it: rename my branches. But as always: I'm interested in general solutions. And I didn't arrive at this situation by any arcane magic, I just cloned the repo and forked using the official |
Is there any way to configure the |
Probably yes. |
|
@HaraldNordgren Happy to rework this PR accordingly to that otherwise can close out. |
Aha, you meant to instruct gh to handle us differently? Well, I'll take a look and otherwise close it. |
Indeed or maybe even a e.g. |
413647b to
a79b3a2
Compare
originorigin
a79b3a2 to
114ff3a
Compare
- `gh repo fork` sets up the fork as `origin` and `Homebrew/brew` as `upstream`, so `--changed` compared against the fork's possibly stale default branch and `brew lgtm` checked every file changed upstream since then. - Have `brew doctor` and `brew lgtm` suggest renaming the remotes in that case, rather than `git remote set-url` replacing the fork. - Accept GitHub SSH origins, which `brew doctor` reported as non-standard.
114ff3a to
a7cb8c7
Compare
|
@MikeMcQuaid I turned it into a warning instead. |
There was a problem hiding this comment.
Actionable comments posted: 3
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
211fee93-08da-429b-a57f-a6dae71d040a
📒 Files selected for processing: 4
Library/Homebrew/dev-cmd/lgtm.rbLibrary/Homebrew/diagnostic.rbLibrary/Homebrew/test/dev-cmd/lgtm_spec.rbLibrary/Homebrew/test/diagnostic_checks_spec.rb
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.
- Compare remotes with `Tap.same_remote?`, keeping the `.git` suffix and trailing slash allowance for other hosts, so e.g. `githubXcom` no longer matches `github.com`. - Never suggest renaming `origin` itself, e.g. when `url.insteadOf` rewrites its URL. - Check the core tap against `$HOMEBREW_CORE_GIT_REMOTE` in `brew lgtm`, as `brew doctor` does.
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to GitHub limitations.
🟡 Minor · Use a collision-free temporary remote when swapping remote names. · diagnostic.rb:214-234
Library/Homebrew/diagnostic.rb:214-234
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick winUse a collision-free temporary remote when swapping remote names.
When both
originand the matchingforkremote exist, both remediation commands fail because each destination name is already occupied. The matching remote does not becomeorigin.Suggested fix
elsif desired_remote + remote_names = remotes.map { |line| line.split.first }.compact.uniq + temporary_remote = "homebrew-temp" + suffix = 0 + while remote_names.include?(temporary_remote) + suffix += 1 + temporary_remote = "homebrew-temp-#{suffix}" + end + Finding.new( @@ - git -C "#{repository_path}" remote rename origin fork - git -C "#{repository_path}" remote rename #{desired_remote} origin + git -C "#{repository_path}" remote rename #{desired_remote} #{temporary_remote} + git -C "#{repository_path}" remote rename origin #{desired_remote} + git -C "#{repository_path}" remote rename #{temporary_remote} origin @@ - "git -C \"#{repository_path}\" remote rename origin fork", - "git -C \"#{repository_path}\" remote rename #{desired_remote} origin", + "git -C \"#{repository_path}\" remote rename #{desired_remote} #{temporary_remote}", + "git -C \"#{repository_path}\" remote rename origin #{desired_remote}", + "git -C \"#{repository_path}\" remote rename #{temporary_remote} origin",
ℹ️ Review info
⚙️ Run configuration
- Configuration used: Organization UI
- Review profile: CHILL
- Plan: Advanced
- Run ID:
51bb17f4-7c5f-4dd2-906f-2608f9680b7c
📒 Files selected for processing: 4
Library/Homebrew/dev-cmd/lgtm.rbLibrary/Homebrew/diagnostic.rbLibrary/Homebrew/test/dev-cmd/lgtm_spec.rbLibrary/Homebrew/test/diagnostic_checks_spec.rb
🚧 Files skipped from review as they are similar to previous changes: 4
- Library/Homebrew/dev-cmd/lgtm.rb
- Library/Homebrew/test/diagnostic_checks_spec.rb
- Library/Homebrew/test/dev-cmd/lgtm_spec.rb
- Library/Homebrew/diagnostic.rb
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 8 remain after this review.
Homebrew assumes
originisHomebrew/brew:brew updatefetches from it, and the--changedoptions (and sobrew lgtm) compare against the merge-base withorigin/HEAD.gh repo forksets things up the other way round, with the fork asoriginandHomebrew/brewasupstream, both with--cloneand when run inside an existing clone. If the fork's default branch is behind,brew lgtmthen checks every file changed upstream since then, without saying why.This makes
brew doctorandbrew lgtmdetect that layout, whereoriginisn't the expected repository but another remote is, and suggest renaming the remotes:brew lgtmshows it before running any checks, for the brew repository or an official tap.brew doctoralready flagged a non-standard origin, but it suggestedgit remote set-url origin https://github.com/Homebrew/brew, which would replace the fork's URL, and it also reported SSH origins likegit@github.com:Homebrew/brew.gitas non-standard. Both are fixed here.This replaces the earlier version of this PR, which made
--changedlook for theHomebrew/brewremote by URL.How I got here
brew lgtmhad been failing for me while installing formulae, before it got to any checks. My checkout had the layoutgh repo forkcreates:originwas my fork, whoseorigin/HEADpointed at amasterfrom August, about 1,450 commits behind, andupstreamwasHomebrew/brew. So--changedsaw about 1,700 changed files, 54 of them shell or workflow files.brew stylethen neededshfmt, and because mine was outdated,./bin/brewtried to buildgofrom source on my macOS 12 machine and failed.Once I realised why, I renamed my remotes so that
originisHomebrew/brew:After that,
brew lgtmran cleanly without installing anything. With this change,brew lgtmwould have told me what to rename straight away.Steps to reproduce
Homebrew/brew, rungh repo fork --remote(or usegh repo fork Homebrew/brew --clone), with a fork whose default branch is behindHomebrew/brew.git switch -c some-change upstream/mainand change one Ruby file, e.g.Library/Homebrew/utils/git.rb../bin/brew lgtmchecks every file changed upstream since the fork's default branch, and./bin/brew doctorsuggestsgit remote set-url origin https://github.com/Homebrew/brew, which would replace the fork's URL.Changes
brew doctor: whenoriginisn't the expected repository but another remote is, suggest renaming the remotes rather thangit remote set-url. Accept GitHub SSH URLs fororigin.brew lgtm: show the same warning for the brew repository or an official tap before running any checks.brew benchmarkresults.brewcommands to reproduce the bug?brew lgtm(style, typechecking and tests) locally?Claude Code (Claude Opus 5.5) helped trace why
brew lgtmwas installing formulae and write the change and specs. The new specs fail without the change and pass with it, andbrew lgtmpasses locally.Summary by CodeRabbit
brew lgtmnow checks Git origins for repositories outside taps and for core and official taps, warning when an origin does not match the expected repository.origin; otherwise, it retains the existing guidance for correcting the origin URL.