mirror of
https://github.com/extrawurst/gitui.git
synced 2024-11-23 03:32:30 +03:00
fix hunk edits with non standard diff options (#1803)
This commit is contained in:
parent
495d4d5da7
commit
53988ba4e0
@ -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
|
||||
|
||||
|
@ -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());
|
||||
|
||||
|
@ -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) => {
|
||||
|
@ -191,6 +191,7 @@ impl CompareCommitsComponent {
|
||||
theme,
|
||||
key_config.clone(),
|
||||
true,
|
||||
options.clone(),
|
||||
),
|
||||
open_request: None,
|
||||
git_diff: AsyncDiff::new(repo.borrow().clone(), sender),
|
||||
|
@ -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()),
|
||||
)?;
|
||||
}
|
||||
|
||||
|
@ -89,6 +89,7 @@ impl FileRevlogComponent {
|
||||
theme,
|
||||
key_config.clone(),
|
||||
true,
|
||||
options.clone(),
|
||||
),
|
||||
git_log: None,
|
||||
git_diff: AsyncDiff::new(
|
||||
|
@ -227,6 +227,7 @@ impl InspectCommitComponent {
|
||||
theme,
|
||||
key_config.clone(),
|
||||
true,
|
||||
options.clone(),
|
||||
),
|
||||
open_request: None,
|
||||
git_diff: AsyncDiff::new(repo.borrow().clone(), sender),
|
||||
|
@ -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(
|
||||
|
Loading…
Reference in New Issue
Block a user