@devries-cameron20 / t3code Mirror · read-only / commits / 6708fe996a
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 25, 18:30 UTC

Scope branch refresh fetch to checked-out upstream refspec

- derive upstream branch from `branch@{upstream}` and guard empty values - fetch only `+refs/heads/<branch>:refs/remotes/<remote>/<branch>` instead of all remote refs - add integration test asserting scoped fetch args during `checkoutBranch`

Julius Marminge committed Feb 15, 2026 at 00:47 UTC 6708fe996ac144e606abd8645530ea0d7023d42d
2 files changed +55 -1
apps/server/src/git.test.ts
+49
@@ -324,6 +324,55 @@ describe("git integration", () => {
324 expect(await git(source.path, "branch --show-current")).toBe(featureBranch);
325 });
326
327 + it("refresh fetch is scoped to the checked out branch upstream refspec", async () => {
328 + await using remote = await makeTmpDir();
329 + await using source = await makeTmpDir();
330 + await git(remote.path, "init --bare");
331 +
332 + await initRepoWithCommit(source.path);
333 + const defaultBranch = (await listGitBranches({ cwd: source.path })).branches.find(
334 + (branch) => branch.current,
335 + )!.name;
336 + await git(source.path, `remote add origin ${JSON.stringify(remote.path)}`);
337 + await git(source.path, `push -u origin ${defaultBranch}`);
338 +
339 + const featureBranch = "feature/scoped-fetch";
340 + await git(source.path, `checkout -b ${featureBranch}`);
341 + await writeFile(path.join(source.path, "feature.txt"), "feature base\n");
342 + await git(source.path, "add feature.txt");
343 + await git(source.path, "commit -m 'feature base'");
344 + await git(source.path, `push -u origin ${featureBranch}`);
345 + await git(source.path, `checkout ${defaultBranch}`);
346 +
347 + class FetchRecordingGitCoreService extends GitCoreService {
348 + fetchArgs: readonly string[] | null = null;
349 +
350 + override async git(
351 + cwd: string,
352 + args: readonly string[],
353 + allowNonZeroExit = false,
354 + ): Promise<void> {
355 + if (args[0] === "fetch") {
356 + this.fetchArgs = args;
357 + return;
358 + }
359 + await super.git(cwd, args, allowNonZeroExit);
360 + }
361 + }
362 +
363 + const core = new FetchRecordingGitCoreService();
364 + await core.checkoutBranch({ cwd: source.path, branch: featureBranch });
365 +
366 + expect(await git(source.path, "branch --show-current")).toBe(featureBranch);
367 + expect(core.fetchArgs).toEqual([
368 + "fetch",
369 + "--quiet",
370 + "--no-tags",
371 + "origin",
372 + `+refs/heads/${featureBranch}:refs/remotes/origin/${featureBranch}`,
373 + ]);
374 + });
375 +
376 it("throws when branch does not exist", async () => {
377 await using tmp = await makeTmpDir();
378 await initRepoWithCommit(tmp.path);
apps/server/src/git.ts
+6 -1
@@ -570,11 +570,16 @@ export class GitCoreService {
570 return;
571 }
572 const remoteName = upstreamRef.slice(0, separatorIndex);
573 + const upstreamBranch = upstreamRef.slice(separatorIndex + 1);
574 if (remoteName.length === 0) {
575 return;
576 }
577 + if (upstreamBranch.length === 0) {
578 + return;
579 + }
580
577 - await this.git(cwd, ["fetch", "--quiet", "--no-tags", remoteName], true);
581 + const refspec = `+refs/heads/${upstreamBranch}:refs/remotes/${upstreamRef}`;
582 + await this.git(cwd, ["fetch", "--quiet", "--no-tags", remoteName, refspec], true);
583 }
584
585 async checkoutBranch(input: GitCheckoutInput): Promise<void> {