diff options
| author | DanConwayDev <DanConwayDev@protonmail.com> | 2023-11-01 00:00:00 +0000 |
|---|---|---|
| committer | DanConwayDev <DanConwayDev@protonmail.com> | 2023-11-01 00:00:00 +0000 |
| commit | 39ad36115d368d79d4723b3a6b1cefe4874813a3 (patch) | |
| tree | a74ed0c389c46f7be90877d20bc705e0180a0686 /src/git.rs | |
| parent | 6672f54dc166d7447e5c799f1809ecbb3d9ec04c (diff) | |
feat(prs-create) add pr tag branch-name and title
tag pr event with title, description and the name of the current
checkedout branch
Diffstat (limited to 'src/git.rs')
| -rw-r--r-- | src/git.rs | 31 |
1 files changed, 31 insertions, 0 deletions
| @@ -30,6 +30,7 @@ impl Repo { | |||
| 30 | pub trait RepoActions { | 30 | pub trait RepoActions { |
| 31 | fn get_local_branch_names(&self) -> Result<Vec<String>>; | 31 | fn get_local_branch_names(&self) -> Result<Vec<String>>; |
| 32 | fn get_main_or_master_branch(&self) -> Result<(&str, Sha1Hash)>; | 32 | fn get_main_or_master_branch(&self) -> Result<(&str, Sha1Hash)>; |
| 33 | fn get_checked_out_branch_name(&self) -> Result<String>; | ||
| 33 | fn get_tip_of_local_branch(&self, branch_name: &str) -> Result<Sha1Hash>; | 34 | fn get_tip_of_local_branch(&self, branch_name: &str) -> Result<Sha1Hash>; |
| 34 | fn get_root_commit(&self, branch_name: &str) -> Result<Sha1Hash>; | 35 | fn get_root_commit(&self, branch_name: &str) -> Result<Sha1Hash>; |
| 35 | fn get_head_commit(&self) -> Result<Sha1Hash>; | 36 | fn get_head_commit(&self) -> Result<Sha1Hash>; |
| @@ -83,6 +84,15 @@ impl RepoActions for Repo { | |||
| 83 | Ok(branch_names) | 84 | Ok(branch_names) |
| 84 | } | 85 | } |
| 85 | 86 | ||
| 87 | fn get_checked_out_branch_name(&self) -> Result<String> { | ||
| 88 | Ok(self | ||
| 89 | .git_repo | ||
| 90 | .head()? | ||
| 91 | .shorthand() | ||
| 92 | .context("an object without a shorthand is checked out")? | ||
| 93 | .to_string()) | ||
| 94 | } | ||
| 95 | |||
| 86 | fn get_tip_of_local_branch(&self, branch_name: &str) -> Result<Sha1Hash> { | 96 | fn get_tip_of_local_branch(&self, branch_name: &str) -> Result<Sha1Hash> { |
| 87 | let branch = self | 97 | let branch = self |
| 88 | .git_repo | 98 | .git_repo |
| @@ -378,6 +388,27 @@ mod tests { | |||
| 378 | } | 388 | } |
| 379 | } | 389 | } |
| 380 | 390 | ||
| 391 | mod get_checked_out_branch_name { | ||
| 392 | use super::*; | ||
| 393 | |||
| 394 | #[test] | ||
| 395 | fn returns_checked_out_branch_name() -> Result<()> { | ||
| 396 | let test_repo = GitTestRepo::default(); | ||
| 397 | let _ = test_repo.populate()?; | ||
| 398 | // create feature branch | ||
| 399 | test_repo.create_branch("example-feature")?; | ||
| 400 | test_repo.checkout("example-feature")?; | ||
| 401 | |||
| 402 | let git_repo = Repo::from_path(&test_repo.dir)?; | ||
| 403 | |||
| 404 | assert_eq!( | ||
| 405 | git_repo.get_checked_out_branch_name()?, | ||
| 406 | "example-feature".to_string() | ||
| 407 | ); | ||
| 408 | Ok(()) | ||
| 409 | } | ||
| 410 | } | ||
| 411 | |||
| 381 | mod get_commits_ahead_behind { | 412 | mod get_commits_ahead_behind { |
| 382 | use super::*; | 413 | use super::*; |
| 383 | mod returns_main { | 414 | mod returns_main { |