Keep original timestamp on rebase

Squash commits of branch bugfix/keep_original_timestamp_on_rebase:

- Keep original timestamp on rebase
This commit is contained in:
Rene Pfeuffer
2025-02-20 09:58:56 +01:00
parent 844dc394e9
commit 8bcb814f94
4 changed files with 14 additions and 2 deletions

View File

@@ -66,12 +66,21 @@ class CommitHelper {
String message,
boolean sign,
ObjectId... parentCommitIds) throws IOException, CanceledException, UnsupportedSigningFormatException {
return createCommit(treeId, createPersonIdent(author), committer, message, sign, parentCommitIds);
}
ObjectId createCommit(ObjectId treeId,
PersonIdent author,
Person committer,
String message,
boolean sign,
ObjectId... parentCommitIds) throws IOException, CanceledException, UnsupportedSigningFormatException {
log.trace("create commit for tree {} and parent ids {} in repository {}", treeId, parentCommitIds, context.getRepository());
try (ObjectInserter inserter = repository.newObjectInserter()) {
CommitBuilder commitBuilder = new CommitBuilder();
commitBuilder.setTreeId(treeId);
commitBuilder.setParentIds(parentCommitIds);
commitBuilder.setAuthor(createPersonIdent(author));
commitBuilder.setAuthor(author);
commitBuilder.setCommitter(createPersonIdent(committer));
commitBuilder.setMessage(message);
if (sign) {

View File

@@ -85,7 +85,7 @@ class GitMergeRebase {
PersonIdent originalAuthor = commit.getAuthorIdent();
targetRevision = commitHelper.createCommit(
newTreeId,
new Person(originalAuthor.getName(), originalAuthor.getEmailAddress()),
originalAuthor,
request.getAuthor(),
commit.getFullMessage(),
request.isSign(),

View File

@@ -543,6 +543,7 @@ public class GitMergeCommandTest extends AbstractGitCommandTestBase {
assertThat(mergeCommit.getParent(0).name()).isEqualTo("fcd0ef1831e4002ac43ea539f4094334c79ea9ec");
assertThat(mergeCommit.getName()).isEqualTo(mergeCommandResult.getNewHeadRevision());
assertThat(mergeCommit.getName()).doesNotStartWith("91b99de908fcd04772798a31c308a64aea1a5523");
assertThat(mergeCommit.getAuthorIdent().getWhenAsInstant()).isEqualTo("2018-11-07T10:20:52Z"); // the timestamp of the original commit
}
@Test