Overwrite committer on amend when gpgsign = false (#2792)

This commit is contained in:
Christoph Rüßler 2025-11-28 21:11:22 +01:00 committed by GitHub
parent 3de0b23ef2
commit a6d6f31885
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 53 additions and 1 deletions

View file

@ -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

View file

@ -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");