diff options
author | Robin Stocker <robin@nibor.org> | 2012-10-07 17:18:58 +0200 |
---|---|---|
committer | Robin Stocker <robin@nibor.org> | 2012-10-08 00:31:27 +0200 |
commit | 79f33419ec073edf31a1db16ae9b11e69ee997a1 (patch) | |
tree | 0d96710ee0d70e4f92a58ed64ee65fe163618704 /org.eclipse.jgit.test | |
parent | c96b40d5921d68edb96afad38b9c171388af4e05 (diff) | |
download | jgit-79f33419ec073edf31a1db16ae9b11e69ee997a1.tar.gz jgit-79f33419ec073edf31a1db16ae9b11e69ee997a1.zip |
CommitCommand: Use original author on amend if author is not set
This way, callers don't have to parse author ident of HEAD themselves.
Bug: 362391
Change-Id: I383a817e6ed4707d637c52c007bc7b57728e6c85
Diffstat (limited to 'org.eclipse.jgit.test')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java index 3729387f32..3e73c7598e 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java @@ -48,7 +48,9 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.File; +import java.util.Date; import java.util.List; +import java.util.TimeZone; import org.eclipse.jgit.api.errors.WrongRepositoryStateException; import org.eclipse.jgit.diff.DiffEntry; @@ -57,6 +59,7 @@ import org.eclipse.jgit.lib.ConfigConstants; import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.FileMode; import org.eclipse.jgit.lib.ObjectId; +import org.eclipse.jgit.lib.PersonIdent; import org.eclipse.jgit.lib.RefUpdate; import org.eclipse.jgit.lib.RefUpdate.Result; import org.eclipse.jgit.lib.Repository; @@ -427,4 +430,45 @@ public class CommitCommandTest extends RepositoryTestCase { Git git = new Git(db); git.commit().setAmend(true).setMessage("initial commit").call(); } + + @Test + public void commitAmendWithoutAuthorShouldSetOriginalAuthorAndAuthorTime() + throws Exception { + Git git = new Git(db); + + writeTrashFile("file1", "file1"); + git.add().addFilepattern("file1").call(); + + final String authorName = "First Author"; + final String authorEmail = "author@example.org"; + final Date authorDate = new Date(1349621117000L); + PersonIdent firstAuthor = new PersonIdent(authorName, authorEmail, + authorDate, TimeZone.getTimeZone("UTC")); + git.commit().setMessage("initial commit").setAuthor(firstAuthor).call(); + + RevCommit amended = git.commit().setAmend(true) + .setMessage("amend commit").call(); + + PersonIdent amendedAuthor = amended.getAuthorIdent(); + assertEquals(authorName, amendedAuthor.getName()); + assertEquals(authorEmail, amendedAuthor.getEmailAddress()); + assertEquals(authorDate.getTime(), amendedAuthor.getWhen().getTime()); + } + + @Test + public void commitAmendWithAuthorShouldUseIt() throws Exception { + Git git = new Git(db); + + writeTrashFile("file1", "file1"); + git.add().addFilepattern("file1").call(); + git.commit().setMessage("initial commit").call(); + + RevCommit amended = git.commit().setAmend(true) + .setAuthor("New Author", "newauthor@example.org") + .setMessage("amend commit").call(); + + PersonIdent amendedAuthor = amended.getAuthorIdent(); + assertEquals("New Author", amendedAuthor.getName()); + assertEquals("newauthor@example.org", amendedAuthor.getEmailAddress()); + } } |