diff options
Diffstat (limited to 'src/git.rs')
| -rw-r--r-- | src/git.rs | 16 |
1 files changed, 16 insertions, 0 deletions
| @@ -39,6 +39,7 @@ pub trait RepoActions { | |||
| 39 | fn get_main_or_master_branch(&self) -> Result<(&str, Sha1Hash)>; | 39 | fn get_main_or_master_branch(&self) -> Result<(&str, Sha1Hash)>; |
| 40 | fn get_checked_out_branch_name(&self) -> Result<String>; | 40 | fn get_checked_out_branch_name(&self) -> Result<String>; |
| 41 | fn get_tip_of_branch(&self, branch_name: &str) -> Result<Sha1Hash>; | 41 | fn get_tip_of_branch(&self, branch_name: &str) -> Result<Sha1Hash>; |
| 42 | fn get_commit_or_tip_of_reference(&self, reference: &str) -> Result<Sha1Hash>; | ||
| 42 | fn get_root_commit(&self) -> Result<Sha1Hash>; | 43 | fn get_root_commit(&self) -> Result<Sha1Hash>; |
| 43 | fn does_commit_exist(&self, commit: &str) -> Result<bool>; | 44 | fn does_commit_exist(&self, commit: &str) -> Result<bool>; |
| 44 | fn get_head_commit(&self) -> Result<Sha1Hash>; | 45 | fn get_head_commit(&self) -> Result<Sha1Hash>; |
| @@ -215,6 +216,21 @@ impl RepoActions for Repo { | |||
| 215 | Ok(oid_to_sha1(&branch.into_reference().peel_to_commit()?.id())) | 216 | Ok(oid_to_sha1(&branch.into_reference().peel_to_commit()?.id())) |
| 216 | } | 217 | } |
| 217 | 218 | ||
| 219 | fn get_commit_or_tip_of_reference(&self, sha1_or_reference: &str) -> Result<Sha1Hash> { | ||
| 220 | let oid = { | ||
| 221 | if let Ok(oid) = Oid::from_str(sha1_or_reference) { | ||
| 222 | self.git_repo.find_commit(oid)?; | ||
| 223 | oid | ||
| 224 | } else { | ||
| 225 | self.git_repo | ||
| 226 | .find_reference(sha1_or_reference)? | ||
| 227 | .peel_to_commit()? | ||
| 228 | .id() | ||
| 229 | } | ||
| 230 | }; | ||
| 231 | Ok(oid_to_sha1(&oid)) | ||
| 232 | } | ||
| 233 | |||
| 218 | fn get_root_commit(&self) -> Result<Sha1Hash> { | 234 | fn get_root_commit(&self) -> Result<Sha1Hash> { |
| 219 | let mut revwalk = self | 235 | let mut revwalk = self |
| 220 | .git_repo | 236 | .git_repo |