Files
oh-my-pi/packages/git-tool/test/helpers.ts
T
can1357 56e760f2bc feat(git-tool): added git-tool package with 22 operations and safety guards
- Added new @oh-my-pi/pi-git-tool package with 22 git operations, safety guards, caching, and GitHub CLI integration.
- Added /wt slash command for git worktree management with create, list, merge, remove, spawn, and parallel operations.
- Added worktree library with collapse strategies (simple, merge-base, rebase) and session tracking for agent tasks.
- Added structured git tool with TypeBox schema exposing gitTool and createGitTool from SDK.
- Added safety policies blocking force push to protected branches and warning on destructive operations.
2026-01-05 15:37:44 +01:00

45 lines
1.2 KiB
TypeScript

import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
export interface GitRunResult {
stdout: string;
stderr: string;
exitCode: number;
}
export function runGit(args: string[], cwd: string): GitRunResult {
const result = Bun.spawnSync(["git", ...args], {
cwd,
stdin: "ignore",
stdout: "pipe",
stderr: "pipe",
});
return {
stdout: Buffer.from(result.stdout ?? []).toString(),
stderr: Buffer.from(result.stderr ?? []).toString(),
exitCode: result.exitCode ?? 0,
};
}
export function createTestRepo(): string {
const dir = mkdtempSync(join(tmpdir(), "git-tool-test-"));
let result = runGit(["init"], dir);
if (result.exitCode !== 0) {
throw new Error(result.stderr);
}
result = runGit(["config", "user.email", "test@example.com"], dir);
if (result.exitCode !== 0) throw new Error(result.stderr);
result = runGit(["config", "user.name", "Test User"], dir);
if (result.exitCode !== 0) throw new Error(result.stderr);
return dir;
}
export function writeFile(path: string, content: string): void {
writeFileSync(path, content, "utf-8");
}
export function cleanupRepo(dir: string): void {
rmSync(dir, { recursive: true, force: true });
}