diff options
author | Robert Bartlensky <bartlensky.robert@gmail.com> | 2023-07-26 20:45:10 +0100 |
---|---|---|
committer | Robert Bartlensky <bartlensky.robert@gmail.com> | 2023-07-26 20:45:10 +0100 |
commit | fb9e1b3950ab9b821ad402098c34bac46cfbd453 (patch) | |
tree | 547eef7eff99faad3a2a11637785971fa556f84e | |
parent | e16fcff80e899aefbe942e8ee206e2d4cc8bf579 (diff) |
Only update head_tree when we commit.
Fixes the case where if we pass `--dry-run` the additions/deletions
keep growing in number since we never "reset" the tree back.
-rw-r--r-- | src/lib.rs | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -255,7 +255,7 @@ fn run_with_repo(config: &Config, repo: &git2::Repository) -> Result<()> { .iter() .zip(hunks_with_commit.iter().skip(1).map(Some).chain([None])) { - head_tree = apply_hunk_to_tree( + let new_head_tree = apply_hunk_to_tree( &repo, &head_tree, ¤t.hunk_to_apply, @@ -279,9 +279,10 @@ fn run_with_repo(config: &Config, repo: &git2::Repository) -> Result<()> { .filter(|&msg| summary_counts[msg] == 1) .unwrap_or(&dest_commit_id); let diff = repo - .diff_tree_to_tree(Some(&head_commit.tree()?), Some(&head_tree), None)? + .diff_tree_to_tree(Some(&head_commit.tree()?), Some(&new_head_tree), None)? .stats()?; if !config.dry_run { + head_tree = new_head_tree; head_commit = repo.find_commit(repo.commit( Some("HEAD"), &signature, |