Skip to content

Commit 9d5597b

Browse files
committed
chore: remove git_pull, now unused
1 parent fcda162 commit 9d5597b

File tree

1 file changed

+55
-39
lines changed

1 file changed

+55
-39
lines changed

src/utils.rs

Lines changed: 55 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -60,38 +60,11 @@ pub fn git_clone(repo_url: &str, target_dir: &Path, revision: Option<&str>) -> R
6060
.status()
6161
.with_context(|| format!("Failed to clone repository from {}", repo_url))?;
6262

63-
6463
let revision_str = revision.unwrap_or("main");
65-
return git_to_revision(target_dir, "origin", revision_str)
66-
}
67-
68-
pub fn git_pull(repo_path: &Path) -> Result<()> {
69-
if !repo_path.is_dir() {
70-
return Err(anyhow!(
71-
"Error with git pull. {} is not a directory",
72-
repo_path.display()
73-
));
74-
}
75-
76-
let command = "git pull";
77-
let command_vec = shell_words::split(command).map_err(anyhow::Error::new)?;
78-
79-
let status = Command::new(&command_vec[0])
80-
.args(&command_vec[1..])
81-
.current_dir(repo_path)
82-
.stdout(Stdio::null())
83-
.status()
84-
.with_context(|| format!("Failed to execute process in {}", repo_path.display()))?;
85-
86-
if status.success() {
87-
Ok(())
88-
} else {
89-
Err(anyhow!("Error wth git pull in {}", repo_path.display()))
90-
}
64+
return git_to_revision(target_dir, "origin", revision_str);
9165
}
9266

9367
pub fn git_update(repo_path: &Path, repo_url: &str, revision: Option<&str>) -> Result<()> {
94-
9568
if !repo_path.is_dir() {
9669
return Err(anyhow!(
9770
"Error with updating. {} is not a directory",
@@ -121,7 +94,14 @@ pub fn git_update(repo_path: &Path, repo_url: &str, revision: Option<&str>) -> R
12194
.current_dir(repo_path)
12295
.stdout(Stdio::null())
12396
.status()
124-
.with_context(|| format!("Error with adding {} as a remote named {} in {}", repo_url,tmp_remote_name, repo_path.display()))?;
97+
.with_context(|| {
98+
format!(
99+
"Error with adding {} as a remote named {} in {}",
100+
repo_url,
101+
tmp_remote_name,
102+
repo_path.display()
103+
)
104+
})?;
125105

126106
// Attempt to switch to the revision on temporary remote
127107
let revision_str = revision.unwrap_or("main");
@@ -147,25 +127,35 @@ pub fn git_update(repo_path: &Path, repo_url: &str, revision: Option<&str>) -> R
147127
.args(&command_vec[1..])
148128
.stdout(Stdio::null())
149129
.status()
150-
.with_context(|| format!("Failed to set origin remote to {} in {}", repo_url, repo_path.display()))?;
130+
.with_context(|| {
131+
format!(
132+
"Failed to set origin remote to {} in {}",
133+
repo_url,
134+
repo_path.display()
135+
)
136+
})?;
151137
Command::new("git")
152138
.current_dir(repo_path)
153139
.args(vec!["remote", "rm", &tmp_remote_name])
154140
.stdout(Stdio::null())
155141
.status()
156-
.with_context(|| format!("Failed to remove temporary remote {} in {}", tmp_remote_name, repo_path.display()))?;
157-
return Ok(())
142+
.with_context(|| {
143+
format!(
144+
"Failed to remove temporary remote {} in {}",
145+
tmp_remote_name,
146+
repo_path.display()
147+
)
148+
})?;
149+
return Ok(());
158150
}
159151

160-
161152
fn random_remote_name() -> String {
162153
let mut rng = rand::thread_rng();
163154
let random_number: u32 = rng.gen();
164155
format!("tinty-remote-{}", random_number)
165156
}
166157

167158
fn git_to_revision(repo_path: &Path, remote_name: &str, revision: &str) -> Result<()> {
168-
169159
let command = format!("git fetch \"{}\" \"{}\"", remote_name, revision);
170160
let command_vec = shell_words::split(&command).map_err(anyhow::Error::new)?;
171161

@@ -174,7 +164,12 @@ fn git_to_revision(repo_path: &Path, remote_name: &str, revision: &str) -> Resul
174164
.current_dir(repo_path)
175165
.stdout(Stdio::null())
176166
.status()
177-
.with_context(|| format!("fetch: Failed to execute process in {}", repo_path.display()))?;
167+
.with_context(|| {
168+
format!(
169+
"fetch: Failed to execute process in {}",
170+
repo_path.display()
171+
)
172+
})?;
178173

179174
if !fetch.success() {
180175
return Err(anyhow!("Error with fetching \"{}\"", revision));
@@ -189,23 +184,44 @@ fn git_to_revision(repo_path: &Path, remote_name: &str, revision: &str) -> Resul
189184
.args(&command_vec[1..])
190185
.current_dir(repo_path)
191186
.output()
192-
.with_context(|| format!("Unable to parse revision {} in {}", revision, repo_path.display()))?;
187+
.with_context(|| {
188+
format!(
189+
"Unable to parse revision {} in {}",
190+
revision,
191+
repo_path.display()
192+
)
193+
})?;
193194

194195
let stdout = String::from_utf8_lossy(&parse_out.stdout);
195196

196197
let commit_sha = match stdout.lines().next() {
197198
Some(sha) => sha,
198-
None => return Err(anyhow!("Unable to parse revision {} in {}", revision, repo_path.display()))
199+
None => {
200+
return Err(anyhow!(
201+
"Unable to parse revision {} in {}",
202+
revision,
203+
repo_path.display()
204+
))
205+
}
199206
};
200207

201-
let command = format!("git -c advice.detachedHead=false checkout \"{}\"", commit_sha);
208+
let command = format!(
209+
"git -c advice.detachedHead=false checkout \"{}\"",
210+
commit_sha
211+
);
202212
let command_vec = shell_words::split(&command).map_err(anyhow::Error::new)?;
203213

204214
Command::new(&command_vec[0])
205215
.args(&command_vec[1..])
206216
.current_dir(repo_path)
207217
.status()
208-
.with_context(|| format!("Failed to checkout SHA {} in {}", commit_sha, repo_path.display()))?;
218+
.with_context(|| {
219+
format!(
220+
"Failed to checkout SHA {} in {}",
221+
commit_sha,
222+
repo_path.display()
223+
)
224+
})?;
209225

210226
Ok(())
211227
}

0 commit comments

Comments
 (0)