| ... | @@ -324,6 +324,55 @@ describe("git integration", () => { | ... | @@ -324,6 +324,55 @@ describe("git integration", () => { |
| 324 | expect(await git(source.path, "branch --show-current")).toBe(featureBranch); | 324 | expect(await git(source.path, "branch --show-current")).toBe(featureBranch); |
| 325 | }); | 325 | }); |
| 326 | | 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 | |
| 327 | it("throws when branch does not exist", async () => { | 376 | it("throws when branch does not exist", async () => { |
| 328 | await using tmp = await makeTmpDir(); | 377 | await using tmp = await makeTmpDir(); |
| 329 | await initRepoWithCommit(tmp.path); | 378 | await initRepoWithCommit(tmp.path); |