Skip to content

Commit ea09b63

Browse files
committed
Fix bug where --branches flag doesn't exist for some versions of git
1 parent 2ad251c commit ea09b63

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

src/utils.rs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ pub fn git_update(repo_path: &Path, repo_url: &str, revision: Option<&str>) -> R
153153
repo_path.display()
154154
)
155155
})?;
156-
return Ok(());
156+
157+
Ok(())
157158
}
158159

159160
fn random_remote_name() -> String {
@@ -178,14 +179,14 @@ fn git_resolve_revision(repo_path: &Path, remote_name: &str, revision: &str) ->
178179
.stderr(Stdio::null())
179180
.stdout(Stdio::piped())
180181
.spawn()
181-
.with_context(|| format!("Failed to spawn"))?;
182+
.with_context(|| "Failed to spawn".to_string())?;
182183

183184
let stdout = child.stdout.take().expect("failed to capture stdout");
184185
let reader = BufReader::new(stdout);
185186

186187
if let Some(parts) = reader
187188
.lines()
188-
.filter_map(|line| line.ok())
189+
.map_while(Result::ok)
189190
.map(|line| line.split("\t").map(String::from).collect::<Vec<String>>())
190191
.filter(|parts| parts.len() == 2)
191192
.find(|parts| parts[1] == expected_tag_ref)
@@ -204,22 +205,22 @@ fn git_resolve_revision(repo_path: &Path, remote_name: &str, revision: &str) ->
204205
let expected_branch_ref = format!("refs/heads/{}", revision);
205206
let mut command = safe_command(
206207
format!(
207-
"git ls-remote --quiet --branches \"{}\" \"{}\"",
208+
"git ls-remote --quiet \"{}\" \"{}\"",
208209
remote_name, expected_branch_ref
209210
),
210211
repo_path,
211212
)?;
212213
let mut child = command
213214
.stdout(Stdio::piped())
214215
.spawn()
215-
.with_context(|| format!("Failed to spawn"))?;
216+
.with_context(|| "Failed to spawn".to_string())?;
216217

217218
let stdout = child.stdout.take().expect("failed to capture stdout");
218219
let reader = BufReader::new(stdout);
219220

220221
if let Some(parts) = reader
221222
.lines()
222-
.filter_map(|line| line.ok())
223+
.map_while(Result::ok)
223224
.map(|line| line.split("\t").map(String::from).collect::<Vec<String>>())
224225
.filter(|parts| parts.len() == 2)
225226
.find(|parts| parts[1] == expected_branch_ref)
@@ -268,10 +269,10 @@ fn git_resolve_revision(repo_path: &Path, remote_name: &str, revision: &str) ->
268269

269270
let stdout = child.stdout.take().expect("failed to capture stdout");
270271
let reader = BufReader::new(stdout);
271-
if let Some(_) = reader
272+
if reader
272273
.lines()
273-
.filter_map(|line| line.ok())
274-
.find(|line| line.clone().starts_with(&remote_branch_prefix))
274+
.map_while(Result::ok)
275+
.any(|line| line.clone().starts_with(&remote_branch_prefix))
275276
{
276277
// we found a remote ref that contains the commit sha
277278
child.kill()?; // Abort the child process.
@@ -286,11 +287,11 @@ fn git_resolve_revision(repo_path: &Path, remote_name: &str, revision: &str) ->
286287
)
287288
})?;
288289

289-
return Err(anyhow!(
290+
Err(anyhow!(
290291
"cannot find revision {} in remote {}",
291292
revision,
292293
remote_name
293-
));
294+
))
294295
}
295296

296297
fn safe_command(command: String, cwd: &Path) -> Result<Command, Error> {
@@ -408,7 +409,8 @@ pub fn get_all_scheme_file_paths(
408409
file.path().file_stem()?.to_str()?,
409410
);
410411
let scheme_file = SchemeFile::new(file.path().as_path()).ok()?;
411-
return Some((name, scheme_file));
412+
413+
Some((name, scheme_file))
412414
})
413415
.collect::<HashMap<String, SchemeFile>>();
414416
scheme_files.extend(files);

0 commit comments

Comments
 (0)