import { exec } from "node:child_process";
import { promisify } from "node:util";
import * as path from "node:path";
import * as fse from "fs-extra";
const execAsync = promisify(exec);
/**
 * Git service implementation
 */
export class GitService {
    async isRepository(dir) {
        const gitDir = path.join(dir, ".git");
        return fse.pathExists(gitDir);
    }
    async isDirty(dir) {
        try {
            const { stdout } = await execAsync("git status --porcelain", {
                cwd: dir,
            });
            return stdout.trim().length > 0;
        }
        catch {
            // Fail safe: unknown git state should block risky operations
            return true;
        }
    }
    async getStatus(dir) {
        try {
            const { stdout } = await execAsync("git status --short", {
                cwd: dir,
            });
            return stdout.trim();
        }
        catch {
            return "";
        }
    }
}
/**
 * No-op git service for testing or when git checks should be skipped
 */
export class NoOpGitService {
    async isRepository(_dir) {
        return false;
    }
    async isDirty(_dir) {
        return false;
    }
    async getStatus(_dir) {
        return "";
    }
}
//# sourceMappingURL=git-service.js.map