diff options
author | Robert Bartlensky <bartlensky.robert@gmail.com> | 2023-08-04 01:07:52 +0100 |
---|---|---|
committer | Robert Bartlensky <bartlensky.robert@gmail.com> | 2023-08-04 01:10:14 +0100 |
commit | c35b4dfce60399f649c4bbd0e5650ce6fe4fb923 (patch) | |
tree | feb1251163cce81dcb8d1f7c9ab51a9c8f1f29bf | |
parent | 48f2ab7c1f967e504e1dcd0e81b54822c3bf824c (diff) |
Update `head_tree` when no commit happens.
This regression was introduced in
fb9e1b3950ab9b821ad402098c34bac46cfbd453.
Moreover, the tests didn't catch it because they didn't check that
there are no leftover changes.
-rw-r--r-- | src/lib.rs | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -301,6 +301,9 @@ fn run_with_repo(config: &Config, repo: &git2::Repository) -> Result<()> { "header" => format!("+{},-{}", diff.insertions(), diff.deletions()), ); } + } else { + // we didn't commit anything, but we applied a hunk + head_tree = new_head_tree; } } @@ -500,6 +503,18 @@ lines ctx } + fn nothing_left_in_index(ctx: Context) { + let head = ctx.repo.head().unwrap().peel_to_tree().unwrap(); + let diff = ctx + .repo + .diff_tree_to_index(Some(&head), Some(&ctx.repo.index().unwrap()), None) + .unwrap(); + let stats = diff.stats().unwrap(); + assert_eq!(stats.files_changed(), 0); + assert_eq!(stats.insertions(), 0); + assert_eq!(stats.deletions(), 0); + } + #[test] fn multiple_fixups_per_commit() { let ctx = prepare_and_stage(); @@ -521,6 +536,8 @@ lines let mut revwalk = ctx.repo.revwalk().unwrap(); revwalk.push_head().unwrap(); assert_eq!(revwalk.count(), 3); + + nothing_left_in_index(ctx); } #[test] @@ -544,5 +561,7 @@ lines let mut revwalk = ctx.repo.revwalk().unwrap(); revwalk.push_head().unwrap(); assert_eq!(revwalk.count(), 2); + + nothing_left_in_index(ctx); } } |