Skip to content

Commit

Permalink
Fix bug where --branches flag doesn't exist for some versions of git (
Browse files Browse the repository at this point in the history
  • Loading branch information
JamyGolden authored Jan 25, 2025
1 parent 2ad251c commit db7248b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 12 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
### Fixed

- Fixed a bug where scheme files ending in `.yml` weren't recognized.
- Fixed a bug where `install` subcommand gives an error for older versions of
git

## [0.26.0] - 2025-01-18

Expand Down
26 changes: 14 additions & 12 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ pub fn git_update(repo_path: &Path, repo_url: &str, revision: Option<&str>) -> R
repo_path.display()
)
})?;
return Ok(());

Ok(())
}

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

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

if let Some(parts) = reader
.lines()
.filter_map(|line| line.ok())
.map_while(Result::ok)
.map(|line| line.split("\t").map(String::from).collect::<Vec<String>>())
.filter(|parts| parts.len() == 2)
.find(|parts| parts[1] == expected_tag_ref)
Expand All @@ -204,22 +205,22 @@ fn git_resolve_revision(repo_path: &Path, remote_name: &str, revision: &str) ->
let expected_branch_ref = format!("refs/heads/{}", revision);
let mut command = safe_command(
format!(
"git ls-remote --quiet --branches \"{}\" \"{}\"",
"git ls-remote --quiet \"{}\" \"{}\"",
remote_name, expected_branch_ref
),
repo_path,
)?;
let mut child = command
.stdout(Stdio::piped())
.spawn()
.with_context(|| format!("Failed to spawn"))?;
.with_context(|| "Failed to spawn".to_string())?;

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

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

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

return Err(anyhow!(
Err(anyhow!(
"cannot find revision {} in remote {}",
revision,
remote_name
));
))
}

fn safe_command(command: String, cwd: &Path) -> Result<Command, Error> {
Expand Down Expand Up @@ -408,7 +409,8 @@ pub fn get_all_scheme_file_paths(
file.path().file_stem()?.to_str()?,
);
let scheme_file = SchemeFile::new(file.path().as_path()).ok()?;
return Some((name, scheme_file));

Some((name, scheme_file))
})
.collect::<HashMap<String, SchemeFile>>();
scheme_files.extend(files);
Expand Down

0 comments on commit db7248b

Please sign in to comment.