Skip to content

Commit 8e0a5fb

Browse files
committed
fix hunk edits with non standard diff options
1 parent 403c5aa commit 8e0a5fb

File tree

8 files changed

+26
-6
lines changed

8 files changed

+26
-6
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
* fix commit dialog char count for multibyte characters ([#1726](https://github.com/extrawurst/gitui/issues/1726))
2626
* fix wrong hit highlighting in fuzzy find popup [[@UUGTech](https://github.com/UUGTech)] ([#1731](https://github.com/extrawurst/gitui/pull/1731))
2727
* fix symlink support for configuration files [[@TheBlackSheep3](https://github.com/TheBlackSheep3)] ([#1751](https://github.com/extrawurst/gitui/issues/1751))
28+
* fix hunk (un)staging/reset for # of context lines != 3 ([#1746](https://github.com/extrawurst/gitui/issues/1746))
2829

2930
## [0.23.0] - 2022-06-19
3031

asyncgit/src/sync/hunks.rs

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use super::{
2-
diff::{get_diff_raw, HunkHeader},
2+
diff::{get_diff_raw, DiffOptions, HunkHeader},
33
RepoPath,
44
};
55
use crate::{
@@ -15,12 +15,13 @@ pub fn stage_hunk(
1515
repo_path: &RepoPath,
1616
file_path: &str,
1717
hunk_hash: u64,
18+
options: Option<DiffOptions>,
1819
) -> Result<()> {
1920
scope_time!("stage_hunk");
2021

2122
let repo = repo(repo_path)?;
2223

23-
let diff = get_diff_raw(&repo, file_path, false, false, None)?;
24+
let diff = get_diff_raw(&repo, file_path, false, false, options)?;
2425

2526
let mut opt = ApplyOptions::new();
2627
opt.hunk_callback(|hunk| {
@@ -40,12 +41,13 @@ pub fn reset_hunk(
4041
repo_path: &RepoPath,
4142
file_path: &str,
4243
hunk_hash: u64,
44+
options: Option<DiffOptions>,
4345
) -> Result<()> {
4446
scope_time!("reset_hunk");
4547

4648
let repo = repo(repo_path)?;
4749

48-
let diff = get_diff_raw(&repo, file_path, false, false, None)?;
50+
let diff = get_diff_raw(&repo, file_path, false, false, options)?;
4951

5052
let hunk_index = find_hunk_index(&diff, hunk_hash);
5153
if let Some(hunk_index) = hunk_index {
@@ -98,12 +100,13 @@ pub fn unstage_hunk(
98100
repo_path: &RepoPath,
99101
file_path: &str,
100102
hunk_hash: u64,
103+
options: Option<DiffOptions>,
101104
) -> Result<bool> {
102105
scope_time!("revert_hunk");
103106

104107
let repo = repo(repo_path)?;
105108

106-
let diff = get_diff_raw(&repo, file_path, true, false, None)?;
109+
let diff = get_diff_raw(&repo, file_path, true, false, options)?;
107110
let diff_count_positive = diff.deltas().len();
108111

109112
let hunk_index = find_hunk_index(&diff, hunk_hash);
@@ -112,7 +115,7 @@ pub fn unstage_hunk(
112115
Ok,
113116
)?;
114117

115-
let diff = get_diff_raw(&repo, file_path, true, true, None)?;
118+
let diff = get_diff_raw(&repo, file_path, true, true, options)?;
116119

117120
if diff.deltas().len() != diff_count_positive {
118121
return Err(Error::Generic(format!(
@@ -182,6 +185,7 @@ mod tests {
182185
repo_path,
183186
file_path.to_str().unwrap(),
184187
diff.hunks[0].header_hash,
188+
None,
185189
)
186190
.is_err());
187191

src/app.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,12 @@ impl App {
991991
flags.insert(NeedsUpdate::ALL);
992992
}
993993
Action::ResetHunk(path, hash) => {
994-
sync::reset_hunk(&self.repo.borrow(), &path, hash)?;
994+
sync::reset_hunk(
995+
&self.repo.borrow(),
996+
&path,
997+
hash,
998+
Some(self.options.borrow().diff_options()),
999+
)?;
9951000
flags.insert(NeedsUpdate::ALL);
9961001
}
9971002
Action::ResetLines(path, lines) => {

src/components/compare_commits.rs

+1
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,7 @@ impl CompareCommitsComponent {
191191
theme,
192192
key_config.clone(),
193193
true,
194+
options.clone(),
194195
),
195196
open_request: None,
196197
git_diff: AsyncDiff::new(repo.borrow().clone(), sender),

src/components/diff.rs

+6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use super::{
66
use crate::{
77
components::{CommandInfo, Component, EventState},
88
keys::{key_match, SharedKeyConfig},
9+
options::SharedOptions,
910
queue::{Action, InternalEvent, NeedsUpdate, Queue, ResetItem},
1011
string_utils::tabs_to_spaces,
1112
string_utils::trim_offset,
@@ -117,6 +118,7 @@ pub struct DiffComponent {
117118
theme: SharedTheme,
118119
key_config: SharedKeyConfig,
119120
is_immutable: bool,
121+
options: SharedOptions,
120122
}
121123

122124
impl DiffComponent {
@@ -127,6 +129,7 @@ impl DiffComponent {
127129
theme: SharedTheme,
128130
key_config: SharedKeyConfig,
129131
is_immutable: bool,
132+
options: SharedOptions,
130133
) -> Self {
131134
Self {
132135
focused: false,
@@ -144,6 +147,7 @@ impl DiffComponent {
144147
key_config,
145148
is_immutable,
146149
repo,
150+
options,
147151
}
148152
}
149153
///
@@ -503,6 +507,7 @@ impl DiffComponent {
503507
&self.repo.borrow(),
504508
&self.current.path,
505509
hash,
510+
Some(self.options.borrow().diff_options()),
506511
)?;
507512
self.queue_update();
508513
}
@@ -525,6 +530,7 @@ impl DiffComponent {
525530
&self.repo.borrow(),
526531
&self.current.path,
527532
hash,
533+
Some(self.options.borrow().diff_options()),
528534
)?;
529535
}
530536

src/components/file_revlog.rs

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ impl FileRevlogComponent {
8989
theme,
9090
key_config.clone(),
9191
true,
92+
options.clone(),
9293
),
9394
git_log: None,
9495
git_diff: AsyncDiff::new(

src/components/inspect_commit.rs

+1
Original file line numberDiff line numberDiff line change
@@ -227,6 +227,7 @@ impl InspectCommitComponent {
227227
theme,
228228
key_config.clone(),
229229
true,
230+
options.clone(),
230231
),
231232
open_request: None,
232233
git_diff: AsyncDiff::new(repo.borrow().clone(), sender),

src/tabs/status.rs

+1
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,7 @@ impl Status {
195195
theme,
196196
key_config.clone(),
197197
false,
198+
options.clone(),
198199
),
199200
git_diff: AsyncDiff::new(repo_clone.clone(), sender),
200201
git_status_workdir: AsyncStatus::new(

0 commit comments

Comments
 (0)