Skip to content

Commit

Permalink
fix: error if git rev and git depth are used together (#340)
Browse files Browse the repository at this point in the history
* fix: error if git rev and git depth are used together
* fix: error in fetch git source
* fix: check if not entire git history is fetched or not
  • Loading branch information
swarnimarun authored Nov 22, 2023
1 parent f7c318e commit 1e015ec
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 5 deletions.
13 changes: 13 additions & 0 deletions src/recipe/parser/source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,19 @@ impl TryConvertNode<GitSource> 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" => {
Expand Down
26 changes: 21 additions & 5 deletions src/source/git_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()))()
Expand Down

0 comments on commit 1e015ec

Please sign in to comment.