Trim author/committer name and email in commit header

C Git trims name and email before inserting them into the commit header
so that " A U Thor  " and "  author@example.com " becomes 
"A U Thor <author@example.com>" with a single separating space.

This changes PersonIdent#toExternalString() to trim name and email
before concatenating them.

Change-Id: Idd77b659d0db957626824f6632e2da38d7731625
Signed-off-by: Rüdiger Herrmann <ruediger.herrmann@gmx.de>
This commit is contained in:
Rüdiger Herrmann 2014-10-17 13:05:41 +02:00 committed by Matthias Sohn
parent 1cb5668441
commit a4c2c8a3ee
2 changed files with 14 additions and 2 deletions

View File

@ -44,6 +44,7 @@
package org.eclipse.jgit.lib;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import java.util.Date;
import java.util.TimeZone;
@ -83,4 +84,15 @@ public void nullForNameShouldThrowIllegalArgumentException() {
public void nullForEmailShouldThrowIllegalArgumentException() {
new PersonIdent("A U Thor", null);
}
@Test
public void testToExternalStringTrimsNameAndEmail() throws Exception {
PersonIdent personIdent = new PersonIdent(" A U Thor ",
" author@example.com ");
String externalString = personIdent.toExternalString();
assertTrue(externalString.startsWith("A U Thor <author@example.com>"));
}
}

View File

@ -254,9 +254,9 @@ && getEmailAddress().equals(p.getEmailAddress())
*/
public String toExternalString() {
final StringBuilder r = new StringBuilder();
r.append(getName());
r.append(getName().trim());
r.append(" <"); //$NON-NLS-1$
r.append(getEmailAddress());
r.append(getEmailAddress().trim());
r.append("> "); //$NON-NLS-1$
r.append(when / 1000);
r.append(' ');