Wire in the branch name

This commit is contained in:
Mikayla Maki 2023-05-03 08:51:58 -07:00
parent 5b4e58d1de
commit 26afd592c5
No known key found for this signature in database
2 changed files with 23 additions and 5 deletions

View file

@ -5,6 +5,7 @@ use std::{
path::{Component, Path, PathBuf},
sync::Arc,
};
use util::ResultExt;
pub use git2::Repository as LibGitRepository;
@ -13,6 +14,8 @@ pub trait GitRepository: Send {
fn reload_index(&self);
fn load_index_text(&self, relative_file_path: &Path) -> Option<String>;
fn branch_name(&self) -> Option<String>;
}
impl std::fmt::Debug for dyn GitRepository {
@ -52,6 +55,12 @@ impl GitRepository for LibGitRepository {
}
None
}
fn branch_name(&self) -> Option<String> {
let head = self.head().log_err()?;
let branch = String::from_utf8_lossy(head.shorthand_bytes());
Some(branch.to_string())
}
}
#[derive(Debug, Clone, Default)]
@ -78,6 +87,10 @@ impl GitRepository for FakeGitRepository {
let state = self.state.lock();
state.index_contents.get(path).cloned()
}
fn branch_name(&self) -> Option<String> {
None
}
}
fn check_path_to_repo_path_errors(relative_file_path: &Path) -> Result<()> {