Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: error if git rev and git depth are used together #340

Merged
merged 3 commits into from
Nov 22, 2023
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
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
Loading