Skip to content

Commit

Permalink
fix(core): remove hardcoded git domains (#244)
Browse files Browse the repository at this point in the history
  • Loading branch information
puuuuh authored Feb 5, 2025
1 parent d83862c commit c7e8198
Show file tree
Hide file tree
Showing 7 changed files with 88 additions and 128 deletions.
23 changes: 11 additions & 12 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ select from. Dependencies specified with a custom URL do not use the version req
#### ZIP file

```bash
[forge] soldeer install <NAME>~<VERSION> <ZIP_URL>
[forge] soldeer install <NAME>~<VERSION> --url <ZIP_URL>
```

If the URL to a ZIP file is provided, the registry is not used and the file is downloaded from the URL directly. Note
Expand All @@ -72,32 +72,31 @@ that a version must still be provided, but it can be freely chosen.
#### Git Repository

```bash
[forge] soldeer install <NAME>~<VERSION> <GIT_URL>
[forge] soldeer install <NAME>~<VERSION> --git <GIT_URL>
```

If the URL to a git repository is provided (at the moment, only `github.com` and `gitlab.com` are supported, and the URL
must end with `.git`), then the repository will be cloned into the `dependencies` folder with the `git` CLI available
on the system. HTTPS and SSH-style URLs are supported (see examples below).
If the URL to a git repository is provided, then the repository will be cloned into the `dependencies` folder with the
`git` CLI available on the system. HTTPS and SSH-style URLs are supported (see examples below).

Cloning a specific identifier can be done with the `--rev <COMMIT>`, `--branch <BRANCH>` or `--tag <TAG>` arguments. If
omitted, then the default branch is checked out.

Some examples:

```bash
[forge] soldeer install test-project~v1 [email protected]:test/test.git
[forge] soldeer install test-project~v1 [email protected]:test/test.git
[forge] soldeer install test-project~v1 --git [email protected]:test/test.git
[forge] soldeer install test-project~v1 --git [email protected]:test/test.git
```

```bash
[forge] soldeer install test-project~v1 https://github.com/test/test.git
[forge] soldeer install test-project~v1 https://gitlab.com/test/test.git
[forge] soldeer install test-project~v1 --git https://github.com/test/test.git
[forge] soldeer install test-project~v1 --git https://gitlab.com/test/test.git
```

```bash
[forge] soldeer install test-project~v1 [email protected]:test/test.git --rev 345e611cd84bfb4e62c583fa1886c1928bc1a464
[forge] soldeer install test-project~v1 [email protected]:test/test.git --branch dev
[forge] soldeer install test-project~v1 [email protected]:test/test.git --tag v1
[forge] soldeer install test-project~v1 --git [email protected]:test/test.git --rev 345e611cd84bfb4e62c583fa1886c1928bc1a464
[forge] soldeer install test-project~v1 --git [email protected]:test/test.git --branch dev
[forge] soldeer install test-project~v1 --git [email protected]:test/test.git --tag v1
```

Note that a version must still be provided, but it can be freely chosen.
Expand Down
32 changes: 19 additions & 13 deletions crates/commands/src/commands/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use cliclack::{
use soldeer_core::{
config::{
add_to_config, read_config_deps, read_soldeer_config, Dependency, GitIdentifier, Paths,
UrlType,
},
errors::{InstallError, LockError},
install::{ensure_dependencies_dir, install_dependencies, install_dependency, Progress},
Expand All @@ -28,11 +29,11 @@ If used with arguments, a dependency will be added to the configuration. When us
Examples:
- Install all: soldeer install
- Add from registry: soldeer install lib_name~2.3.0
- Add with custom URL: soldeer install lib_name~2.3.0 https://foo.bar/lib.zip
- Add with git: soldeer install lib_name~2.3.0 [email protected]:foo/bar.git
- Add with git (commit): soldeer install lib_name~2.3.0 [email protected]:foo/bar.git --rev 05f218fb6617932e56bf5388c3b389c3028a7b73
- Add with git (tag): soldeer install lib_name~2.3.0 [email protected]:foo/bar.git --tag v2.3.0
- Add with git (branch): soldeer install lib_name~2.3.0 [email protected]:foo/bar.git --branch feature/baz",
- Add with custom URL: soldeer install lib_name~2.3.0 --url https://foo.bar/lib.zip
- Add with git: soldeer install lib_name~2.3.0 --git [email protected]:foo/bar.git
- Add with git (commit): soldeer install lib_name~2.3.0 --git [email protected]:foo/bar.git --rev 05f218fb6617932e56bf5388c3b389c3028a7b73
- Add with git (tag): soldeer install lib_name~2.3.0 --git [email protected]:foo/bar.git --tag v2.3.0
- Add with git (branch): soldeer install lib_name~2.3.0 --git [email protected]:foo/bar.git --branch feature/baz",
after_help = "For more information, read the README.md"
)]
#[non_exhaustive]
Expand All @@ -45,22 +46,26 @@ pub struct Install {

/// The URL to the dependency zip file.
///
/// If not present, the package will be installed from the Soldeer repository.
///
/// Example: https://my-domain/dep.zip
#[arg(value_name = "URL", requires = "dependency")]
pub remote_url: Option<String>,
#[arg(long = "url", requires = "dependency", conflicts_with = "git_url")]
pub zip_url: Option<String>,

/// The URL to the dependency repository.
///
/// Example: [email protected]:foo/bar.git
#[arg(long = "git", requires = "dependency", conflicts_with = "zip_url")]
pub git_url: Option<String>,

/// A Git commit hash
#[arg(long, group = "identifier", requires = "remote_url")]
#[arg(long, group = "identifier", requires = "git_url")]
pub rev: Option<String>,

/// A Git tag
#[arg(long, group = "identifier", requires = "remote_url")]
#[arg(long, group = "identifier", requires = "git_url")]
pub tag: Option<String>,

/// A Git branch
#[arg(long, group = "identifier", requires = "remote_url")]
#[arg(long, group = "identifier", requires = "git_url")]
pub branch: Option<String>,

/// If set, this command will delete the existing remappings and re-create them
Expand Down Expand Up @@ -140,7 +145,8 @@ pub(crate) async fn install_command(paths: &Paths, cmd: Install) -> Result<()> {
(None, None, None) => None,
_ => unreachable!("clap should prevent this"),
};
let mut dep = Dependency::from_name_version(&dependency, cmd.remote_url, identifier)?;
let url = cmd.zip_url.map(UrlType::http).or(cmd.git_url.map(UrlType::git));
let mut dep = Dependency::from_name_version(&dependency, url, identifier)?;
if dependencies
.iter()
.any(|d| d.name() == dep.name() && d.version_req() == dep.version_req())
Expand Down
4 changes: 2 additions & 2 deletions crates/commands/tests/tests-init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ out = "out"
libs = ["dependencies"]
[dependencies]
forge-std = "1.9.4"
forge-std = "1.9.6"
# See more config options https://github.com/foundry-rs/foundry/blob/master/crates/config/README.md#all-options
"#;
Expand All @@ -151,7 +151,7 @@ async fn test_init_select_soldeer_location() {
assert!(config_path.exists());

let contents = r#"[dependencies]
forge-std = "1.9.4"
forge-std = "1.9.6"
"#;
assert_eq!(fs::read_to_string(config_path).unwrap(), contents);
}
17 changes: 10 additions & 7 deletions crates/commands/tests/tests-install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,10 @@ async fn test_install_registry_specific_version() {
async fn test_install_custom_http() {
let dir = testdir!();
fs::write(dir.join("soldeer.toml"), "[dependencies]\n").unwrap();
let cmd: Command = Install::builder().dependency("mylib~1.0.0").remote_url("https://github.com/mario-eth/soldeer/archive/8585a7ec85a29889cec8d08f4770e15ec4795943.zip").build().into();
let cmd: Command = Install::builder().dependency("mylib~1.0.0")
.zip_url("https://github.com/mario-eth/soldeer/archive/8585a7ec85a29889cec8d08f4770e15ec4795943.zip")
.build()
.into();
let res =
async_with_vars([("SOLDEER_PROJECT_ROOT", Some(dir.to_string_lossy().as_ref()))], run(cmd))
.await;
Expand All @@ -86,7 +89,7 @@ async fn test_install_git_main() {
fs::write(dir.join("soldeer.toml"), "[dependencies]\n").unwrap();
let cmd: Command = Install::builder()
.dependency("mylib~0.1.0")
.remote_url("https://github.com/beeb/test-repo.git")
.git_url("https://github.com/beeb/test-repo.git")
.build()
.into();
let res =
Expand All @@ -108,7 +111,7 @@ async fn test_install_git_commit() {
fs::write(dir.join("soldeer.toml"), "[dependencies]\n").unwrap();
let cmd: Command = Install::builder()
.dependency("mylib~0.1.0")
.remote_url("https://github.com/beeb/test-repo.git")
.git_url("https://github.com/beeb/test-repo.git")
.rev("78c2f6a1a54db26bab6c3f501854a1564eb3707f")
.build()
.into();
Expand All @@ -131,7 +134,7 @@ async fn test_install_git_tag() {
fs::write(dir.join("soldeer.toml"), "[dependencies]\n").unwrap();
let cmd: Command = Install::builder()
.dependency("mylib~0.1.0")
.remote_url("https://github.com/beeb/test-repo.git")
.git_url("https://github.com/beeb/test-repo.git")
.tag("v0.1.0")
.build()
.into();
Expand All @@ -154,7 +157,7 @@ async fn test_install_git_branch() {
fs::write(dir.join("soldeer.toml"), "[dependencies]\n").unwrap();
let cmd: Command = Install::builder()
.dependency("mylib~dev")
.remote_url("https://github.com/beeb/test-repo.git")
.git_url("https://github.com/beeb/test-repo.git")
.branch("dev")
.build()
.into();
Expand Down Expand Up @@ -192,7 +195,7 @@ async fn test_install_foundry_remappings() {
remappings_location = "config"
[dependencies]
"@openzeppelin-contracts" = "5"
"@openzeppelin-contracts" = "5.1.0"
"#;
fs::write(dir.join("foundry.toml"), contents).unwrap();
let cmd: Command = Install::builder().build().into();
Expand All @@ -202,7 +205,7 @@ remappings_location = "config"
assert!(res.is_ok(), "{res:?}");
let config = fs::read_to_string(dir.join("foundry.toml")).unwrap();
assert!(config.contains(
"remappings = [\"@openzeppelin-contracts-5/=dependencies/@openzeppelin-contracts-5.1.0/\"]"
"remappings = [\"@openzeppelin-contracts-5.1.0/=dependencies/@openzeppelin-contracts-5.1.0/\"]"
));
}

Expand Down
Loading

0 comments on commit c7e8198

Please sign in to comment.