aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2022-06-30 12:24:10 -0500
committersonartech <sonartech@sonarsource.com>2022-07-06 20:03:56 +0000
commitb31d435c35d2e104b225a6f722e459616b0cb8af (patch)
tree87bf24fbdbb4a42d8a165cbb63f57d1227028a47 /sonar-scanner-engine
parente50acc4b9cb0f32bea6efc8ae7c8f6875170adeb (diff)
downloadsonarqube-b31d435c35d2e104b225a6f722e459616b0cb8af.tar.gz
sonarqube-b31d435c35d2e104b225a6f722e459616b0cb8af.zip
SONAR-16634 Native git blame fails if email address contains spaces
Diffstat (limited to 'sonar-scanner-engine')
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scm/git/GitBlameCommand.java2
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitBlameCommandTest.java24
2 files changed, 22 insertions, 4 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scm/git/GitBlameCommand.java b/sonar-scanner-engine/src/main/java/org/sonar/scm/git/GitBlameCommand.java
index 171ea50175f..777dd28c0f5 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scm/git/GitBlameCommand.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scm/git/GitBlameCommand.java
@@ -46,7 +46,7 @@ public class GitBlameCommand {
protected static final String GIT_DIR_FORCE_FLAG = "-C";
private static final Logger LOG = Loggers.get(GitBlameCommand.class);
- private static final Pattern EMAIL_PATTERN = Pattern.compile("<(\\S*?)>");
+ private static final Pattern EMAIL_PATTERN = Pattern.compile("<(.*?)>");
private static final String COMMITTER_TIME = "committer-time ";
private static final String COMMITTER_MAIL = "committer-mail ";
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitBlameCommandTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitBlameCommandTest.java
index 9d914e1bb9b..56402740d9c 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitBlameCommandTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitBlameCommandTest.java
@@ -244,6 +244,21 @@ public class GitBlameCommandTest {
}
@Test
+ public void blame_mail_with_spaces_doesnt_fail() throws Exception {
+ Path baseDir = temp.newFolder().toPath();
+ Git git = createRepository(baseDir);
+ String filePath = "file.txt";
+ createFile(filePath, "line", baseDir);
+ commit(git, filePath, "my DOT name AT server DOT com");
+
+ GitBlameCommand blameCommand = new GitBlameCommand(System2.INSTANCE, processWrapperFactory);
+ assertThat(blameCommand.checkIfEnabled()).isTrue();
+ List<BlameLine> blame = blameCommand.blame(baseDir, filePath);
+ assertThat(blame).hasSize(1);
+ assertThat(blame.get(0).author()).isEqualTo("my DOT name AT server DOT com");
+ }
+
+ @Test
public void do_not_execute() throws Exception {
Path baseDir = temp.newFolder().toPath();
Git git = createRepository(baseDir);
@@ -300,13 +315,16 @@ public class GitBlameCommandTest {
}
private void commitWithNoEmail(Git git, String path) throws GitAPIException {
- git.add().addFilepattern(path).call();
- git.commit().setCommitter("joe", "").setMessage("msg").call();
+ commit(git, path, "");
}
private void commit(Git git, String path) throws GitAPIException {
+ commit(git, path, "email@email.com");
+ }
+
+ private void commit(Git git, String path, String email) throws GitAPIException {
git.add().addFilepattern(path).call();
- git.commit().setCommitter("joe", "email@email.com").setMessage("msg").call();
+ git.commit().setCommitter("joe", email).setMessage("msg").call();
}
private File createNewTempFolder() throws IOException {