summaryrefslogtreecommitdiffstats
path: root/src/tabs
diff options
context:
space:
mode:
authorGleb Davydov <23462908+Mifom@users.noreply.github.com>2022-04-24 20:25:50 +0300
committerGitHub <noreply@github.com>2022-04-24 19:25:50 +0200
commit5f466ff983b35176649e855ea60a2585f8b85847 (patch)
tree43fed03897b943229f8b228f926daf6946f29652 /src/tabs
parent13afbf6bba61035011dbc47159dbdce8a7110fc8 (diff)
Change diff renamed files (#1040)
Diffstat (limited to 'src/tabs')
-rw-r--r--src/tabs/status.rs66
1 files changed, 52 insertions, 14 deletions
diff --git a/src/tabs/status.rs b/src/tabs/status.rs
index 65497f12..bd45d7d8 100644
--- a/src/tabs/status.rs
+++ b/src/tabs/status.rs
@@ -19,7 +19,7 @@ use asyncgit::{
},
sync::{BranchCompare, CommitId},
AsyncDiff, AsyncGitNotification, AsyncStatus, DiffParams,
- DiffType, PushType, StatusParams,
+ DiffType, PushType, StatusItemType, StatusParams,
};
use crossbeam_channel::Sender;
use crossterm::event::Event;
@@ -377,7 +377,7 @@ impl Status {
self.index.focus_select(is_stage);
}
- pub fn selected_path(&self) -> Option<(String, bool)> {
+ pub fn selected_data(&self) -> Option<DiffData> {
let (idx, is_stage) = match self.diff_target {
DiffTarget::Stage => (&self.index, true),
DiffTarget::WorkingDir => (&self.index_wd, false),
@@ -385,7 +385,12 @@ impl Status {
if let Some(item) = idx.selection() {
if let FileTreeItemKind::File(i) = item.kind {
- return Some((i.path, is_stage));
+ return Some(DiffData {
+ old_path: i.old_path,
+ new_path: i.new_path,
+ status: i.status,
+ is_stage,
+ });
}
}
None
@@ -480,7 +485,13 @@ impl Status {
///
pub fn update_diff(&mut self) -> Result<()> {
- if let Some((path, is_stage)) = self.selected_path() {
+ if let Some(DiffData {
+ old_path,
+ new_path,
+ status,
+ is_stage,
+ }) = self.selected_data()
+ {
let diff_type = if is_stage {
DiffType::Stage
} else {
@@ -488,30 +499,46 @@ impl Status {
};
let diff_params = DiffParams {
- path: path.clone(),
+ src_path: old_path
+ .clone()
+ .unwrap_or_else(|| new_path.clone()),
+ dst_path: new_path.clone(),
diff_type,
options: self.options.borrow().diff,
};
- if self.diff.current() == (path.clone(), is_stage) {
+ if self.diff.current()
+ == (old_path.clone(), new_path.clone(), is_stage)
+ {
// we are already showing a diff of the right file
// maybe the diff changed (outside file change)
if let Some((params, last)) = self.git_diff.last()? {
if params == diff_params {
// all params match, so we might need to update
- self.diff.update(path, is_stage, last);
+ self.diff.update(
+ old_path, new_path, status, is_stage,
+ last,
+ );
} else {
// params changed, we need to request the right diff
self.request_diff(
diff_params,
- path,
+ old_path,
+ new_path,
+ status,
is_stage,
)?;
}
}
} else {
// we dont show the right diff right now, so we need to request
- self.request_diff(diff_params, path, is_stage)?;
+ self.request_diff(
+ diff_params,
+ old_path,
+ new_path,
+ status,
+ is_stage,
+ )?;
}
} else {
self.diff.clear(false);
@@ -523,11 +550,14 @@ impl Status {
fn request_diff(
&mut self,
diff_params: DiffParams,
- path: String,
+ old_path: Option<String>,
+ new_path: String,
+ status: StatusItemType,
is_stage: bool,
) -> Result<(), anyhow::Error> {
if let Some(diff) = self.git_diff.request(diff_params)? {
- self.diff.update(path, is_stage, diff);
+ self.diff
+ .update(old_path, new_path, status, is_stage, diff);
} else {
self.diff.clear(true);
}
@@ -539,7 +569,8 @@ impl Status {
pub fn reset(&mut self, item: &ResetItem) -> bool {
if let Err(e) = sync::reset_workdir(
&self.repo.borrow(),
- item.path.as_str(),
+ item.old_path.as_deref(),
+ item.new_path.as_str(),
) {
self.queue.push(InternalEvent::ShowErrorMsg(format!(
"reset failed:\n{}",
@@ -701,6 +732,13 @@ impl Status {
}
}
+pub struct DiffData {
+ old_path: Option<String>,
+ new_path: String,
+ status: StatusItemType,
+ is_stage: bool,
+}
+
impl Component for Status {
fn commands(
&self,
@@ -818,10 +856,10 @@ impl Component for Status {
&& (self.can_focus_diff()
|| self.is_focus_on_diff())
{
- if let Some((path, _)) = self.selected_path() {
+ if let Some(diff_data) = self.selected_data() {
self.queue.push(
InternalEvent::OpenExternalEditor(Some(
- path,
+ diff_data.new_path,
)),
);
}