Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
53 changes: 52 additions & 1 deletion asyncgit/src/sync/commit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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");
Expand Down
Loading