diff options
author | Teddy Wing | 2020-08-01 16:06:51 +0200 |
---|---|---|
committer | Teddy Wing | 2020-08-01 16:06:51 +0200 |
commit | f8742476444c4d58904c3ff7f1f4f17b8b7ab39b (patch) | |
tree | 697415b4b90496bdf768770e0be5b10e13880be4 /src/owner_repo.rs | |
parent | 1453c4bdb4f179f1d27b0cbe95cfb33d111fa406 (diff) | |
download | git-suggestion-f8742476444c4d58904c3ff7f1f4f17b8b7ab39b.tar.bz2 |
OwnerRepo: Move `identifier_for_remote` to `OwnerRepo::from_remote`
Since this function returns an `OwnerRepo`, make it a method on the
struct.
Diffstat (limited to 'src/owner_repo.rs')
-rw-r--r-- | src/owner_repo.rs | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/owner_repo.rs b/src/owner_repo.rs index c0d97a2..67572ef 100644 --- a/src/owner_repo.rs +++ b/src/owner_repo.rs @@ -57,19 +57,21 @@ impl FromStr for OwnerRepo { } } -pub fn identifier_for_remote( - remote_name: Option<&str>, -) -> Result<OwnerRepo, Error> { - let repo = Repository::open(".")?; - - let remote_name = match remote_name { - Some(r) => r, - None => "origin", - }; - - let remote = repo.find_remote(remote_name)?; - let url = remote.url() - .ok_or_else(|| Error::NoRemote(remote_name.to_owned()))?; - - Ok(url.parse()?) +impl OwnerRepo { + pub fn from_remote( + remote_name: Option<&str>, + ) -> Result<OwnerRepo, Error> { + let repo = Repository::open(".")?; + + let remote_name = match remote_name { + Some(r) => r, + None => "origin", + }; + + let remote = repo.find_remote(remote_name)?; + let url = remote.url() + .ok_or_else(|| Error::NoRemote(remote_name.to_owned()))?; + + Ok(url.parse()?) + } } |