Skip to content
Merged
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
271 changes: 0 additions & 271 deletions apps/desktop/src/main/__tests__/composer-git-branch.test.ts

This file was deleted.

28 changes: 1 addition & 27 deletions apps/desktop/src/main/__tests__/git-review-main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import { tmpdir } from 'node:os';
import { join } from 'node:path';
import { promisify } from 'node:util';
import { after, describe, it } from 'node:test';
import { readGitBranch, readGitReview } from '../git-review-main.js';
import { readGitReview } from '../git-review-main.js';

const execFileAsync = promisify(execFile);
const roots = new Set<string>();
Expand Down Expand Up @@ -170,29 +170,3 @@ async function git(root: string, ...args: string[]): Promise<void> {
timeout: 10_000,
});
}

describe('Git branch read (composer chip)', () => {
it('reads the checked-out branch', async () => {
const root = await repository();
await git(root, 'checkout', '-b', 'feature/chip');
assert.deepEqual(await readGitBranch(root), {
ok: true,
snapshot: { branch: 'feature/chip', shortSha: null },
});
});

it('falls back to the short sha on a detached HEAD', async () => {
const root = await repository();
await git(root, 'checkout', '--detach', 'HEAD');
const result = await readGitBranch(root);
assert.equal(result.ok, true);
if (!result.ok) return;
assert.equal(result.snapshot.branch, null);
assert.match(result.snapshot.shortSha ?? '', /^[0-9a-f]{7,}$/u);
});

it('reports a non-repository as isGitRepo: false, so no chip is drawn', async () => {
const root = await temporaryRoot();
assert.deepEqual(await readGitBranch(root), { ok: false, isGitRepo: false });
});
});
31 changes: 0 additions & 31 deletions apps/desktop/src/main/git-review-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import { isAbsolute, relative, resolve } from 'node:path';
import { promisify } from 'node:util';
import { countDiffLineStats } from '@maka/core/unified-diff';
import {
type GitBranchReadResult,
type GitBranchSnapshot,
type GitReviewFile,
type GitReviewFileStatus,
type GitReviewReadResult,
Expand All @@ -43,35 +41,6 @@ export interface GitReviewCommandRunner {
(root: string, args: readonly string[]): Promise<string>;
}

/**
* The working tree's Git branch, for the composer's branch chip. Three states:
* not a repository (`ok: false, isGitRepo: false` — the caller renders nothing),
* a detached HEAD (`branch: null`, `shortSha` set), or a named branch.
*
* Read-only and deliberately cheap: the review reader withholds the bulk of its
* work, so this asks only what the chip prints.
*/
export async function readGitBranch(
cwd: string,
runGit: GitReviewCommandRunner = runGitCommand,
): Promise<GitBranchReadResult> {
try {
const repositoryRoot = await resolveProjectRoot([cwd]);
if (!(await resolveProjectGitInfo(repositoryRoot)).isGitRepo) {
return { ok: false, isGitRepo: false };
}
const branch = cleanLine(await runGit(repositoryRoot, ['branch', '--show-current']));
// A detached HEAD yields no branch name; its short commit is the honest
// answer, and a repository with no commits yet has neither.
const shortSha = branch === null
? cleanLine(await runGit(repositoryRoot, ['rev-parse', '--short', 'HEAD']).catch(() => ''))
: null;
return { ok: true, snapshot: { branch, shortSha } };
} catch {
return { ok: false, isGitRepo: true };
}
}

export async function readGitReview(
cwd: string,
source: GitReviewSource,
Expand Down
17 changes: 1 addition & 16 deletions apps/desktop/src/main/runtime-host-workspace-ipc-main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import { stat } from 'node:fs/promises';
import type { GitReviewSource } from '@maka/core/git-review';
import type { DesktopRuntimeHostClient } from './runtime-host-client.js';
import { readGitBranch, readGitReview } from './git-review-main.js';
import { readGitReview } from './git-review-main.js';
import {
handleReconnectableRead,
type ReconnectableReadIpcMain,
Expand All @@ -44,21 +44,6 @@ export function registerRuntimeHostWorkspaceIpc(
if (!cwd) return { ok: false as const, reason: 'workspace_unavailable' as const };
return readGitReview(cwd, request.source, undefined, request.baseBranch);
});

// The composer's branch chip: the same session → workspace resolution as the
// review read above, but only the branch the chip prints.
handleReconnectableRead(input.ipcMain, 'git:branch', async (_event, raw: unknown) => {
const sessionId = readBranchRequest(raw);
const cwd =
input.allowLocalWorkspace === false ? null : await sessionWorkspace(input.client, sessionId);
// An unavailable workspace is not a repository either: the chip stays off.
if (!cwd) return { ok: false as const, isGitRepo: false };
return readGitBranch(cwd);
});
}

function readBranchRequest(value: unknown): string {
return requiredString(requiredRecord(value, 'Git branch').sessionId, 'Session id');
}

async function sessionWorkspace(client: WorkspaceClient, sessionId: string): Promise<string | null> {
Expand Down
Loading
Loading