Skip to content

Commit

Permalink
fix get_repo_name when cloning from url that ends with forward slash
Browse files Browse the repository at this point in the history
  • Loading branch information
o2sh committed Oct 5, 2020
1 parent 8c9ccca commit 82cc9a2
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,26 +382,22 @@ impl Info {
let config = repo.config().map_err(|_| Error::NoGitData);
let mut remote_url = String::new();
let mut repository_name = String::new();
let mut remote_upstream: Option<String> = None;

for entry in &config.unwrap().entries(None).unwrap() {
let entry = entry.unwrap();
match entry.name().unwrap() {
"remote.origin.url" => remote_url = entry.value().unwrap().to_string(),
"remote.upstream.url" => remote_upstream = Some(entry.value().unwrap().to_string()),
_ => (),
}
}

if let Some(url) = remote_upstream {
remote_url = url;
if let "remote.origin.url" = entry.name().unwrap() {
remote_url = entry.value().unwrap().to_string()
};
}

let url = remote_url;
let name_parts: Vec<&str> = url.split('/').collect();
let name_parts: Vec<&str> = remote_url.split('/').collect();

if !name_parts.is_empty() {
repository_name = name_parts[name_parts.len() - 1].to_string();
if remote_url.ends_with('/') {
repository_name = name_parts[name_parts.len() - 2].to_string();
} else {
repository_name = name_parts[name_parts.len() - 1].to_string();
}
}

if repository_name.contains(".git") {
Expand Down

0 comments on commit 82cc9a2

Please sign in to comment.