Skip to content

Commit

Permalink
fix: git dependency trailing slash (#6725)
Browse files Browse the repository at this point in the history
Co-authored-by: Ary Borenszweig <[email protected]>
  • Loading branch information
aakoshh and asterite authored Dec 6, 2024
1 parent da9a74a commit df71df7
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions tooling/nargo_toml/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,4 @@ noirc_driver.workspace = true
semver = "1.0.20"

[dev-dependencies]
test-case.workspace = true
28 changes: 24 additions & 4 deletions tooling/nargo_toml/src/git.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,20 @@ use std::path::PathBuf;
/// Creates a unique folder name for a GitHub repo
/// by using its URL and tag
fn resolve_folder_name(base: &url::Url, tag: &str) -> String {
let mut folder_name = base.domain().unwrap().to_owned();
folder_name.push_str(base.path());
folder_name.push_str(tag);
folder_name
let mut folder = PathBuf::from("");
for part in [base.domain().unwrap(), base.path(), tag] {
folder.push(part.trim_start_matches('/'));
}
folder.to_string_lossy().into_owned()
}

/// Path to the `nargo` directory under `$HOME`.
fn nargo_crates() -> PathBuf {
dirs::home_dir().unwrap().join("nargo")
}

/// Target directory to download dependencies into, e.g.
/// `$HOME/nargo/github.com/noir-lang/noir-bignum/v0.1.2`
fn git_dep_location(base: &url::Url, tag: &str) -> PathBuf {
let folder_name = resolve_folder_name(base, tag);

Expand Down Expand Up @@ -53,3 +57,19 @@ pub(crate) fn clone_git_repo(url: &str, tag: &str) -> Result<PathBuf, String> {

Ok(loc)
}

#[cfg(test)]
mod tests {
use test_case::test_case;
use url::Url;

use super::resolve_folder_name;

#[test_case("https://github.com/noir-lang/noir-bignum/"; "with slash")]
#[test_case("https://github.com/noir-lang/noir-bignum"; "without slash")]
fn test_resolve_folder_name(url: &str) {
let tag = "v0.4.2";
let dir = resolve_folder_name(&Url::parse(url).unwrap(), tag);
assert_eq!(dir, "github.com/noir-lang/noir-bignum/v0.4.2");
}
}

0 comments on commit df71df7

Please sign in to comment.