History

fix(server): parse git branches correctly when column.ui is enabled (#1529)

EDM115 committed 7 months ago

Commit 19eb9e71 parent aa5521d2 files · +63 −4Browse files

Unified · Split

2 files
  1. apps/server/src/git/Layers/GitCore.test.ts +59 −1
  2. apps/server/src/git/Layers/GitCore.ts +4 −3
apps/server/src/git/Layers/GitCore.test.ts+59−1
@@ -369,6 +369,64 @@ it.layer(TestLayer)("git integration", (it) => { · 368 unmodified lines
369369 }),
370370 );
371371
372+ it.effect("parses separate branch names when column.ui is always enabled", () =>
373+ Effect.gen(function* () {
374+ const tmp = yield* makeTmpDir();
375+ const { initialBranch } = yield* initRepoWithCommit(tmp);
376+ const createdBranchNames = [
377+ "go-bin",
378+ "copilot/rewrite-cli-in-go",
379+ "copilot/rewrite-cli-in-rust",
380+ ] as const;
381+ for (const branchName of createdBranchNames) {
382+ yield* (yield* GitCore).createBranch({ cwd: tmp, branch: branchName });
383+ }
384+ yield* git(tmp, ["config", "column.ui", "always"]);
385+
386+ const rawBranchOutput = yield* git(tmp, ["branch", "--no-color"], {
387+ ...process.env,
388+ COLUMNS: "120",
389+ });
390+ expect(
391+ rawBranchOutput
392+ .split("\n")
393+ .some(
394+ (line) =>
395+ createdBranchNames.filter((branchName) => line.includes(branchName)).length >= 2,
396+ ),
397+ ).toBe(true);
398+
399+ const realGitCore = yield* GitCore;
400+ const core = yield* makeIsolatedGitCore((input) =>
401+ realGitCore.execute(
402+ input.args[0] === "branch"
403+ ? {
404+ ...input,
405+ env: { ...input.env, COLUMNS: "120" },
406+ }
407+ : input,
408+ ),
409+ );
410+
411+ const result = yield* core.listBranches({ cwd: tmp });
412+ const localBranchNames = result.branches
413+ .filter((branch) => !branch.isRemote)
414+ .map((branch) => branch.name);
415+
416+ expect(localBranchNames).toHaveLength(4);
417+ expect(localBranchNames).toEqual(
418+ expect.arrayContaining([initialBranch, ...createdBranchNames]),
419+ );
420+ expect(
421+ localBranchNames.some(
422+ (branchName) =>
423+ createdBranchNames.filter((createdBranch) => branchName.includes(createdBranch))
424+ .length >= 2,
425+ ),
426+ ).toBe(false);
427+ }),
428+ );
429+
372430 it.effect("isDefault is false when no remote exists", () =>
373431 Effect.gen(function* () {
374432 const tmp = yield* makeTmpDir();
@@ -1898,7 +1956,7 @@ it.layer(TestLayer)("git integration", (it) => { · 1523 unmodified lines
18981956 let didFailRemoteBranches = false;
18991957 let didFailRemoteNames = false;
19001958 const core = yield* makeIsolatedGitCore((input) => {
1901− if (input.args.join(" ") === "branch --no-color --remotes") {
1959+ if (input.args.join(" ") === "branch --no-color --no-column --remotes") {
19021960 didFailRemoteBranches = true;
19031961 return Effect.fail(
19041962 new GitCommandError({
apps/server/src/git/Layers/GitCore.ts+4−3
@@ -1566,7 +1566,7 @@ export const makeGitCore = Effect.fn("makeGitCore")(function* (options?: { · 1565 unmodified lines
15661566 const localBranchResult = yield* executeGit(
15671567 "GitCore.listBranches.branchNoColor",
15681568 input.cwd,
1569− ["branch", "--no-color"],
1569+ ["branch", "--no-color", "--no-column"],
15701570 {
15711571 timeoutMs: 10_000,
15721572 allowNonZeroExit: true,
@@ -1581,7 +1581,7 @@ export const makeGitCore = Effect.fn("makeGitCore")(function* (options?: { · 8 unmodified lines
15811581 return yield* createGitCommandError(
15821582 "GitCore.listBranches",
15831583 input.cwd,
1584− ["branch", "--no-color"],
1584+ ["branch", "--no-color", "--no-column"],
15851585 stderr || "git branch failed",
15861586 );
15871587 }
@@ -1589,7 +1589,7 @@ export const makeGitCore = Effect.fn("makeGitCore")(function* (options?: { · 1 unmodified line
15891589 const remoteBranchResultEffect = executeGit(
15901590 "GitCore.listBranches.remoteBranches",
15911591 input.cwd,
1592− ["branch", "--no-color", "--remotes"],
1592+ ["branch", "--no-color", "--no-column", "--remotes"],
15931593 {
15941594 timeoutMs: 10_000,
15951595 allowNonZeroExit: true,
@@ -1957,6 +1957,7 @@ export const makeGitCore = Effect.fn("makeGitCore")(function* (options?: { · 361 unmodified lines
19571957 runGitStdout("GitCore.listLocalBranchNames", cwd, [
19581958 "branch",
19591959 "--list",
1960+ "--no-column",
19601961 "--format=%(refname:short)",
19611962 ]).pipe(
19621963 Effect.map((stdout) =>