Skip to content

Commit

Permalink
more robust parsing of repo name
Browse files Browse the repository at this point in the history
  • Loading branch information
Byron committed Jul 23, 2022
1 parent 881f514 commit f965965
Showing 1 changed file with 10 additions and 17 deletions.
27 changes: 10 additions & 17 deletions src/info/repo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,23 +241,16 @@ impl Repo {
None => return Ok(Default::default()),
};

let mut repository_name = String::new();
let name_parts: Vec<&str> = remote_url.split('/').collect();
if !name_parts.is_empty() {
let mut i = 1;
while repository_name.is_empty() && i <= name_parts.len() {
repository_name = name_parts[name_parts.len() - i].to_string();
i += 1;
}
}

if repository_name.contains(".git") {
let repo_name = repository_name.clone();
let parts: Vec<&str> = repo_name.split(".git").collect();
repository_name = parts[0].to_string();
}

Ok((repository_name, remote_url))
let url = git::url::parse(remote_url.as_bytes())?;
let path = git::path::from_bstr(url.path.as_bstr());
let repo_name = path
.with_extension("")
.file_name()
.expect("non-empty path")
.to_string_lossy()
.into_owned();

Ok((repo_name, remote_url))
}

pub fn get_head_refs(&self) -> Result<HeadRefs> {
Expand Down

0 comments on commit f965965

Please sign in to comment.