branchyard
Version:
branchyard ā Your shipyard for parallel development workflows. Maintain your digital yard with clean branches, productive workflows, and AI-era readiness.
40 lines (34 loc) ⢠1.36 kB
text/typescript
import { $ } from "bun";
import { isGitRepo, getRepoRoot, getCurrentBranch } from "./git";
import { commandExists } from "./system";
import * as colorette from "colorette";
export async function preflightCheck(showInfo: boolean = true, allowSubdir: boolean = false) {
// Check for Bun (already running if we got here)
// Check for Git
if (!(await commandExists("git"))) {
console.error("ā Git is not installed or not in PATH.");
console.error("Please install Git: https://git-scm.com/");
process.exit(1);
}
// Check if in a git repository
if (!(await isGitRepo())) {
console.error("ā Not in a Git repository.");
console.error("Please run branchyard from inside a Git repository.");
process.exit(1);
}
if (showInfo) {
const cwd = process.cwd();
const repoRoot = await getRepoRoot();
const branch = await getCurrentBranch();
console.log("š Pre-flight check:");
console.log(` Current directory: ${cwd}`);
console.log(` Repository root: ${repoRoot}`);
console.log(` Current branch: ${branch}`);
if (cwd !== repoRoot && !allowSubdir) {
console.warn("\nā ļø Warning: Not in repository root!");
console.warn(" This may cause unexpected behavior.");
console.warn(" Use --allow-subdir to suppress this warning.");
console.warn("");
}
}
}