// src/actions/gitlint.ts
import chalk from "chalk";
import ParseGitConfig from "parse-git-config";
var gitlint = () => {
  console.log(`
Gitlint Start [${process.cwd()}]
`);
  let valid = 0;
  let warnings = 0;
  const errors = 0;
  const gitConfig = ParseGitConfig.sync();
  const warn = (message) => {
    console.warn(chalk.yellow(`Warning: ${message}`));
    warnings++;
  };
  if (gitConfig.core.ignorecase) {
    warn("Please set core.ignorecase to FALSE in .git/config file [run yarn gitlint-fix]");
  } else {
    valid++;
  }
  if (gitConfig.core.autocrlf === false) {
    valid++;
  } else {
    warn("Please set core.autocrlf to FALSE in .git/config file [run yarn gitlint-fix]");
  }
  if (gitConfig.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 { execSync } from "child_process";
import chalk2 from "chalk";
import ParseGitConfig2 from "parse-git-config";
var gitlintFix = () => {
  console.log(`
Gitlint Fix Start [${process.cwd()}]
`);
  const gitConfig = ParseGitConfig2.sync();
  if (gitConfig.core.ignorecase) {
    execSync("git config core.ignorecase false", { stdio: "inherit" });
    console.warn(chalk2.yellow("\nGitlint Fix: Updated core.ignorecase to be false\n"));
  }
  if (gitConfig.core.autocrlf !== false) {
    execSync("git config core.autocrlf false", { stdio: "inherit" });
    console.warn(chalk2.yellow("\nGitlint Fix: Updated core.autocrlf to be false\n"));
  }
  if (gitConfig.core.eol !== "lf") {
    execSync("git config core.eol lf", { stdio: "inherit" });
    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