diff --git a/packages/core/__test__/index.spec.mjs b/packages/core/__test__/index.spec.mjs index 4164289..5864749 100644 --- a/packages/core/__test__/index.spec.mjs +++ b/packages/core/__test__/index.spec.mjs @@ -12,12 +12,14 @@ test.beforeEach('mkdir test dir', async (t) => { execSync('git config --global init.defaultBranch main') execSync('git config --global user.email "test@example.com"') execSync('git config --global user.name "Test User"') + // 添加安全目录配置,否则会报错 + execSync('git config --global --add safe.directory "*"') execSync('git init') - await new Promise(resolve => setTimeout(resolve, 100)) + // await new Promise(resolve => setTimeout(resolve, 100)) console.log('Finish git init') - execSync('git rev-parse --is-inside-work-tree', { - stdio: 'inherit', - }) + // execSync('git rev-parse --is-inside-work-tree', { + // stdio: 'inherit', + // }) }) test.afterEach('rm test dir', async (t) => { // process.chdir(startDir) diff --git a/packages/core/src/git.rs b/packages/core/src/git.rs index d7513bd..788ad82 100644 --- a/packages/core/src/git.rs +++ b/packages/core/src/git.rs @@ -12,24 +12,24 @@ pub fn is_git_installed() -> bool { } pub fn is_git_repo() -> bool { - // let is_in_repo = Command::new("git") - // .arg("rev-parse") - // .arg("--is-inside-work-tree") - // .stdout(std::process::Stdio::null()) - // .stderr(std::process::Stdio::null()) - // .status() - // .map_err(|e| { - // format!( - // "Failed to check if current directory is a git repository: {}", - // e - // ) - // }) - // .unwrap() - // .success(); + let is_in_repo = Command::new("git") + .arg("rev-parse") + .arg("--is-inside-work-tree") + .stdout(std::process::Stdio::null()) + .stderr(std::process::Stdio::null()) + .status() + .map_err(|e| { + format!( + "Failed to check if current directory is a git repository: {}", + e + ) + }) + .unwrap() + .success(); - // if !is_in_repo { - // return false; - // } + if !is_in_repo { + return false; + } let git_dir = Path::new(".git"); if !git_dir.exists() || !git_dir.is_dir() { return false;