forked from mirrors/kingfisher
Remote scans with --git-history=none now clone repositories with a working tree and scan the current files instead of erroring with 'No inputs to scan.'
This commit is contained in:
parent
d9b90fbc50
commit
0b8e8fcc75
6 changed files with 140 additions and 19 deletions
|
|
@ -105,8 +105,13 @@ impl Git {
|
|||
let _span = debug_span!("git_update", "{repo_url} {}", output_dir.display()).entered();
|
||||
debug!("Attempting to update clone of {repo_url} at {}", output_dir.display());
|
||||
let mut cmd = self.git();
|
||||
cmd.arg("--git-dir");
|
||||
cmd.arg(output_dir);
|
||||
if output_dir.join(".git").is_dir() {
|
||||
cmd.arg("-C");
|
||||
cmd.arg(output_dir);
|
||||
} else {
|
||||
cmd.arg("--git-dir");
|
||||
cmd.arg(output_dir);
|
||||
}
|
||||
cmd.arg("remote");
|
||||
cmd.arg("update");
|
||||
cmd.arg("--prune");
|
||||
|
|
@ -129,7 +134,9 @@ impl Git {
|
|||
debug!("Attempting to create fresh clone of {} at {}", repo_url, output_dir.display());
|
||||
let mut cmd = self.git();
|
||||
cmd.arg("clone");
|
||||
cmd.arg(clone_mode.arg());
|
||||
if let Some(arg) = clone_mode.arg() {
|
||||
cmd.arg(arg);
|
||||
}
|
||||
cmd.arg(repo_url.as_str());
|
||||
cmd.arg(output_dir);
|
||||
debug!("{cmd:#?}");
|
||||
|
|
@ -151,14 +158,17 @@ pub enum CloneMode {
|
|||
Bare,
|
||||
/// Equivalent to `git clone --mirror`
|
||||
Mirror,
|
||||
/// Standard clone with a working tree
|
||||
Checkout,
|
||||
}
|
||||
|
||||
impl CloneMode {
|
||||
/// Return the CLI argument for this clone mode.
|
||||
pub fn arg(&self) -> &str {
|
||||
pub fn arg(&self) -> Option<&str> {
|
||||
match self {
|
||||
Self::Bare => "--bare",
|
||||
Self::Mirror => "--mirror",
|
||||
Self::Bare => Some("--bare"),
|
||||
Self::Mirror => Some("--mirror"),
|
||||
Self::Checkout => None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -183,8 +193,9 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_clone_mode_arg() {
|
||||
assert_eq!(CloneMode::Bare.arg(), "--bare");
|
||||
assert_eq!(CloneMode::Mirror.arg(), "--mirror");
|
||||
assert_eq!(CloneMode::Bare.arg(), Some("--bare"));
|
||||
assert_eq!(CloneMode::Mirror.arg(), Some("--mirror"));
|
||||
assert_eq!(CloneMode::Checkout.arg(), None);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -12,10 +12,7 @@ use crate::blob::BlobIdMap;
|
|||
use crate::{
|
||||
blob::BlobMetadata,
|
||||
cli::{
|
||||
commands::{
|
||||
github::{GitCloneMode, GitHistoryMode},
|
||||
scan,
|
||||
},
|
||||
commands::{github::GitCloneMode, github::GitHistoryMode, scan},
|
||||
global,
|
||||
},
|
||||
findings_store,
|
||||
|
|
@ -42,16 +39,20 @@ pub fn clone_or_update_git_repos(
|
|||
datastore: &Arc<Mutex<findings_store::FindingsStore>>,
|
||||
) -> Result<Vec<PathBuf>> {
|
||||
let mut input_roots = args.input_specifier_args.path_inputs.clone();
|
||||
if repo_urls.is_empty() || args.input_specifier_args.git_history == GitHistoryMode::None {
|
||||
if repo_urls.is_empty() {
|
||||
return Ok(input_roots);
|
||||
}
|
||||
info!("{} Git URLs to fetch", repo_urls.len());
|
||||
for repo_url in repo_urls {
|
||||
debug!("Need to fetch {repo_url}")
|
||||
}
|
||||
let clone_mode = match args.input_specifier_args.git_clone {
|
||||
GitCloneMode::Mirror => CloneMode::Mirror,
|
||||
GitCloneMode::Bare => CloneMode::Bare,
|
||||
let clone_mode = if args.input_specifier_args.git_history == GitHistoryMode::None {
|
||||
CloneMode::Checkout
|
||||
} else {
|
||||
match args.input_specifier_args.git_clone {
|
||||
GitCloneMode::Mirror => CloneMode::Mirror,
|
||||
GitCloneMode::Bare => CloneMode::Bare,
|
||||
}
|
||||
};
|
||||
let git = Git::new(global_args.ignore_certs);
|
||||
|
||||
|
|
@ -68,6 +69,7 @@ pub fn clone_or_update_git_repos(
|
|||
} else {
|
||||
ProgressBar::hidden()
|
||||
};
|
||||
|
||||
for repo_url in repo_urls {
|
||||
let output_dir = {
|
||||
let datastore = datastore.lock().unwrap();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue