const require_rolldown_runtime = require('../../../../../../../../_virtual/rolldown_runtime.cjs');
const require_built = require('./config/dist/esm/built.cjs');
const require_logger = require('../../../../../../config/dist/esm/logger.cjs');
let node_path = require("node:path");
let node_fs = require("node:fs");
let simple_git = require("simple-git");
simple_git = require_rolldown_runtime.__toESM(simple_git);

//#region ../cli/dist/esm/chokidar/dist/esm/listGitFiles.mjs
const getGitRootDir = async () => {
	try {
		return (await (0, simple_git.default)().revparse(["--show-toplevel"])).trim();
	} catch (error) {
		require_logger.getAppLogger(require_built.built_default)(`Error getting git root directory: ${error}`, { level: "error" });
		return null;
	}
};
const listGitFiles = async ({ mode, baseRef = "origin/main", currentRef = "HEAD", absolute = true }) => {
	try {
		const git = (0, simple_git.default)();
		const diff = /* @__PURE__ */ new Set();
		if (mode.includes("untracked")) (await git.status()).not_added.forEach((f) => diff.add(f));
		if (mode.includes("uncommitted")) (await git.diff(["--name-only", "HEAD"])).split("\n").filter(Boolean).forEach((file) => diff.add(file));
		if (mode.includes("unpushed")) (await git.diff(["--name-only", "@{push}...HEAD"])).split("\n").filter(Boolean).forEach((file) => diff.add(file));
		if (mode.includes("gitDiff")) {
			await git.fetch(baseRef);
			(await git.diff(["--name-only", `${baseRef}...${currentRef}`])).split("\n").filter(Boolean).forEach((file) => diff.add(file));
		}
		if (absolute) {
			const gitRootDir = await getGitRootDir();
			if (!gitRootDir) return [];
			return Array.from(diff).map((file) => (0, node_path.join)(gitRootDir, file));
		}
		return Array.from(diff);
	} catch (error) {
		console.warn("Failed to get changes list:", error);
	}
};

//#endregion
exports.listGitFiles = listGitFiles;
//# sourceMappingURL=listGitFiles.cjs.map