Skip to content

Commit a6d6f31

Browse files
authored
Overwrite committer on amend when gpgsign = false (#2792)
1 parent 3de0b23 commit a6d6f31

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3838
* print slightly nicer errors when failing to create a directory [[@linkmauve](https://github.com/linkmauve)] (https://github.com/gitui-org/gitui/pull/2728)
3939
* 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))
4040
* disable blame and history popup keybinds for untracked files [[@kpbaks](https://github.com/kpbaks)] ([#2489](https://github.com/gitui-org/gitui/pull/2489))
41+
* overwrite committer on amend when `gpgsign` is `false` [[@cruessler](https://github.com/cruessler)] ([#2784](https://github.com/gitui-org/gitui/issues/2784))
4142

4243
## [0.27.0] - 2024-01-14
4344

asyncgit/src/sync/commit.rs

Lines changed: 52 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,10 +40,12 @@ pub fn amend(
4040
return Err(Error::SignAmendNonLastCommit);
4141
}
4242

43+
let committer = signature_allow_undefined_name(&repo)?;
44+
4345
let new_id = commit.amend(
4446
Some("HEAD"),
4547
None,
46-
None,
48+
Some(&committer), // Passing a value will overwrite the committer.
4749
None,
4850
Some(msg),
4951
Some(&tree),
@@ -307,6 +309,55 @@ mod tests {
307309
Ok(())
308310
}
309311

312+
#[test]
313+
fn test_amend_with_different_user() {
314+
let file_path1 = Path::new("foo");
315+
let file_path2 = Path::new("foo2");
316+
let (_td, repo) = repo_init_empty().unwrap();
317+
let root = repo.path().parent().unwrap();
318+
let repo_path: &RepoPath =
319+
&root.as_os_str().to_str().unwrap().into();
320+
321+
File::create(root.join(file_path1))
322+
.unwrap()
323+
.write_all(b"test1")
324+
.unwrap();
325+
326+
stage_add_file(repo_path, file_path1).unwrap();
327+
let id = commit(repo_path, "commit msg").unwrap();
328+
329+
let amended_details =
330+
get_commit_details(repo_path, id).unwrap();
331+
332+
assert_eq!(amended_details.committer, None);
333+
334+
File::create(root.join(file_path2))
335+
.unwrap()
336+
.write_all(b"test2")
337+
.unwrap();
338+
339+
stage_add_file(repo_path, file_path2).unwrap();
340+
341+
repo.config()
342+
.unwrap()
343+
.set_str("user.name", "changed name")
344+
.unwrap();
345+
repo.config()
346+
.unwrap()
347+
.set_str("user.email", "changed@example.com")
348+
.unwrap();
349+
350+
let new_id = amend(repo_path, id, "amended").unwrap();
351+
352+
let amended_details =
353+
get_commit_details(repo_path, new_id).unwrap();
354+
assert_eq!(amended_details.author.name, "name");
355+
assert_eq!(amended_details.author.email, "email");
356+
let committer = amended_details.committer.unwrap();
357+
assert_eq!(committer.name, "changed name");
358+
assert_eq!(committer.email, "changed@example.com");
359+
}
360+
310361
#[test]
311362
fn test_tag() -> Result<()> {
312363
let file_path = Path::new("foo");

0 commit comments

Comments
 (0)