Skip to content
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

Fix bug where --branches flag doesn't exist for some versions of git #101

Merged
merged 1 commit into from
Jan 25, 2025
Merged
Show file tree
Hide file tree
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
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
Loading