Skip to content

Commit

Permalink
ci: fix test env git safe directory issue
Browse files Browse the repository at this point in the history
  • Loading branch information
erguotou committed Jan 6, 2025
1 parent 20a5776 commit 4517994
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 21 deletions.
10 changes: 6 additions & 4 deletions packages/core/__test__/index.spec.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@ test.beforeEach('mkdir test dir', async (t) => {
execSync('git config --global init.defaultBranch main')
execSync('git config --global user.email "[email protected]"')
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)
Expand Down
34 changes: 17 additions & 17 deletions packages/core/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 4517994

Please sign in to comment.