Skip to content

Use relative path for git commands in install cmd #623

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

Merged
merged 2 commits into from
Jan 30, 2022
Merged
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
37 changes: 16 additions & 21 deletions cli/src/cmd/install.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,11 @@ pub(crate) fn install(

for dep in dependencies {
let DependencyInstallOpts { no_git, no_commit, quiet } = opts;
let path = libs.join(&dep.name);
p_println!(!quiet => "Installing {} in {:?}, (url: {}, tag: {:?})", dep.name, path, dep.url, dep.tag);
p_println!(!quiet => "Installing {} in {:?}, (url: {}, tag: {:?})", dep.name, &libs.join(&dep.name), dep.url, dep.tag);
if no_git {
install_as_folder(&dep, &path)?;
install_as_folder(&dep, &libs)?;
} else {
install_as_submodule(&dep, root, &path, no_commit)?;
install_as_submodule(&dep, &libs, no_commit)?;
}

p_println!(!quiet => " {} {}", Colour::Green.paint("Installed"), dep.name);
Expand All @@ -79,48 +78,44 @@ pub(crate) fn install(
}

/// installs the dependency as an ordinary folder instead of a submodule
fn install_as_folder(dep: &Dependency, path: &Path) -> eyre::Result<()> {
fn install_as_folder(dep: &Dependency, libs: &Path) -> eyre::Result<()> {
Command::new("git")
.args(&["clone", &dep.url, &path.display().to_string()])
.args(&["clone", &dep.url, &dep.name])
.current_dir(&libs)
.stdout(Stdio::piped())
.spawn()?
.wait()?;

if let Some(ref tag) = dep.tag {
Command::new("git")
.args(&["checkout", tag])
.current_dir(&path)
.current_dir(&libs.join(&dep.name))
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?
.wait()?;
}

// rm git artifacts
std::fs::remove_dir_all(path.join(".git"))?;
std::fs::remove_dir_all(libs.join(&dep.name).join(".git"))?;

Ok(())
}

/// installs the dependency as new submodule
fn install_as_submodule(
dep: &Dependency,
root: &Path,
path: &Path,
no_commit: bool,
) -> eyre::Result<()> {
fn install_as_submodule(dep: &Dependency, libs: &Path, no_commit: bool) -> eyre::Result<()> {
// install the dep
Command::new("git")
.args(&["submodule", "add", &dep.url, &path.display().to_string()])
.current_dir(&root)
.args(&["submodule", "add", &dep.url, &dep.name])
.current_dir(&libs)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?
.wait()?;
// call update on it
Command::new("git")
.args(&["submodule", "update", "--init", "--recursive", &path.display().to_string()])
.current_dir(&root)
.args(&["submodule", "update", "--init", "--recursive", &dep.name])
.current_dir(&libs)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?
Expand All @@ -130,14 +125,14 @@ fn install_as_submodule(
let message = if let Some(ref tag) = dep.tag {
Command::new("git")
.args(&["checkout", "--recurse-submodules", tag])
.current_dir(&path)
.current_dir(&libs.join(&dep.name))
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()?
.wait()?;

if !no_commit {
Command::new("git").args(&["add", &path.display().to_string()]).spawn()?.wait()?;
Command::new("git").args(&["add", &libs.display().to_string()]).spawn()?.wait()?;
}
format!("forge install: {}\n\n{}", dep.name, tag)
} else {
Expand All @@ -147,7 +142,7 @@ fn install_as_submodule(
if !no_commit {
Command::new("git")
.args(&["commit", "-m", &message])
.current_dir(&root)
.current_dir(&libs)
.stdout(Stdio::piped())
.spawn()?
.wait()?;
Expand Down