UNPKG

t-comm

Version:

专业、稳定、纯粹的工具库

52 lines (49 loc) 1.9 kB
import fs__default from 'fs'; import path__default from 'path'; import { execCommand } from '../node/node-command.mjs'; import '@babel/runtime/helpers/typeof'; /** * 检测当前是否为Windows环境 */ function isWindows() { return process.platform === 'win32'; } function checkGitClean(dir) { if (!fs__default.existsSync(dir)) { console.error("Not Exist ".concat(dir)); return; } var list = fs__default.readdirSync(dir); // eslint-disable-next-line @typescript-eslint/no-require-imports var chalk = require('chalk'); list.forEach(function (file) { var subDir = path__default.resolve(dir, file); var dotGit = path__default.resolve(subDir, '.git'); var isGitRepo = fs__default.existsSync(dotGit); if (!isGitRepo) ; else { if (isWindows()) { // Windows兼容:使用git status --porcelain检查工作区状态 var statusOutput = execCommand('git status --porcelain', subDir, 'pipe'); if (statusOutput.trim()) { console.log(chalk.red('[not clean] '), subDir); } // Windows兼容:检查是否有未推送的提交 var aheadCount = execCommand('git rev-list --count @{u}..HEAD 2>/dev/null || echo 0', subDir, 'pipe'); if (aheadCount.trim() && parseInt(aheadCount.trim(), 10) > 0) { console.log(chalk.blue('[not push]'), subDir); } } else { // Unix/Linux/macOS版本:保持原有命令 var res = execCommand('git status | grep -c "nothing to commit, working tree clean" || true', subDir, 'pipe'); if (res != '1') { console.log(chalk.red('[not clean] '), subDir); } var isNotPush = execCommand('git status | grep -c "Your branch is ahead of" || true', subDir, 'pipe'); if (isNotPush == '1') { console.log(chalk.blue('[not push]'), subDir); } } } }); } export { checkGitClean };