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 — refactor(server): reuse branchExists for the unlisted current branch · pingdotgg/t3code@2a4afa9

File tree

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

‎apps/server/src/vcs/GitVcsDriverCore.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriverCore.test.ts
+23-35Lines changed: 23 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -722,43 +722,31 @@ it.effect("reads a branch whose name starts with a parenthesis as attached", ()
722722
).pipe(Effect.provide(layerTest)),
723723
);
724724

725-
it.effect("follows a checkout made outside the driver after refs were cached", () =>
726-
Effect.scoped(
727-
Effect.gen(function* () {
728-
const cwd = yield* makeTmpDir();
729-
const { initialBranch } = yield* initRepoWithCommit(cwd);
730-
yield* git(cwd, ["branch", "feature/outside"]);
731-
const driver = yield* GitVcsDriver.GitVcsDriver;
732-
yield* driver.listRefs({ cwd });
733-
734-
yield* git(cwd, ["switch", "feature/outside"]);
735-
736-
const refs = (yield* driver.listRefs({ cwd })).refs;
737-
const previous = refs.find((ref) => ref.name === initialBranch);
738-
assert.isTrue(refs.find((ref) => ref.name === "feature/outside")?.current);
739-
assert.isFalse(previous?.current);
740-
assert.isNull(previous?.worktreePath ?? null);
741-
}),
742-
).pipe(Effect.provide(layerTest)),
743-
);
744-
745-
it.effect("includes a newly created external branch after refs were cached", () =>
746-
Effect.scoped(
747-
Effect.gen(function* () {
748-
const cwd = yield* makeTmpDir();
749-
const { initialBranch } = yield* initRepoWithCommit(cwd);
750-
const driver = yield* GitVcsDriver.GitVcsDriver;
751-
yield* driver.listRefs({ cwd });
725+
it.effect.each(["an existing", "a new"] as const)(
726+
"follows a checkout of %s branch made outside the driver after refs were cached",
727+
(branch) =>
728+
Effect.scoped(
729+
Effect.gen(function* () {
730+
const cwd = yield* makeTmpDir();
731+
const { initialBranch } = yield* initRepoWithCommit(cwd);
732+
if (branch === "an existing") yield* git(cwd, ["branch", "feature/outside"]);
733+
const driver = yield* GitVcsDriver.GitVcsDriver;
734+
yield* driver.listRefs({ cwd });
752735

753-
yield* git(cwd, ["switch", "-c", "feature/outside"]);
736+
yield* git(
737+
cwd,
738+
branch === "an existing"
739+
? ["switch", "feature/outside"]
740+
: ["switch", "-c", "feature/outside"],
741+
);
754742

755-
const refs = (yield* driver.listRefs({ cwd })).refs;
756-
const previous = refs.find((ref) => ref.name === initialBranch);
757-
assert.isTrue(refs.find((ref) => ref.name === "feature/outside")?.current);
758-
assert.isFalse(previous?.current);
759-
assert.isNull(previous?.worktreePath ?? null);
760-
}),
761-
).pipe(Effect.provide(layerTest)),
743+
const refs = (yield* driver.listRefs({ cwd })).refs;
744+
const previous = refs.find((ref) => ref.name === initialBranch);
745+
assert.isTrue(refs.find((ref) => ref.name === "feature/outside")?.current);
746+
assert.isFalse(previous?.current);
747+
assert.isNull(previous?.worktreePath ?? null);
748+
}),
749+
).pipe(Effect.provide(layerTest)),
762750
);
763751

764752
it.effect.each(["on a branch", "detached", "unborn"] as const)(
Collapse file

‎apps/server/src/vcs/GitVcsDriverCore.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/vcs/GitVcsDriverCore.ts
+4-17Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -4499,20 +4499,6 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
44994499
yield* Cache.invalidate(repositoryPathsCache, repositoryPathsCacheKey);
45004500
});
45014501

4502-
const headHasCommit = (cwd: string) =>
4503-
executeGit(
4504-
"GitVcsDriver.listRefs.headCommit",
4505-
cwd,
4506-
["rev-parse", "--verify", "--quiet", "HEAD"],
4507-
{
4508-
timeoutMs: 5_000,
4509-
allowNonZeroExit: true,
4510-
},
4511-
).pipe(
4512-
Effect.map((result) => result.exitCode === 0),
4513-
Effect.orElseSucceed(() => false),
4514-
);
4515-
45164502
const listRefs: GitVcsDriver.GitVcsDriver["Service"]["listRefs"] = Effect.fn("listRefs")(
45174503
function* (input) {
45184504
const repositoryPaths = yield* resolveRepositoryPaths(input.cwd, input.refresh === true).pipe(
@@ -4543,12 +4529,13 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
45434529
{ concurrency: 2 },
45444530
);
45454531
const { worktreeRoot } = repositoryPaths;
4546-
// A branch created outside T3 Code after the snapshot is listed until the next refresh.
4547-
// An unborn HEAD names a branch that does not exist yet, so it needs a commit to count.
4532+
// The snapshot misses a branch created outside T3 Code until it refreshes. An unborn HEAD
4533+
// names a branch with no ref yet, so the ref must exist before it is listed.
45484534
const currentBranchUnlisted =
45494535
currentBranch !== null && !snapshot.localBranches.some((ref) => ref.name === currentBranch);
45504536
const unlistedCurrentBranch: ReadonlyArray<VcsRef> =
4551-
currentBranchUnlisted && (yield* headHasCommit(input.cwd))
4537+
currentBranchUnlisted &&
4538+
(yield* branchExists(input.cwd, currentBranch).pipe(Effect.orElseSucceed(() => false)))
45524539
? [
45534540
{
45544541
name: currentBranch,

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.