Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/scanners/blast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,20 @@ pub fn run(
out_format: Option<String>,
out_file: Option<String>,
) {
if *only_uncommitted && !utils::generic::is_git_repo("./") {
eprintln!("This is not a git repository. Without a git repository Corgea CLI can't determine which files have been modified or added thus only a full scan is possible.");
std::process::exit(1);
if *only_uncommitted {
match utils::generic::is_git_repo("./") {
Ok(false) => {
eprintln!("This is not a git repository. Without a git repository Corgea CLI can't determine which files have been modified or added thus only a full scan is possible.");
std::process::exit(1);
},
Err(e) => {
eprintln!("Error checking git repository information: {}. Without a git repository Corgea CLI can't determine which files have been modified or added thus only a full scan is possible.", e);
std::process::exit(1);
},
Ok(true) => {
// Continue with the git repo logic
}
}
}
println!(
"\nScanning with BLAST 🚀🚀🚀"
Expand Down
28 changes: 19 additions & 9 deletions src/utils/generic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,26 @@ pub fn create_path_if_not_exists<P: AsRef<Path>>(path: P) -> io::Result<()> {
Ok(())
}

pub fn get_repo_path(dir: &str) -> Result<String, git2::Error> {
let repo = match Repository::discover(dir) {
Ok(repo) => repo,
Err(e) => return Err(e),
};
Ok(repo.path().to_string_lossy().to_string())
}

pub fn is_git_repo(dir: &str) -> bool {
get_repo_path(dir).is_ok()
pub fn is_git_repo(dir: &str) -> Result<bool, git2::Error> {
let git_path = Path::new(dir).join(".git");
if git_path.exists() {
return Ok(true);
}

// Fall back to the more expensive discover method for cases like:
// - We're in a subdirectory of a git repo
// - .git is a file (worktrees, submodules)
match Repository::discover(dir) {
Ok(_) => Ok(true),
Err(e) => {
if e.code() == git2::ErrorCode::NotFound {
Ok(false)
} else {
Err(e)
}
}
}
}

pub fn delete_directory<P: AsRef<Path>>(path: P) -> io::Result<()> {
Expand Down
Loading