From a4c2c8a3eea8a28b34e298f5ef3ccbd56dd87fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=BCdiger=20Herrmann?= Date: Fri, 17 Oct 2014 13:05:41 +0200 Subject: [PATCH] Trim author/committer name and email in commit header MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 " 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 --- .../org/eclipse/jgit/lib/T0001_PersonIdentTest.java | 12 ++++++++++++ .../src/org/eclipse/jgit/lib/PersonIdent.java | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java index 1b7276bf7..315c49560 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/T0001_PersonIdentTest.java @@ -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 class T0001_PersonIdentTest { 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 ")); + } + } diff --git a/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java b/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java index 69f7fd440..8f7e3eff7 100644 --- a/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java +++ b/org.eclipse.jgit/src/org/eclipse/jgit/lib/PersonIdent.java @@ -254,9 +254,9 @@ public class PersonIdent implements Serializable { */ 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(' ');