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
663663 }
664664 }
665665
666+#[derive(Clone, Debug)]
666667 pub enum BufferDiffEvent {
667668 DiffChanged {
668669 changed_range: Option<Range<text::Anchor>>,
669670 },
670671 LanguageChanged,
672+ HunksStagedOrUnstaged(Option<Rope>),
671673 }
672674
673675 impl EventEmitter<BufferDiffEvent> for BufferDiff {}
@@ -762,6 +764,17 @@ impl BufferDiff { · 88 unmodified lines
762764 self.secondary_diff.clone()
763765 }
764766
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+
765778 pub fn stage_or_unstage_hunks(
766779 &mut self,
767780 stage: bool,
@@ -784,6 +797,9 @@ impl BufferDiff { · 16 unmodified lines
784797 }
785798 });
786799 }
800+ cx.emit(BufferDiffEvent::HunksStagedOrUnstaged(
801+ new_index_text.clone(),
802+ ));
787803 if let Some((first, last)) = hunks.first().zip(hunks.last()) {
788804 let changed_range = first.buffer_range.start..last.buffer_range.end;
789805 cx.emit(BufferDiffEvent::DiffChanged {
@@ -900,6 +916,14 @@ impl BufferDiff { · 110 unmodified lines
900916 }
901917 }
902918
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+
903927 pub fn hunks_intersecting_range<'a>(
904928 &'a self,
905929 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