summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorextrawurst <776816+extrawurst@users.noreply.github.com>2023-08-10 14:48:36 +0200
committerGitHub <noreply@github.com>2023-08-10 14:48:36 +0200
commit53988ba4e0c07bc053a50f8a48bbd099a199fee2 (patch)
tree78f3a26a21ee45e8aa12c94219b51dc0b84f824f
parent495d4d5da76b64a378c2927efdc8b6494d9a0f3e (diff)
fix hunk edits with non standard diff options (#1803)
-rw-r--r--CHANGELOG.md3
-rw-r--r--asyncgit/src/sync/hunks.rs14
-rw-r--r--src/app.rs7
-rw-r--r--src/components/compare_commits.rs1
-rw-r--r--src/components/diff.rs6
-rw-r--r--src/components/file_revlog.rs1
-rw-r--r--src/components/inspect_commit.rs1
-rw-r--r--src/tabs/status.rs1
8 files changed, 27 insertions, 7 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 94fa0903..f5d89275 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -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
diff --git a/asyncgit/src/sync/hunks.rs b/asyncgit/src/sync/hunks.rs
index d5d89601..672f9d66 100644
--- a/asyncgit/src/sync/hunks.rs
+++ b/asyncgit/src/sync/hunks.rs
@@ -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());
diff --git a/src/app.rs b/src/app.rs
index 1811b508..848c4e6b 100644
--- a/src/app.rs
+++ b/src/app.rs
@@ -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) => {
diff --git a/src/components/compare_commits.rs b/src/components/compare_commits.rs
index bd92750a..db5ea23c 100644
--- a/src/components/compare_commits.rs
+++ b/src/components/compare_commits.rs
@@ -191,6 +191,7 @@ impl CompareCommitsComponent {
theme,
key_config.clone(),
true,
+ options.clone(),
),
open_request: None,
git_diff: AsyncDiff::new(repo.borrow().clone(), sender),
diff --git a/src/components/diff.rs b/src/components/diff.rs
index bec75722..d4051271 100644
--- a/src/components/diff.rs
+++ b/src/components/diff.rs
@@ -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()),
)?;
}
diff --git a/src/components/file_revlog.rs b/src/components/file_revlog.rs
index 7d6dbc2b..fa571bde 100644
--- a/src/components/file_revlog.rs
+++ b/src/components/file_revlog.rs
@@ -89,6 +89,7 @@ impl FileRevlogComponent {
theme,
key_config.clone(),
true,
+ options.clone(),
),
git_log: None,
git_diff: AsyncDiff::new(
diff --git a/src/components/inspect_commit.rs b/src/components/inspect_commit.rs
index 0ddcd30b..664e6c2d 100644
--- a/src/components/inspect_commit.rs
+++ b/src/components/inspect_commit.rs
@@ -227,6 +227,7 @@ impl InspectCommitComponent {
theme,
key_config.clone(),
true,
+ options.clone(),
),
open_request: None,
git_diff: AsyncDiff::new(repo.borrow().clone(), sender),
diff --git a/src/tabs/status.rs b/src/tabs/status.rs
index 0539d5ba..ec49cdc1 100644
--- a/src/tabs/status.rs
+++ b/src/tabs/status.rs
@@ -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(