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 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))
* 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

View File

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

View File

@ -991,7 +991,12 @@ impl App {
flags.insert(NeedsUpdate::ALL);
}
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);
}
Action::ResetLines(path, lines) => {

View File

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

View File

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

View File

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

View File

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

View File

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