Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5b69a3342 | ||
|
|
04d17b3adc | ||
|
|
10571fafa5 | ||
|
|
44506ba2f5 | ||
|
|
bc312825cf | ||
|
|
6d9a467e75 |
No files matched your search
@@ -83,12 +83,7 @@ function startBackend(): void {
|
||||
|
||||
const child = spawn(process.execPath, [BACKEND_ENTRY], {
|
||||
cwd: ROOT_DIR,
|
||||
// In Electron main, process.execPath points to the Electron binary.
|
||||
// Run the child in Node mode so this backend process does not become a GUI app instance.
|
||||
env: {
|
||||
...backendEnv(),
|
||||
ELECTRON_RUN_AS_NODE: "1",
|
||||
},
|
||||
env: backendEnv(),
|
||||
stdio: "inherit",
|
||||
});
|
||||
backendProcess = child;
|
||||
|
||||
+5
-108
@@ -2,7 +2,7 @@ import { existsSync } from "node:fs";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import {
|
||||
GitCoreService,
|
||||
@@ -51,25 +51,6 @@ async function initRepoWithCommit(cwd: string): Promise<void> {
|
||||
await git(cwd, "commit -m 'initial commit'");
|
||||
}
|
||||
|
||||
async function commitWithDate(
|
||||
cwd: string,
|
||||
fileName: string,
|
||||
fileContents: string,
|
||||
dateIsoString: string,
|
||||
message: string,
|
||||
): Promise<void> {
|
||||
await writeFile(path.join(cwd, fileName), fileContents);
|
||||
await git(cwd, `add ${fileName}`);
|
||||
const commitResult = await runTerminalCommand({
|
||||
command: `GIT_AUTHOR_DATE="${dateIsoString}" GIT_COMMITTER_DATE="${dateIsoString}" git commit -m "${message}"`,
|
||||
cwd,
|
||||
timeoutMs: 10_000,
|
||||
});
|
||||
if (commitResult.code !== 0) {
|
||||
throw new Error(`git dated commit failed: ${commitResult.stderr}`);
|
||||
}
|
||||
}
|
||||
|
||||
// ── Tests ──
|
||||
|
||||
describe("git integration", () => {
|
||||
@@ -125,82 +106,14 @@ describe("git integration", () => {
|
||||
expect(current!.current).toBe(true);
|
||||
});
|
||||
|
||||
it("keeps current branch first and sorts the remaining branches by recency", async () => {
|
||||
it("sorts current branch first", async () => {
|
||||
await using tmp = await makeTmpDir();
|
||||
await initRepoWithCommit(tmp.path);
|
||||
const initialBranch = (await listGitBranches({ cwd: tmp.path })).branches.find(
|
||||
(branch) => branch.current,
|
||||
)!.name;
|
||||
|
||||
await createGitBranch({ cwd: tmp.path, branch: "older-branch" });
|
||||
await checkoutGitBranch({ cwd: tmp.path, branch: "older-branch" });
|
||||
await commitWithDate(
|
||||
tmp.path,
|
||||
"older.txt",
|
||||
"older branch change\n",
|
||||
"Thu, 1 Jan 2037 00:00:00 +0000",
|
||||
"older branch change",
|
||||
);
|
||||
|
||||
await checkoutGitBranch({ cwd: tmp.path, branch: initialBranch });
|
||||
await createGitBranch({ cwd: tmp.path, branch: "newer-branch" });
|
||||
await checkoutGitBranch({ cwd: tmp.path, branch: "newer-branch" });
|
||||
await commitWithDate(
|
||||
tmp.path,
|
||||
"newer.txt",
|
||||
"newer branch change\n",
|
||||
"Fri, 1 Jan 2038 00:00:00 +0000",
|
||||
"newer branch change",
|
||||
);
|
||||
|
||||
// Switch away to show current branch is pinned, then remaining branches are recency-sorted.
|
||||
await checkoutGitBranch({ cwd: tmp.path, branch: "older-branch" });
|
||||
await createGitBranch({ cwd: tmp.path, branch: "aaa-first-alpha" });
|
||||
await createGitBranch({ cwd: tmp.path, branch: "zzz-last" });
|
||||
|
||||
const result = await listGitBranches({ cwd: tmp.path });
|
||||
expect(result.branches[0]!.name).toBe("older-branch");
|
||||
expect(result.branches[1]!.name).toBe("newer-branch");
|
||||
});
|
||||
|
||||
it("keeps default branch right after current branch", async () => {
|
||||
await using tmp = await makeTmpDir();
|
||||
await using remote = await makeTmpDir();
|
||||
await initRepoWithCommit(tmp.path);
|
||||
const defaultBranch = (await listGitBranches({ cwd: tmp.path })).branches.find(
|
||||
(branch) => branch.current,
|
||||
)!.name;
|
||||
|
||||
await git(remote.path, "init --bare");
|
||||
await git(tmp.path, `remote add origin ${JSON.stringify(remote.path)}`);
|
||||
await git(tmp.path, `push -u origin ${defaultBranch}`);
|
||||
await git(tmp.path, `remote set-head origin ${defaultBranch}`);
|
||||
|
||||
await createGitBranch({ cwd: tmp.path, branch: "current-branch" });
|
||||
await checkoutGitBranch({ cwd: tmp.path, branch: "current-branch" });
|
||||
await commitWithDate(
|
||||
tmp.path,
|
||||
"current.txt",
|
||||
"current change\n",
|
||||
"Thu, 1 Jan 2037 00:00:00 +0000",
|
||||
"current change",
|
||||
);
|
||||
|
||||
await checkoutGitBranch({ cwd: tmp.path, branch: defaultBranch });
|
||||
await createGitBranch({ cwd: tmp.path, branch: "newer-branch" });
|
||||
await checkoutGitBranch({ cwd: tmp.path, branch: "newer-branch" });
|
||||
await commitWithDate(
|
||||
tmp.path,
|
||||
"newer.txt",
|
||||
"newer change\n",
|
||||
"Fri, 1 Jan 2038 00:00:00 +0000",
|
||||
"newer change",
|
||||
);
|
||||
|
||||
await checkoutGitBranch({ cwd: tmp.path, branch: "current-branch" });
|
||||
|
||||
const result = await listGitBranches({ cwd: tmp.path });
|
||||
expect(result.branches[0]!.name).toBe("current-branch");
|
||||
expect(result.branches[1]!.name).toBe(defaultBranch);
|
||||
expect(result.branches[2]!.name).toBe("newer-branch");
|
||||
expect(result.branches[0]!.current).toBe(true);
|
||||
});
|
||||
|
||||
it("lists multiple branches after creating them", async () => {
|
||||
@@ -603,21 +516,5 @@ describe("git integration", () => {
|
||||
const skipped = await core.pushCurrentBranch(tmp.path, null);
|
||||
expect(skipped.status).toBe("skipped_up_to_date");
|
||||
});
|
||||
|
||||
it("lists branches when recency lookup fails", async () => {
|
||||
await using tmp = await makeTmpDir();
|
||||
await initRepoWithCommit(tmp.path);
|
||||
const core = new GitCoreService();
|
||||
const recencySpy = vi
|
||||
.spyOn(core as any, "readBranchRecency")
|
||||
.mockRejectedValueOnce(new Error("timeout"));
|
||||
|
||||
const result = await core.listBranches({ cwd: tmp.path });
|
||||
|
||||
expect(result.isRepo).toBe(true);
|
||||
expect(result.branches.length).toBeGreaterThan(0);
|
||||
expect(result.branches[0]?.current).toBe(true);
|
||||
recencySpy.mockRestore();
|
||||
});
|
||||
});
|
||||
});
|
||||
+3
-42
@@ -312,40 +312,7 @@ export class GitCoreService {
|
||||
return value.length > 0 ? value : null;
|
||||
}
|
||||
|
||||
private async readBranchRecency(cwd: string): Promise<Map<string, number>> {
|
||||
const branchRecency = await executeGit(
|
||||
cwd,
|
||||
["for-each-ref", "--format=%(refname:short)%09%(committerdate:unix)", "refs/heads"],
|
||||
{
|
||||
timeoutMs: 15_000,
|
||||
allowNonZeroExit: true,
|
||||
},
|
||||
);
|
||||
|
||||
const branchLastCommit = new Map<string, number>();
|
||||
if (branchRecency.code !== 0) {
|
||||
return branchLastCommit;
|
||||
}
|
||||
|
||||
for (const line of branchRecency.stdout.split("\n")) {
|
||||
if (line.length === 0) {
|
||||
continue;
|
||||
}
|
||||
const [name, lastCommitRaw] = line.split("\t");
|
||||
if (!name) {
|
||||
continue;
|
||||
}
|
||||
const lastCommit = Number.parseInt(lastCommitRaw ?? "0", 10);
|
||||
branchLastCommit.set(name, Number.isFinite(lastCommit) ? lastCommit : 0);
|
||||
}
|
||||
|
||||
return branchLastCommit;
|
||||
}
|
||||
|
||||
async listBranches(input: GitListBranchesInput): Promise<GitListBranchesResult> {
|
||||
const branchRecencyPromise = this.readBranchRecency(input.cwd).catch(
|
||||
() => new Map<string, number>(),
|
||||
);
|
||||
const result = await executeGit(input.cwd, ["branch", "--no-color"], {
|
||||
timeoutMs: 10_000,
|
||||
allowNonZeroExit: true,
|
||||
@@ -359,7 +326,7 @@ export class GitCoreService {
|
||||
throw new Error(stderr || "git branch failed");
|
||||
}
|
||||
|
||||
const [defaultRef, worktreeList, branchLastCommit] = await Promise.all([
|
||||
const [defaultRef, worktreeList] = await Promise.all([
|
||||
executeGit(input.cwd, ["symbolic-ref", "refs/remotes/origin/HEAD"], {
|
||||
timeoutMs: 5_000,
|
||||
allowNonZeroExit: true,
|
||||
@@ -368,7 +335,6 @@ export class GitCoreService {
|
||||
timeoutMs: 5_000,
|
||||
allowNonZeroExit: true,
|
||||
}),
|
||||
branchRecencyPromise,
|
||||
]);
|
||||
const defaultBranch =
|
||||
defaultRef.code === 0
|
||||
@@ -404,13 +370,8 @@ export class GitCoreService {
|
||||
};
|
||||
})
|
||||
.toSorted((a, b) => {
|
||||
const aPriority = a.current ? 0 : a.isDefault ? 1 : 2;
|
||||
const bPriority = b.current ? 0 : b.isDefault ? 1 : 2;
|
||||
if (aPriority !== bPriority) return aPriority - bPriority;
|
||||
|
||||
const aLastCommit = branchLastCommit.get(a.name) ?? 0;
|
||||
const bLastCommit = branchLastCommit.get(b.name) ?? 0;
|
||||
if (aLastCommit !== bLastCommit) return bLastCommit - aLastCommit;
|
||||
if (a.current !== b.current) return a.current ? -1 : 1;
|
||||
if (a.isDefault !== b.isDefault) return a.isDefault ? -1 : 1;
|
||||
return a.name.localeCompare(b.name);
|
||||
});
|
||||
|
||||
|
||||
@@ -262,12 +262,24 @@ export default function ChatView() {
|
||||
}, []);
|
||||
const toggleTerminalVisibility = useCallback(() => {
|
||||
if (!activeThreadId) return;
|
||||
const isOpen = Boolean(activeThread?.terminalOpen);
|
||||
|
||||
if (isOpen && api) {
|
||||
if (typeof api.terminal.close === "function") {
|
||||
void api.terminal.close({ threadId: activeThreadId }).catch(() => {
|
||||
void api.terminal.write({ threadId: activeThreadId, data: "exit\n" }).catch(() => undefined);
|
||||
});
|
||||
} else {
|
||||
void api.terminal.write({ threadId: activeThreadId, data: "exit\n" }).catch(() => undefined);
|
||||
}
|
||||
}
|
||||
|
||||
dispatch({
|
||||
type: "SET_THREAD_TERMINAL_OPEN",
|
||||
threadId: activeThreadId,
|
||||
open: !activeThread?.terminalOpen,
|
||||
open: !isOpen,
|
||||
});
|
||||
}, [activeThread?.terminalOpen, activeThreadId, dispatch]);
|
||||
}, [activeThread?.terminalOpen, activeThreadId, api, dispatch]);
|
||||
const splitTerminal = useCallback(() => {
|
||||
if (!activeThreadId) return;
|
||||
dispatch({
|
||||
|
||||
@@ -1,11 +0,0 @@
|
||||
# New Poem
|
||||
|
||||
Morning threads the city seams,
|
||||
Coffee steam and careful dreams.
|
||||
Keys begin their silver rain,
|
||||
Small ideas become a plane.
|
||||
|
||||
Windows glow with patient light,
|
||||
Bugs turn understandable by night.
|
||||
Line by line, the silence hums,
|
||||
Tomorrow starts where this one comes.
|
||||
Reference in new issue
Block a user