summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Jung <tummychow511@gmail.com>2023-08-03 20:27:05 -0400
committerGitHub <noreply@github.com>2023-08-03 20:27:05 -0400
commite0a9f80d6074461c712409f32eda62396e8b8cb4 (patch)
treefeb1251163cce81dcb8d1f7c9ab51a9c8f1f29bf
parent48f2ab7c1f967e504e1dcd0e81b54822c3bf824c (diff)
parentc35b4dfce60399f649c4bbd0e5650ce6fe4fb923 (diff)
Merge pull request #93 from rbartlensky/fix-one-fixup-per-commit
Update `head_tree` when no commit happens.
-rw-r--r--src/lib.rs19
1 files changed, 19 insertions, 0 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 92bde10..d54d0c7 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -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);
}
}