Skip to content

Commit

Permalink
feat(forge): Check tag in forge install (foundry-rs#1416)
Browse files Browse the repository at this point in the history
* Check tag in forge install

* use String::from_utf8_lossy
  • Loading branch information
pyk authored Apr 26, 2022
1 parent 22834f9 commit 1db141f
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions cli/src/cmd/forge/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ pub(crate) fn install(
let target_dir = if let Some(alias) = &dep.alias { alias } else { &dep.name };
let DependencyInstallOpts { no_git, no_commit, quiet } = opts;
p_println!(!quiet => "Installing {} in {:?}, (url: {}, tag: {:?})", dep.name, &libs.join(&target_dir), dep.url, dep.tag);
check_tag(&dep)?;
if no_git {
install_as_folder(&dep, &libs)?;
} else {
Expand All @@ -101,6 +102,21 @@ pub(crate) fn install(
Ok(())
}

/// make sure tag exists on the remote repository
fn check_tag(dep: &Dependency) -> eyre::Result<()> {
if let Some(ref tag) = dep.tag {
let output = Command::new("git")
.args(&["ls-remote", &dep.url, tag])
.stdout(Stdio::piped())
.output()?;
let stdout = String::from_utf8_lossy(&output.stdout);
if !stdout.contains(tag) {
eyre::bail!("tag/branch/commit \"{}\" does not exists", tag)
}
}
Ok(())
}

/// installs the dependency as an ordinary folder instead of a submodule
fn install_as_folder(dep: &Dependency, libs: &Path) -> eyre::Result<()> {
let target_dir = if let Some(alias) = &dep.alias { alias } else { &dep.name };
Expand Down

0 comments on commit 1db141f

Please sign in to comment.