authorgravatar for julius0216@outlook.comJulius Marminge <julius0216@outlook.com> 2026-03-09 17:09:08-07:00
committergravatar for jmarminge@gmail.comJulius Marminge <jmarminge@gmail.com> 2026-03-09 22:50:45-07:00
logfb4f9aa58ef67d192c7692dcfcb58c00a8fb7705
tree38baa88f666782a1151f7075be36edee3505d496
parentde21f4dcd74037dc48d255e06ec27fd58187367b

Use repo initial branch in GitCore PR fetch integration test

- Return `initialBranch` from test repo setup helper - Replace hardcoded `main` checkout/push/assertions with detected branch name

1 files changed, 7 insertions(+), 5 deletions(-)

apps/server/src/git/Layers/GitCore.test.ts+7-5
......@@ -187,7 +187,7 @@ function pullGitBranch({ cwd }: { cwd: string }) {
187187function initRepoWithCommit(
188188 cwd: string,
189189): Effect.Effect<
190 void,
190 { initialBranch: string },
191191 GitCommandError | PlatformError.PlatformError,
192192 GitCore | GitService | FileSystem.FileSystem
193193> {
......@@ -198,6 +198,8 @@ function initRepoWithCommit(
198198 yield* writeTextFile(path.join(cwd, "README.md"), "# test\n");
199199 yield* git(cwd, ["add", "."]);
200200 yield* git(cwd, ["commit", "-m", "initial commit"]);
201 const initialBranch = yield* git(cwd, ["branch", "--show-current"]);
202 return { initialBranch };
201203 });
202204}
203205
......@@ -1207,18 +1209,18 @@ it.layer(TestLayer)("git integration", (it) => {
12071209 it.effect("fetches a GitHub pull request ref into a local branch without checkout", () =>
12081210 Effect.gen(function* () {
12091211 const tmp = yield* makeTmpDir();
1210 yield* initRepoWithCommit(tmp);
1212 const { initialBranch } = yield* initRepoWithCommit(tmp);
12111213 const remoteDir = yield* makeTmpDir("git-remote-");
12121214 yield* git(remoteDir, ["init", "--bare"]);
12131215 yield* git(tmp, ["remote", "add", "origin", remoteDir]);
1214 yield* git(tmp, ["push", "-u", "origin", "main"]);
1216 yield* git(tmp, ["push", "-u", "origin", initialBranch]);
12151217 yield* git(tmp, ["checkout", "-b", "feature/pr-fetch"]);
12161218 yield* writeTextFile(path.join(tmp, "pr-fetch.txt"), "fetch me\n");
12171219 yield* git(tmp, ["add", "pr-fetch.txt"]);
12181220 yield* git(tmp, ["commit", "-m", "Add PR fetch branch"]);
12191221 yield* git(tmp, ["push", "-u", "origin", "feature/pr-fetch"]);
12201222 yield* git(tmp, ["push", "origin", "HEAD:refs/pull/55/head"]);
1221 yield* git(tmp, ["checkout", "main"]);
1223 yield* git(tmp, ["checkout", initialBranch]);
12221224
12231225 yield* fetchGitPullRequestBranch({
12241226 cwd: tmp,
......@@ -1229,7 +1231,7 @@ it.layer(TestLayer)("git integration", (it) => {
12291231 const localBranches = yield* git(tmp, ["branch", "--list", "feature/pr-fetch"]);
12301232 expect(localBranches).toContain("feature/pr-fetch");
12311233 const currentBranch = yield* git(tmp, ["branch", "--show-current"]);
1232 expect(currentBranch).toBe("main");
1234 expect(currentBranch).toBe(initialBranch);
12331235 }),
12341236 );
12351237 });