Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ const getGitOriginUrl: Effect.Effect<string | null> = execCapture(
);

const getBranchName: Effect.Effect<string | null> = execCapture(
"git rev-parse --abbrev-ref HEAD",
"git symbolic-ref --quiet --short HEAD",
);
Comment thread
macroscopeapp[bot] marked this conversation as resolved.

const getRuntime = (): { name: string; version: string } => {
Expand Down
20 changes: 20 additions & 0 deletions apps/server/src/vcs/GitVcsDriverCore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,26 @@ it.layer(TestLayer)("GitVcsDriver core integration", (it) => {
}),
);

it.effect("reports remote status for an unborn branch", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
const driver = yield* GitVcsDriver.GitVcsDriver;
yield* driver.initRepo({ cwd });

const status = yield* driver.statusDetailsRemote(cwd);

assert.equal(status.isRepo, true);
assert.equal(
status.branch,
yield* git(cwd, ["symbolic-ref", "--quiet", "--short", "HEAD"]),
);
assert.equal(status.hasUpstream, false);
assert.equal(status.aheadCount, 0);
assert.equal(status.behindCount, 0);
assert.equal(status.aheadOfDefaultCount, 0);
}),
);

it.effect("reports remote divergence without reading working-tree details", () =>
Effect.gen(function* () {
const cwd = yield* makeTmpDir();
Expand Down
22 changes: 15 additions & 7 deletions apps/server/src/vcs/GitVcsDriverCore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1168,25 +1168,33 @@ export const makeGitVcsDriverCore = Effect.fn("makeGitVcsDriverCore")(function*
const branchResult = yield* executeGit(
"GitVcsDriver.statusDetailsRemote.branch",
cwd,
["rev-parse", "--abbrev-ref", "HEAD"],
["symbolic-ref", "--quiet", "--short", "HEAD"],
{ allowNonZeroExit: true },
).pipe(Effect.catchIf(isMissingGitCwdError, () => Effect.succeed(null)));

if (branchResult === null) {
return NON_REPOSITORY_REMOTE_STATUS_DETAILS;
}
if (branchResult.exitCode !== 0) {
const stderr = branchResult.stderr.trim();
return yield* createGitCommandError(
"GitVcsDriver.statusDetailsRemote.branch",
const headResult = yield* executeGit(
"GitVcsDriver.statusDetailsRemote.head",
cwd,
["rev-parse", "--abbrev-ref", "HEAD"],
stderr || "git branch lookup failed",
["rev-parse", "--verify", "--quiet", "HEAD"],
{ allowNonZeroExit: true },
);
if (headResult.exitCode !== 0) {
const stderr = branchResult.stderr.trim() || headResult.stderr.trim();
return yield* createGitCommandError(
"GitVcsDriver.statusDetailsRemote.branch",
cwd,
["symbolic-ref", "--quiet", "--short", "HEAD"],
stderr || "git branch lookup failed",
);
}
}

const branchValue = branchResult.stdout.trim();
const branch = branchValue.length > 0 && branchValue !== "HEAD" ? branchValue : null;
const branch = branchResult.exitCode === 0 && branchValue.length > 0 ? branchValue : null;
const upstream = yield* resolveCurrentUpstream(cwd);
const upstreamRef = upstream?.upstreamRef ?? null;
let aheadCount = 0;
Expand Down
Loading