// src/lib/gitConfig.ts
import { execFileSync } from "child_process";
function getGitConfig(key) {
  try {
    const value = execFileSync("git", ["config", "--get", key], {
      encoding: "utf8",
      stdio: ["ignore", "pipe", "ignore"]
    }).trim();
    return value.length > 0 ? value : void 0;
  } catch {
    return void 0;
  }
}
function getGitConfigBool(key) {
  try {
    const value = execFileSync("git", ["config", "--bool", "--get", key], {
      encoding: "utf8",
      stdio: ["ignore", "pipe", "ignore"]
    }).trim();
    if (value === "true") return true;
    if (value === "false") return false;
    return void 0;
  } catch {
    return void 0;
  }
}
function setGitConfig(key, value) {
  execFileSync("git", ["config", key, value], { stdio: "inherit" });
}

// src/actions/gitlint.ts
import chalk from "chalk";
function gitlint() {
  console.log(`
Gitlint Start [${process.cwd()}]
`);
  let valid = 0;
  let warnings = 0;
  const errors = 0;
  const warn = (message) => {
    console.warn(chalk.yellow(`Warning: ${message}`));
    warnings++;
  };
  if (getGitConfigBool("core.ignorecase") === true) {
    warn("Please set core.ignorecase to FALSE in .git/config file [run yarn gitlint-fix]");
  } else {
    valid++;
  }
  if (getGitConfigBool("core.autocrlf") === false) {
    valid++;
  } else {
    warn("Please set core.autocrlf to FALSE in .git/config file [run yarn gitlint-fix]");
  }
  if (getGitConfig("core.eol") === "lf") {
    valid++;
  } else {
    warn('Please set core.eol to "lf" in .git/config file [run yarn gitlint-fix]');
  }
  const resultMessages = [];
  if (valid > 0) {
    resultMessages.push(chalk.green(`Passed: ${valid}`));
  }
  if (warnings > 0) {
    resultMessages.push(chalk.yellow(`Warnings: ${warnings}`));
  }
  if (errors > 0) {
    resultMessages.push(chalk.red(` Errors: ${errors}`));
  }
  console.warn(`Gitlint Finish [ ${resultMessages.join(" | ")} ]
`);
  return warnings + errors === 0 ? 0 : 1;
}

// src/actions/gitlint-fix.ts
import chalk2 from "chalk";
function gitlintFix() {
  console.log(`
Gitlint Fix Start [${process.cwd()}]
`);
  if (getGitConfigBool("core.ignorecase") === true) {
    setGitConfig("core.ignorecase", "false");
    console.warn(chalk2.yellow("\nGitlint Fix: Updated core.ignorecase to be false\n"));
  }
  if (getGitConfigBool("core.autocrlf") !== false) {
    setGitConfig("core.autocrlf", "false");
    console.warn(chalk2.yellow("\nGitlint Fix: Updated core.autocrlf to be false\n"));
  }
  if (getGitConfig("core.eol") !== "lf") {
    setGitConfig("core.eol", "lf");
    console.warn(chalk2.yellow('\nGitlint Fix: Updated core.eol to be "lf"\n'));
  }
  return 1;
}

// src/xy/common/gitlintCommand.ts
var gitlintCommand = {
  builder: (yargs) => {
    return yargs.option("fix", {
      default: false,
      description: "Auto-fix git config issues",
      type: "boolean"
    });
  },
  command: "gitlint",
  describe: "Gitlint - Lint your git config",
  handler: (argv) => {
    if (argv.verbose) console.log("Gitlint");
    process.exitCode = argv.fix ? gitlintFix() : gitlint();
  }
};
export {
  gitlintCommand
};
//# sourceMappingURL=gitlintCommand.mjs.map