Reload git index on file events to catch new contents

This commit is contained in:
Julia 2022-10-05 16:28:01 -04:00
parent 3f4be5521c
commit 771215d254
4 changed files with 17 additions and 8 deletions

View file

@ -10,12 +10,20 @@ pub use git2::Repository as LibGitRepository;
#[async_trait::async_trait]
pub trait GitRepository: Send {
fn load_index(&self, relative_file_path: &Path) -> Option<String>;
fn reload_index(&self);
fn load_index_text(&self, relative_file_path: &Path) -> Option<String>;
}
#[async_trait::async_trait]
impl GitRepository for LibGitRepository {
fn load_index(&self, relative_file_path: &Path) -> Option<String> {
fn reload_index(&self) {
if let Ok(mut index) = self.index() {
_ = index.read(false);
}
}
fn load_index_text(&self, relative_file_path: &Path) -> Option<String> {
fn logic(repo: &LibGitRepository, relative_file_path: &Path) -> Result<Option<String>> {
const STAGE_NORMAL: i32 = 0;
let index = repo.index()?;
@ -54,7 +62,9 @@ impl FakeGitRepository {
#[async_trait::async_trait]
impl GitRepository for FakeGitRepository {
fn load_index(&self, path: &Path) -> Option<String> {
fn reload_index(&self) {}
fn load_index_text(&self, path: &Path) -> Option<String> {
let state = self.state.lock();
state.index_contents.get(path).cloned()
}