@devries-cameron20 / t3code Mirror · read-only / commits / d3e0e8b8ab
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 00:45 UTC

refactor(shared): simplify remote branch filtering (#30456)

roxvi committed Nov 9, 2026 at 06:34 UTC d3e0e8b8ab6114274bd07c0f58cbc03edb1d2759
2 files changed +19 -37
apps/web/src/components/BranchToolbar.logic.test.ts
+16 -7
@@ -101,16 +101,23 @@ describe("deriveLocalBranchNameFromRemoteRef", () => {
101 });
102
103 describe("dedupeRemoteBranchesWithLocalMatches", () => {
104 - it("hides remote refs when the matching local ref exists", () => {
104 + it.each([
105 + ["feature/demo", "origin/feature/demo", true],
106 + ["feature/demo", "feature/demo", false],
107 + ["demo", "demo", true],
108 + ["origin/", "origin/", true],
109 + ["/demo", "/demo", true],
110 + ["", "", false],
111 + ])("filters origin ref %s / %s (hidden: %s)", (localName, remoteName, hidden) => {
112 const input: VcsRef[] = [
113 {
107 - name: "feature/demo",
114 + name: localName,
115 current: false,
116 isDefault: false,
117 worktreePath: null,
118 },
119 {
113 - name: "origin/feature/demo",
120 + name: remoteName,
121 isRemote: true,
122 remoteName: "origin",
123 current: false,
@@ -127,10 +134,12 @@ describe("dedupeRemoteBranchesWithLocalMatches", () => {
134 },
135 ];
136
130 - expect(dedupeRemoteBranchesWithLocalMatches(input).map((ref) => ref.name)).toEqual([
131 - "feature/demo",
132 - "origin/feature/remote-only",
133 - ]);
137 + const result = dedupeRemoteBranchesWithLocalMatches(input);
138 + const expected = hidden ? [input[0], input[2]] : input;
139 + expect(result).toEqual(expected);
140 + for (const [index, ref] of result.entries()) {
141 + expect(ref).toBe(expected[index]);
142 + }
143 });
144
145 it("keeps non-origin remote refs visible when git tracks with first-slash local naming", () => {
packages/shared/src/git.ts
+3 -30
@@ -280,26 +280,6 @@ export function parseOriginUrlFromGitConfig(configText: string): string | null {
280 return originUrl ?? firstRemoteUrl;
281 }
282
283 -function deriveLocalBranchNameCandidatesFromRemoteRef(
284 - branchName: string,
285 - remoteName?: string,
286 -): ReadonlyArray<string> {
287 - const candidates = new Set<string>();
288 - const firstSlashCandidate = deriveLocalBranchNameFromRemoteRef(branchName);
289 - if (firstSlashCandidate.length > 0) {
290 - candidates.add(firstSlashCandidate);
291 - }
292 -
293 - if (remoteName) {
294 - const remotePrefix = `${remoteName}/`;
295 - if (branchName.startsWith(remotePrefix) && branchName.length > remotePrefix.length) {
296 - candidates.add(branchName.slice(remotePrefix.length));
297 - }
298 - }
299 -
300 - return [...candidates];
301 -}
302 -
283 // Replace only Git-rejected whitespace; nonbreaking spaces are valid ref characters.
284 export function sanitizeNewRefName(rawName: string): string {
285 return rawName.trim().replace(/[ \t\n\r\f\v]+/g, "-");
@@ -315,19 +295,12 @@ export function dedupeRemoteBranchesWithLocalMatches(
295 );
296
297 return refs.filter((refName) => {
318 - if (!refName.isRemote) {
319 - return true;
320 - }
321 -
322 - if (refName.remoteName !== "origin") {
298 + if (!refName.isRemote || refName.remoteName !== "origin") {
299 return true;
300 }
301
326 - const localBranchCandidates = deriveLocalBranchNameCandidatesFromRemoteRef(
327 - refName.name,
328 - refName.remoteName,
329 - );
330 - return !localBranchCandidates.some((candidate) => localBranchNames.has(candidate));
302 + const localBranchName = deriveLocalBranchNameFromRemoteRef(refName.name);
303 + return localBranchName.length === 0 || !localBranchNames.has(localBranchName);
304 });
305 }
306