Get repository name from remote URL or working directory.
(&self, git_repo: &GitRepository)
| 451 | |
| 452 | /// Get repository name from remote URL or working directory. |
| 453 | fn get_repo_name(&self, git_repo: &GitRepository) -> String { |
| 454 | git_repo |
| 455 | .find_remote("origin") |
| 456 | .ok() |
| 457 | .and_then(|remote| remote.url().ok().map(ToString::to_string)) |
| 458 | .and_then(|url| { |
| 459 | // Extract repo name from URL like "https://github.com/holman/spark.git" |
| 460 | // or "git@github.com:holman/spark.git" |
| 461 | url.trim_end_matches(".git") |
| 462 | .rsplit('/') |
| 463 | .next() |
| 464 | .or_else(|| url.rsplit(':').next().and_then(|s| s.rsplit('/').next())) |
| 465 | .map(|s| s.to_string()) |
| 466 | }) |
| 467 | .or_else(|| { |
| 468 | // Fall back to working directory name |
| 469 | git_repo |
| 470 | .workdir() |
| 471 | .and_then(|p| p.file_name()) |
| 472 | .and_then(|n| n.to_str()) |
| 473 | .map(|s| s.to_string()) |
| 474 | }) |
| 475 | .unwrap_or_else(|| "unknown".to_string()) |
| 476 | } |
| 477 | |
| 478 | /// Get the set of already imported Git SHAs from existing changes, |
| 479 | /// plus the Merkle states already present in the import target view. |
no test coverage detected