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: git dependency trailing slash #6725

Merged
merged 3 commits into from
Dec 6, 2024
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
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");
}
}
Loading