Skip to content

Commit a5e8c44

Browse files
authored
Use relative path for git commands in install cmd (#623)
* Use relative path for git commands in install cmd * Simplify function signatures in `forge install`
1 parent 708f48f commit a5e8c44

File tree

1 file changed

+16
-21
lines changed

1 file changed

+16
-21
lines changed

cli/src/cmd/install.rs

+16-21
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,11 @@ pub(crate) fn install(
6565

6666
for dep in dependencies {
6767
let DependencyInstallOpts { no_git, no_commit, quiet } = opts;
68-
let path = libs.join(&dep.name);
69-
p_println!(!quiet => "Installing {} in {:?}, (url: {}, tag: {:?})", dep.name, path, dep.url, dep.tag);
68+
p_println!(!quiet => "Installing {} in {:?}, (url: {}, tag: {:?})", dep.name, &libs.join(&dep.name), dep.url, dep.tag);
7069
if no_git {
71-
install_as_folder(&dep, &path)?;
70+
install_as_folder(&dep, &libs)?;
7271
} else {
73-
install_as_submodule(&dep, root, &path, no_commit)?;
72+
install_as_submodule(&dep, &libs, no_commit)?;
7473
}
7574

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

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

8989
if let Some(ref tag) = dep.tag {
9090
Command::new("git")
9191
.args(&["checkout", tag])
92-
.current_dir(&path)
92+
.current_dir(&libs.join(&dep.name))
9393
.stdout(Stdio::piped())
9494
.stderr(Stdio::piped())
9595
.spawn()?
9696
.wait()?;
9797
}
9898

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

102102
Ok(())
103103
}
104104

105105
/// installs the dependency as new submodule
106-
fn install_as_submodule(
107-
dep: &Dependency,
108-
root: &Path,
109-
path: &Path,
110-
no_commit: bool,
111-
) -> eyre::Result<()> {
106+
fn install_as_submodule(dep: &Dependency, libs: &Path, no_commit: bool) -> eyre::Result<()> {
112107
// install the dep
113108
Command::new("git")
114-
.args(&["submodule", "add", &dep.url, &path.display().to_string()])
115-
.current_dir(&root)
109+
.args(&["submodule", "add", &dep.url, &dep.name])
110+
.current_dir(&libs)
116111
.stdout(Stdio::piped())
117112
.stderr(Stdio::piped())
118113
.spawn()?
119114
.wait()?;
120115
// call update on it
121116
Command::new("git")
122-
.args(&["submodule", "update", "--init", "--recursive", &path.display().to_string()])
123-
.current_dir(&root)
117+
.args(&["submodule", "update", "--init", "--recursive", &dep.name])
118+
.current_dir(&libs)
124119
.stdout(Stdio::piped())
125120
.stderr(Stdio::piped())
126121
.spawn()?
@@ -130,14 +125,14 @@ fn install_as_submodule(
130125
let message = if let Some(ref tag) = dep.tag {
131126
Command::new("git")
132127
.args(&["checkout", "--recurse-submodules", tag])
133-
.current_dir(&path)
128+
.current_dir(&libs.join(&dep.name))
134129
.stdout(Stdio::piped())
135130
.stderr(Stdio::piped())
136131
.spawn()?
137132
.wait()?;
138133

139134
if !no_commit {
140-
Command::new("git").args(&["add", &path.display().to_string()]).spawn()?.wait()?;
135+
Command::new("git").args(&["add", &libs.display().to_string()]).spawn()?.wait()?;
141136
}
142137
format!("forge install: {}\n\n{}", dep.name, tag)
143138
} else {
@@ -147,7 +142,7 @@ fn install_as_submodule(
147142
if !no_commit {
148143
Command::new("git")
149144
.args(&["commit", "-m", &message])
150-
.current_dir(&root)
145+
.current_dir(&libs)
151146
.stdout(Stdio::piped())
152147
.spawn()?
153148
.wait()?;

0 commit comments

Comments
 (0)