fix hunk edits with non standard diff options (#1803)

This commit is contained in:
extrawurst 2023-08-10 14:48:36 +02:00 committed by GitHub
parent 495d4d5da7
commit 53988ba4e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 27 additions and 7 deletions

View file

@ -25,7 +25,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
* fix commit dialog char count for multibyte characters ([#1726](https://github.com/extrawurst/gitui/issues/1726)) * fix commit dialog char count for multibyte characters ([#1726](https://github.com/extrawurst/gitui/issues/1726))
* fix wrong hit highlighting in fuzzy find popup [[@UUGTech](https://github.com/UUGTech)] ([#1731](https://github.com/extrawurst/gitui/pull/1731)) * fix wrong hit highlighting in fuzzy find popup [[@UUGTech](https://github.com/UUGTech)] ([#1731](https://github.com/extrawurst/gitui/pull/1731))
* fix symlink support for configuration files [[@TheBlackSheep3](https://github.com/TheBlackSheep3)] ([#1751](https://github.com/extrawurst/gitui/issues/1751)) * fix symlink support for configuration files [[@TheBlackSheep3](https://github.com/TheBlackSheep3)] ([#1751](https://github.com/extrawurst/gitui/issues/1751))
* expand `~` in `commit.template` ([#1745](https://github.com/extrawurst/gitui/pull/1745)) * fix expansion of `~` in `commit.template` ([#1745](https://github.com/extrawurst/gitui/pull/1745))
* fix hunk (un)staging/reset for # of context lines != 3 ([#1746](https://github.com/extrawurst/gitui/issues/1746))
## [0.23.0] - 2022-06-19 ## [0.23.0] - 2022-06-19

View file

@ -1,5 +1,5 @@
use super::{ use super::{
diff::{get_diff_raw, HunkHeader}, diff::{get_diff_raw, DiffOptions, HunkHeader},
RepoPath, RepoPath,
}; };
use crate::{ use crate::{
@ -15,12 +15,13 @@ pub fn stage_hunk(
repo_path: &RepoPath, repo_path: &RepoPath,
file_path: &str, file_path: &str,
hunk_hash: u64, hunk_hash: u64,
options: Option<DiffOptions>,
) -> Result<()> { ) -> Result<()> {
scope_time!("stage_hunk"); scope_time!("stage_hunk");
let repo = repo(repo_path)?; let repo = repo(repo_path)?;
let diff = get_diff_raw(&repo, file_path, false, false, None)?; let diff = get_diff_raw(&repo, file_path, false, false, options)?;
let mut opt = ApplyOptions::new(); let mut opt = ApplyOptions::new();
opt.hunk_callback(|hunk| { opt.hunk_callback(|hunk| {
@ -40,12 +41,13 @@ pub fn reset_hunk(
repo_path: &RepoPath, repo_path: &RepoPath,
file_path: &str, file_path: &str,
hunk_hash: u64, hunk_hash: u64,
options: Option<DiffOptions>,
) -> Result<()> { ) -> Result<()> {
scope_time!("reset_hunk"); scope_time!("reset_hunk");
let repo = repo(repo_path)?; let repo = repo(repo_path)?;
let diff = get_diff_raw(&repo, file_path, false, false, None)?; let diff = get_diff_raw(&repo, file_path, false, false, options)?;
let hunk_index = find_hunk_index(&diff, hunk_hash); let hunk_index = find_hunk_index(&diff, hunk_hash);
if let Some(hunk_index) = hunk_index { if let Some(hunk_index) = hunk_index {
@ -98,12 +100,13 @@ pub fn unstage_hunk(
repo_path: &RepoPath, repo_path: &RepoPath,
file_path: &str, file_path: &str,
hunk_hash: u64, hunk_hash: u64,
options: Option<DiffOptions>,
) -> Result<bool> { ) -> Result<bool> {
scope_time!("revert_hunk"); scope_time!("revert_hunk");
let repo = repo(repo_path)?; let repo = repo(repo_path)?;
let diff = get_diff_raw(&repo, file_path, true, false, None)?; let diff = get_diff_raw(&repo, file_path, true, false, options)?;
let diff_count_positive = diff.deltas().len(); let diff_count_positive = diff.deltas().len();
let hunk_index = find_hunk_index(&diff, hunk_hash); let hunk_index = find_hunk_index(&diff, hunk_hash);
@ -112,7 +115,7 @@ pub fn unstage_hunk(
Ok, Ok,
)?; )?;
let diff = get_diff_raw(&repo, file_path, true, true, None)?; let diff = get_diff_raw(&repo, file_path, true, true, options)?;
if diff.deltas().len() != diff_count_positive { if diff.deltas().len() != diff_count_positive {
return Err(Error::Generic(format!( return Err(Error::Generic(format!(
@ -182,6 +185,7 @@ mod tests {
repo_path, repo_path,
file_path.to_str().unwrap(), file_path.to_str().unwrap(),
diff.hunks[0].header_hash, diff.hunks[0].header_hash,
None,
) )
.is_err()); .is_err());

View file

@ -991,7 +991,12 @@ impl App {
flags.insert(NeedsUpdate::ALL); flags.insert(NeedsUpdate::ALL);
} }
Action::ResetHunk(path, hash) => { Action::ResetHunk(path, hash) => {
sync::reset_hunk(&self.repo.borrow(), &path, hash)?; sync::reset_hunk(
&self.repo.borrow(),
&path,
hash,
Some(self.options.borrow().diff_options()),
)?;
flags.insert(NeedsUpdate::ALL); flags.insert(NeedsUpdate::ALL);
} }
Action::ResetLines(path, lines) => { Action::ResetLines(path, lines) => {

View file

@ -191,6 +191,7 @@ impl CompareCommitsComponent {
theme, theme,
key_config.clone(), key_config.clone(),
true, true,
options.clone(),
), ),
open_request: None, open_request: None,
git_diff: AsyncDiff::new(repo.borrow().clone(), sender), git_diff: AsyncDiff::new(repo.borrow().clone(), sender),

View file

@ -6,6 +6,7 @@ use super::{
use crate::{ use crate::{
components::{CommandInfo, Component, EventState}, components::{CommandInfo, Component, EventState},
keys::{key_match, SharedKeyConfig}, keys::{key_match, SharedKeyConfig},
options::SharedOptions,
queue::{Action, InternalEvent, NeedsUpdate, Queue, ResetItem}, queue::{Action, InternalEvent, NeedsUpdate, Queue, ResetItem},
string_utils::tabs_to_spaces, string_utils::tabs_to_spaces,
string_utils::trim_offset, string_utils::trim_offset,
@ -117,6 +118,7 @@ pub struct DiffComponent {
theme: SharedTheme, theme: SharedTheme,
key_config: SharedKeyConfig, key_config: SharedKeyConfig,
is_immutable: bool, is_immutable: bool,
options: SharedOptions,
} }
impl DiffComponent { impl DiffComponent {
@ -127,6 +129,7 @@ impl DiffComponent {
theme: SharedTheme, theme: SharedTheme,
key_config: SharedKeyConfig, key_config: SharedKeyConfig,
is_immutable: bool, is_immutable: bool,
options: SharedOptions,
) -> Self { ) -> Self {
Self { Self {
focused: false, focused: false,
@ -144,6 +147,7 @@ impl DiffComponent {
key_config, key_config,
is_immutable, is_immutable,
repo, repo,
options,
} }
} }
/// ///
@ -503,6 +507,7 @@ impl DiffComponent {
&self.repo.borrow(), &self.repo.borrow(),
&self.current.path, &self.current.path,
hash, hash,
Some(self.options.borrow().diff_options()),
)?; )?;
self.queue_update(); self.queue_update();
} }
@ -525,6 +530,7 @@ impl DiffComponent {
&self.repo.borrow(), &self.repo.borrow(),
&self.current.path, &self.current.path,
hash, hash,
Some(self.options.borrow().diff_options()),
)?; )?;
} }

View file

@ -89,6 +89,7 @@ impl FileRevlogComponent {
theme, theme,
key_config.clone(), key_config.clone(),
true, true,
options.clone(),
), ),
git_log: None, git_log: None,
git_diff: AsyncDiff::new( git_diff: AsyncDiff::new(

View file

@ -227,6 +227,7 @@ impl InspectCommitComponent {
theme, theme,
key_config.clone(), key_config.clone(),
true, true,
options.clone(),
), ),
open_request: None, open_request: None,
git_diff: AsyncDiff::new(repo.borrow().clone(), sender), git_diff: AsyncDiff::new(repo.borrow().clone(), sender),

View file

@ -195,6 +195,7 @@ impl Status {
theme, theme,
key_config.clone(), key_config.clone(),
false, false,
options.clone(),
), ),
git_diff: AsyncDiff::new(repo_clone.clone(), sender), git_diff: AsyncDiff::new(repo_clone.clone(), sender),
git_status_workdir: AsyncStatus::new( git_status_workdir: AsyncStatus::new(