From e15f27106d713a3a519cc44b02e0c41eccd0a31a Mon Sep 17 00:00:00 2001 From: Julia Date: Fri, 7 Oct 2022 12:20:54 -0400 Subject: [PATCH] Reset buffer git diff when setting diff base to None Co-Authored-By: Joseph Lyons --- crates/git/src/diff.rs | 8 ++++++++ crates/language/src/buffer.rs | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/crates/git/src/diff.rs b/crates/git/src/diff.rs index abf874e2bb..4191e5d260 100644 --- a/crates/git/src/diff.rs +++ b/crates/git/src/diff.rs @@ -104,6 +104,11 @@ impl BufferDiff { }) } + pub fn clear(&mut self, buffer: &text::BufferSnapshot) { + self.last_buffer_version = Some(buffer.version().clone()); + self.tree = SumTree::new(); + } + pub fn needs_update(&self, buffer: &text::BufferSnapshot) -> bool { match &self.last_buffer_version { Some(last) => buffer.version().changed_since(last), @@ -296,6 +301,9 @@ mod tests { &diff_base, &[(0..1, "", "point five\n"), (2..3, "two\n", "HELLO\n")], ); + + diff.clear(&buffer); + assert_hunks(diff.hunks(&buffer), &buffer, &diff_base, &[]); } #[test] diff --git a/crates/language/src/buffer.rs b/crates/language/src/buffer.rs index db9aa029f2..a3c0c54d01 100644 --- a/crates/language/src/buffer.rs +++ b/crates/language/src/buffer.rs @@ -707,6 +707,11 @@ impl Buffer { } }) .detach() + } else { + let snapshot = self.snapshot(); + self.git_diff_status.diff.clear(&snapshot); + self.git_diff_update_count += 1; + cx.notify(); } }