From 3abb883aafeb06e358a7b4cbc03d54b83e1fd445 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Sun, 26 Mar 2023 01:07:59 -0400 Subject: handle alternate default branches --- src/vcs/git.rs | 18 ++++++++++++++++++ src/vcs/mod.rs | 1 + 2 files changed, 19 insertions(+) (limited to 'src/vcs') diff --git a/src/vcs/git.rs b/src/vcs/git.rs index f4666d1..8442857 100644 --- a/src/vcs/git.rs +++ b/src/vcs/git.rs @@ -9,6 +9,7 @@ pub struct GitInfo { active_operation: super::ActiveOperation, branch: Option, remote_branch_diff: Option<(usize, usize)>, + default_branch: Option, } impl GitInfo { @@ -127,6 +128,18 @@ impl GitInfo { }) }); talk_about_time!("remote branch diff"); + + let default_branch = git + .find_reference("refs/remotes/origin/HEAD") + .ok() + .and_then(|r| r.resolve().ok()) + .and_then(|r| { + r.shorthand() + .map(|s| s.strip_prefix("origin/").unwrap_or(s)) + .map(String::from) + }); + eprintln!("{:?}", default_branch); + talk_about_time!("default branch"); stop_talking_about_time!(); GitInfo { @@ -137,6 +150,7 @@ impl GitInfo { active_operation, branch, remote_branch_diff, + default_branch, } } } @@ -173,6 +187,10 @@ impl super::VcsInfo for GitInfo { fn remote_branch_diff(&self) -> Option<(usize, usize)> { self.remote_branch_diff } + + fn default_branch(&self) -> Option { + self.default_branch.clone() + } } pub fn detect() -> Option> { diff --git a/src/vcs/mod.rs b/src/vcs/mod.rs index 96340cb..f4edb56 100644 --- a/src/vcs/mod.rs +++ b/src/vcs/mod.rs @@ -24,6 +24,7 @@ pub trait VcsInfo { fn active_operation(&self) -> ActiveOperation; fn branch(&self) -> Option; fn remote_branch_diff(&self) -> Option<(usize, usize)>; + fn default_branch(&self) -> Option; fn is_dirty(&self) -> bool { let diff = self.remote_branch_diff(); -- cgit v1.2.3-54-g00ecf