Reload git index on file events to catch new contents
This commit is contained in:
parent
3f4be5521c
commit
771215d254
4 changed files with 17 additions and 8 deletions
|
@ -630,9 +630,7 @@ impl EditorElement {
|
||||||
let new_hunk = get_hunk(diff_layout.buffer_row, &layout.diff_hunks);
|
let new_hunk = get_hunk(diff_layout.buffer_row, &layout.diff_hunks);
|
||||||
|
|
||||||
let (is_ending, is_starting) = match (diff_layout.last_diff, new_hunk) {
|
let (is_ending, is_starting) = match (diff_layout.last_diff, new_hunk) {
|
||||||
(Some(old_hunk), Some(new_hunk)) if new_hunk == old_hunk => {
|
(Some(old_hunk), Some(new_hunk)) if new_hunk == old_hunk => (false, false),
|
||||||
(false, false)
|
|
||||||
}
|
|
||||||
(a, b) => (a.is_some(), b.is_some()),
|
(a, b) => (a.is_some(), b.is_some()),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,20 @@ pub use git2::Repository as LibGitRepository;
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
pub trait GitRepository: Send {
|
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]
|
#[async_trait::async_trait]
|
||||||
impl GitRepository for LibGitRepository {
|
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>> {
|
fn logic(repo: &LibGitRepository, relative_file_path: &Path) -> Result<Option<String>> {
|
||||||
const STAGE_NORMAL: i32 = 0;
|
const STAGE_NORMAL: i32 = 0;
|
||||||
let index = repo.index()?;
|
let index = repo.index()?;
|
||||||
|
@ -54,7 +62,9 @@ impl FakeGitRepository {
|
||||||
|
|
||||||
#[async_trait::async_trait]
|
#[async_trait::async_trait]
|
||||||
impl GitRepository for FakeGitRepository {
|
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();
|
let state = self.state.lock();
|
||||||
state.index_contents.get(path).cloned()
|
state.index_contents.get(path).cloned()
|
||||||
}
|
}
|
||||||
|
|
|
@ -4684,7 +4684,7 @@ impl Project {
|
||||||
cx.spawn(|_, mut cx| async move {
|
cx.spawn(|_, mut cx| async move {
|
||||||
let diff_base = cx
|
let diff_base = cx
|
||||||
.background()
|
.background()
|
||||||
.spawn(async move { repo.repo.lock().load_index(&relative_repo) })
|
.spawn(async move { repo.repo.lock().load_index_text(&relative_repo) })
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
let buffer_id = buffer.update(&mut cx, |buffer, cx| {
|
let buffer_id = buffer.update(&mut cx, |buffer, cx| {
|
||||||
|
|
|
@ -671,7 +671,7 @@ impl LocalWorktree {
|
||||||
if let Ok(repo_relative) = path.strip_prefix(repo.content_path) {
|
if let Ok(repo_relative) = path.strip_prefix(repo.content_path) {
|
||||||
let repo_relative = repo_relative.to_owned();
|
let repo_relative = repo_relative.to_owned();
|
||||||
cx.background()
|
cx.background()
|
||||||
.spawn(async move { repo.repo.lock().load_index(&repo_relative) })
|
.spawn(async move { repo.repo.lock().load_index_text(&repo_relative) })
|
||||||
.await
|
.await
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
|
@ -2505,6 +2505,7 @@ impl BackgroundScanner {
|
||||||
|
|
||||||
let scan_id = snapshot.scan_id;
|
let scan_id = snapshot.scan_id;
|
||||||
if let Some(repo) = snapshot.in_dot_git(&path) {
|
if let Some(repo) = snapshot.in_dot_git(&path) {
|
||||||
|
repo.repo.lock().reload_index();
|
||||||
repo.scan_id = scan_id;
|
repo.scan_id = scan_id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue