diff --git a/CHANGELOG.md b/CHANGELOG.md index e5b377c997..2aa460c18e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 * print slightly nicer errors when failing to create a directory [[@linkmauve](https://github.com/linkmauve)] (https://github.com/gitui-org/gitui/pull/2728) * When the terminal is insufficient to display all the commands, the cmdbar_bg configuration color does not fully take effect. ([#2347](https://github.com/extrawurst/gitui/issues/2347)) * disable blame and history popup keybinds for untracked files [[@kpbaks](https://github.com/kpbaks)] ([#2489](https://github.com/gitui-org/gitui/pull/2489)) +* overwrite committer on amend when `gpgsign` is `false` [[@cruessler](https://github.com/cruessler)] ([#2784](https://github.com/gitui-org/gitui/issues/2784)) ## [0.27.0] - 2024-01-14 diff --git a/asyncgit/src/sync/commit.rs b/asyncgit/src/sync/commit.rs index f4e0b194ea..b88f055c10 100644 --- a/asyncgit/src/sync/commit.rs +++ b/asyncgit/src/sync/commit.rs @@ -40,10 +40,12 @@ pub fn amend( return Err(Error::SignAmendNonLastCommit); } + let committer = signature_allow_undefined_name(&repo)?; + let new_id = commit.amend( Some("HEAD"), None, - None, + Some(&committer), // Passing a value will overwrite the committer. None, Some(msg), Some(&tree), @@ -307,6 +309,55 @@ mod tests { Ok(()) } + #[test] + fn test_amend_with_different_user() { + let file_path1 = Path::new("foo"); + let file_path2 = Path::new("foo2"); + let (_td, repo) = repo_init_empty().unwrap(); + let root = repo.path().parent().unwrap(); + let repo_path: &RepoPath = + &root.as_os_str().to_str().unwrap().into(); + + File::create(root.join(file_path1)) + .unwrap() + .write_all(b"test1") + .unwrap(); + + stage_add_file(repo_path, file_path1).unwrap(); + let id = commit(repo_path, "commit msg").unwrap(); + + let amended_details = + get_commit_details(repo_path, id).unwrap(); + + assert_eq!(amended_details.committer, None); + + File::create(root.join(file_path2)) + .unwrap() + .write_all(b"test2") + .unwrap(); + + stage_add_file(repo_path, file_path2).unwrap(); + + repo.config() + .unwrap() + .set_str("user.name", "changed name") + .unwrap(); + repo.config() + .unwrap() + .set_str("user.email", "changed@example.com") + .unwrap(); + + let new_id = amend(repo_path, id, "amended").unwrap(); + + let amended_details = + get_commit_details(repo_path, new_id).unwrap(); + assert_eq!(amended_details.author.name, "name"); + assert_eq!(amended_details.author.email, "email"); + let committer = amended_details.committer.unwrap(); + assert_eq!(committer.name, "changed name"); + assert_eq!(committer.email, "changed@example.com"); + } + #[test] fn test_tag() -> Result<()> { let file_path = Path::new("foo");