upleb.uk

Public git repos — served from a NIP-34 GRASP relay at git.upleb.uk

summaryrefslogtreecommitdiff
path: root/src/git.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/git.rs')
-rw-r--r--src/git.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/git.rs b/src/git.rs
index 337444a..f9121f2 100644
--- a/src/git.rs
+++ b/src/git.rs
@@ -30,6 +30,7 @@ impl Repo {
30pub trait RepoActions { 30pub 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 {