diff --git a/docs/components/github-pull-requests.md b/docs/components/github-pull-requests.md index b2e209fa..166c03b8 100644 --- a/docs/components/github-pull-requests.md +++ b/docs/components/github-pull-requests.md @@ -15,9 +15,9 @@ with a worktree's branch and exposes its status and actions. It works through th itself. If a repository has multiple GitHub remotes, Prowl checks each remote for a PR on -the worktree branch. `upstream` is preferred, other named remotes come next, and -`origin` is used as the fallback, so fork-based worktrees can show upstream PRs -without changing `origin` or restarting the app. +the worktree branch. `origin` is preferred, `upstream` comes next, and other +named remotes are used alphabetically, so fork-based worktrees can show upstream +PRs without changing `origin` or restarting the app. ## What it shows diff --git a/supacode/Clients/Git/GitClient.swift b/supacode/Clients/Git/GitClient.swift index 96a418c2..62ee7def 100644 --- a/supacode/Clients/Git/GitClient.swift +++ b/supacode/Clients/Git/GitClient.swift @@ -544,6 +544,10 @@ struct GitClient { if lhsPriority != rhsPriority { return lhsPriority < rhsPriority } + let nameComparison = lhs.element.name.localizedStandardCompare(rhs.element.name) + if nameComparison != .orderedSame { + return nameComparison == .orderedAscending + } return lhs.offset < rhs.offset } .compactMap { entry in @@ -562,12 +566,12 @@ struct GitClient { nonisolated private static func githubPullRequestRemotePriority(_ name: String) -> Int { switch name.lowercased() { - case "upstream": - 0 case "origin": - 2 - default: + 0 + case "upstream": 1 + default: + 2 } } diff --git a/supacodeTests/GitRemoteInfoTests.swift b/supacodeTests/GitRemoteInfoTests.swift index be87cbc7..576b7430 100644 --- a/supacodeTests/GitRemoteInfoTests.swift +++ b/supacodeTests/GitRemoteInfoTests.swift @@ -61,15 +61,17 @@ struct GitRemoteInfoTests { let fork = GithubRemoteInfo(host: "github.com", owner: "fork", repo: "project") let upstream = GithubRemoteInfo(host: "github.com", owner: "upstream", repo: "project") let team = GithubRemoteInfo(host: "github.com", owner: "team", repo: "project") + let zed = GithubRemoteInfo(host: "github.com", owner: "zed", repo: "project") let duplicateTeam = GithubRemoteInfo(host: "github.com", owner: "TEAM", repo: "project") let infos = GitClient.prioritizedGithubRemoteInfos([ + (name: "zed", info: zed), + (name: "upstream", info: upstream), (name: "origin", info: fork), (name: "team", info: team), - (name: "upstream", info: upstream), - (name: "backup", info: duplicateTeam), + (name: "zz-team", info: duplicateTeam), ]) - #expect(infos == [upstream, team, fork]) + #expect(infos == [fork, upstream, team, zed]) } }