aboutsummaryrefslogtreecommitdiffstats
path: root/src/vcs
diff options
context:
space:
mode:
authorJesse Luehrs <doy@tozt.net>2023-03-26 01:07:59 -0400
committerJesse Luehrs <doy@tozt.net>2023-03-26 01:07:59 -0400
commit3abb883aafeb06e358a7b4cbc03d54b83e1fd445 (patch)
treeb305166ff3c19da837e92cf92058bf9f4c72000e /src/vcs
parent2c4bc6762db661011f4d13a858dae8f8dd72fcc2 (diff)
downloadfancy-prompt-3abb883aafeb06e358a7b4cbc03d54b83e1fd445.tar.gz
fancy-prompt-3abb883aafeb06e358a7b4cbc03d54b83e1fd445.zip
handle alternate default branches
Diffstat (limited to 'src/vcs')
-rw-r--r--src/vcs/git.rs18
-rw-r--r--src/vcs/mod.rs1
2 files changed, 19 insertions, 0 deletions
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<String>,
remote_branch_diff: Option<(usize, usize)>,
+ default_branch: Option<String>,
}
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<String> {
+ self.default_branch.clone()
+ }
}
pub fn detect() -> Option<Box<dyn super::VcsInfo>> {
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<String>;
fn remote_branch_diff(&self) -> Option<(usize, usize)>;
+ fn default_branch(&self) -> Option<String>;
fn is_dirty(&self) -> bool {
let diff = self.remote_branch_diff();