Creates a new `GitConfig` by parsing `git` as a URL or a local path.
(
git: Cow<'a, str>,
branch: Option<String>,
identity: Option<PathBuf>,
)
| 53 | impl<'a> GitConfig<'a> { |
| 54 | /// Creates a new `GitConfig` by parsing `git` as a URL or a local path. |
| 55 | pub fn new( |
| 56 | git: Cow<'a, str>, |
| 57 | branch: Option<String>, |
| 58 | identity: Option<PathBuf>, |
| 59 | ) -> Result<Self> { |
| 60 | let (remote, kind) = match determine_repo_kind(git.as_ref()) { |
| 61 | RepoKind::Invalid => anyhow::bail!("Invalid git remote '{}'", &git), |
| 62 | RepoKind::LocalFolder => { |
| 63 | let full_path = canonicalize_path(git.deref().as_ref())?; |
| 64 | if !full_path.exists() { |
| 65 | anyhow::bail!("The given git remote {:?} does not exist.", &git,); |
| 66 | } |
| 67 | ( |
| 68 | full_path.display().to_string().into(), |
| 69 | RepoKind::LocalFolder, |
| 70 | ) |
| 71 | } |
| 72 | k => (git, k), |
| 73 | }; |
| 74 | |
| 75 | Ok(GitConfig { |
| 76 | remote, |
| 77 | kind, |
| 78 | identity, |
| 79 | branch: branch |
| 80 | .map(GitReference::Branch) |
| 81 | .unwrap_or(GitReference::DefaultBranch), |
| 82 | }) |
| 83 | } |
| 84 | |
| 85 | /// Creates a new `GitConfig`, first with `new` and then as a GitHub `owner/repo` remote, like |
| 86 | /// [hub]. |
nothing calls this directly
no test coverage detected