diff --git a/src/recipe/parser/source.rs b/src/recipe/parser/source.rs index 0e1e32021..db06b22e0 100644 --- a/src/recipe/parser/source.rs +++ b/src/recipe/parser/source.rs @@ -171,6 +171,19 @@ impl TryConvertNode for RenderedMappingNode { let mut folder = None; let mut lfs = false; + // TODO: is there a better place for this error? + // raising the error during parsing allows us to suggest fixes in future + // in case we build linting functionality on top + if self.contains_key("git_rev") { + if let Some((k, _)) = self.get_key_value("git_depth") { + return Err(_partialerror!( + *k.span(), + ErrorKind::InvalidField(k.as_str().to_owned().into()), + help = "use of `git_depth` with `git_rev` is invalid" + )); + } + } + for (k, v) in self.iter() { match k.as_str() { "git_url" => { diff --git a/src/source/git_source.rs b/src/source/git_source.rs index 5f069e821..19de85b62 100644 --- a/src/source/git_source.rs +++ b/src/source/git_source.rs @@ -49,11 +49,27 @@ pub fn git_src( recipe_dir.display() ); - // TODO: handle reporting for unavailability of git better, or perhaps pointing to git binary manually? - // currently a solution is to provide a `git` early in PATH with, - // ```bash - // export PATH="/path/to/git:$PATH" - // ``` + // test if git is available locally as we fetch the git from PATH, + // user can always override git path + if !Command::new("git") + .arg("--version") + .output()? + .status + .success() + { + return Err(SourceError::GitErrorStr( + "`git` command not found in `PATH`", + )); + } + + if (source.rev().is_empty() || source.rev().eq("HEAD")) + // depth == -1, fetches the entire git history + && source.depth().map(|s| s != -1).unwrap_or_default() + { + return Err(SourceError::GitErrorStr( + "use of `git_rev` with `git_depth` is invalid", + )); + } let filename = match &source.url() { GitUrl::Url(url) => (|| Some(url.path_segments()?.last()?.to_string()))()