GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Scope branch refresh fetch to checked-out upstream refspec · pingdotgg/t3code@147f433

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src
    • git.test.ts
    • git.ts
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/git.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/git.test.ts
+49Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -324,6 +324,55 @@ describe("git integration", () => {
324324
expect(await git(source.path, "branch --show-current")).toBe(featureBranch);
325325
});
326326

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+
327376
it("throws when branch does not exist", async () => {
328377
await using tmp = await makeTmpDir();
329378
await initRepoWithCommit(tmp.path);
Collapse file

‎apps/server/src/git.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/git.ts
+6-1Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -570,11 +570,16 @@ export class GitCoreService {
570570
return;
571571
}
572572
const remoteName = upstreamRef.slice(0, separatorIndex);
573+
const upstreamBranch = upstreamRef.slice(separatorIndex + 1);
573574
if (remoteName.length === 0) {
574575
return;
575576
}
577+
if (upstreamBranch.length === 0) {
578+
return;
579+
}
576580

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);
578583
}
579584

580585
async checkoutBranch(input: GitCheckoutInput): Promise<void> {

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.