History

Clear pending staged/unstaged diff hunks hunks when writing to the git index fails (#26173)

Release Notes: - Git Beta: Fixed a bug where discarding a hunk in the project diff view performed two concurrent saves of the buffer. - Git Beta: Fixed an issue where diff hunks appeared in the wrong state after failing to write to the git index.

Max Brunsfeld committed 1 year ago

Commit 314ad5d1 parent d3c686514 files · +534 −143Browse files

Showing the changes to crates/buffer_diff/src/buffer_diff.rs (1 of 14 files). Show all

Unified · Split

crates/buffer_diff/src/buffer_diff.rs+24−0
@@ -663,11 +663,13 @@ impl std::fmt::Debug for BufferDiff { · 662 unmodified lines
663 }663 }
664}664}
665 665
666#[derive(Clone, Debug)]
666pub enum BufferDiffEvent {667pub enum BufferDiffEvent {
667 DiffChanged {668 DiffChanged {
668 changed_range: Option<Range<text::Anchor>>,669 changed_range: Option<Range<text::Anchor>>,
669 },670 },
670 LanguageChanged,671 LanguageChanged,
672 HunksStagedOrUnstaged(Option<Rope>),
671}673}
672 674
673impl EventEmitter<BufferDiffEvent> for BufferDiff {}675impl EventEmitter<BufferDiffEvent> for BufferDiff {}
@@ -762,6 +764,17 @@ impl BufferDiff { · 88 unmodified lines
762 self.secondary_diff.clone()764 self.secondary_diff.clone()
763 }765 }
764 766
767 pub fn clear_pending_hunks(&mut self, cx: &mut Context<Self>) {
768 if let Some(secondary_diff) = &self.secondary_diff {
769 secondary_diff.update(cx, |diff, _| {
770 diff.inner.pending_hunks.clear();
771 });
772 cx.emit(BufferDiffEvent::DiffChanged {
773 changed_range: Some(Anchor::MIN..Anchor::MAX),
774 });
775 }
776 }
777
765 pub fn stage_or_unstage_hunks(778 pub fn stage_or_unstage_hunks(
766 &mut self,779 &mut self,
767 stage: bool,780 stage: bool,
@@ -784,6 +797,9 @@ impl BufferDiff { · 16 unmodified lines
784 }797 }
785 });798 });
786 }799 }
800 cx.emit(BufferDiffEvent::HunksStagedOrUnstaged(
801 new_index_text.clone(),
802 ));
787 if let Some((first, last)) = hunks.first().zip(hunks.last()) {803 if let Some((first, last)) = hunks.first().zip(hunks.last()) {
788 let changed_range = first.buffer_range.start..last.buffer_range.end;804 let changed_range = first.buffer_range.start..last.buffer_range.end;
789 cx.emit(BufferDiffEvent::DiffChanged {805 cx.emit(BufferDiffEvent::DiffChanged {
@@ -900,6 +916,14 @@ impl BufferDiff { · 110 unmodified lines
900 }916 }
901 }917 }
902 918
919 pub fn hunks<'a>(
920 &'a self,
921 buffer_snapshot: &'a text::BufferSnapshot,
922 cx: &'a App,
923 ) -> impl 'a + Iterator<Item = DiffHunk> {
924 self.hunks_intersecting_range(Anchor::MIN..Anchor::MAX, buffer_snapshot, cx)
925 }
926
903 pub fn hunks_intersecting_range<'a>(927 pub fn hunks_intersecting_range<'a>(
904 &'a self,928 &'a self,
905 range: Range<text::Anchor>,929 range: Range<text::Anchor>,

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t