diff --git a/asyncgit/src/sync/staging/mod.rs b/asyncgit/src/sync/staging/mod.rs index 72018aa3..6e66c38e 100644 --- a/asyncgit/src/sync/staging/mod.rs +++ b/asyncgit/src/sync/staging/mod.rs @@ -121,7 +121,9 @@ pub(crate) fn apply_selection( .trim() ); - if hunk_line.origin() == '<' { + if hunk_line.origin() == '<' + || hunk_line.origin() == '>' + { break; } diff --git a/asyncgit/src/sync/staging/stage_tracked.rs b/asyncgit/src/sync/staging/stage_tracked.rs index 2872c316..d1d4d8dd 100644 --- a/asyncgit/src/sync/staging/stage_tracked.rs +++ b/asyncgit/src/sync/staging/stage_tracked.rs @@ -107,6 +107,49 @@ mod test { ); } + #[test] + fn test_panic_stage_no_newline() { + static FILE_1: &str = r"a = 1 +b = 2"; + + static FILE_2: &str = r"a = 2 +b = 3 +c = 4"; + + let (path, repo) = repo_init().unwrap(); + let path = path.path().to_str().unwrap(); + + write_commit_file(&repo, "test.txt", FILE_1, "c1"); + + repo_write_file(&repo, "test.txt", FILE_2).unwrap(); + + stage_lines( + path, + "test.txt", + false, + &[ + DiffLinePosition { + old_lineno: Some(1), + new_lineno: None, + }, + DiffLinePosition { + old_lineno: Some(2), + new_lineno: None, + }, + ], + ) + .unwrap(); + + let diff = + get_diff(path, String::from("test.txt"), true).unwrap(); + + assert_eq!(diff.lines, 5); + assert_eq!( + diff.hunks[0].lines[0].content, + String::from("@@ -1,2 +1 @@\n") + ); + } + #[test] fn test_unstage() { static FILE_1: &str = r"0