aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-scanner-engine/src/test
diff options
context:
space:
mode:
authorSteve Marion <steve.marion@sonarsource.com>2022-10-11 14:22:10 +0200
committersonartech <sonartech@sonarsource.com>2022-10-12 20:03:43 +0000
commitbcfb1cac55137b838da7a93385b20e0e5ed47abb (patch)
treecfd6353f7db14037bed10117fcf229b094266578 /sonar-scanner-engine/src/test
parent3810d7b2651827bca469c291340b8fb89fe61f3b (diff)
downloadsonarqube-bcfb1cac55137b838da7a93385b20e0e5ed47abb.tar.gz
sonarqube-bcfb1cac55137b838da7a93385b20e0e5ed47abb.zip
SONAR-17353 native git blame reads author instead of committer
Diffstat (limited to 'sonar-scanner-engine/src/test')
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitBlameCommandTest.java31
-rw-r--r--sonar-scanner-engine/src/test/resources/org/sonar/scm/git/test-repos/dummy-git-different-committer.zipbin0 -> 65543 bytes
2 files changed, 31 insertions, 0 deletions
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 56402740d9c..734edac0262 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
@@ -119,6 +119,37 @@ public class GitBlameCommandTest {
}
@Test
+ public void blame_different_author_and_committer() throws Exception {
+ File projectDir = createNewTempFolder();
+ javaUnzip("dummy-git-different-committer.zip", projectDir);
+ File baseDir = new File(projectDir, "dummy-git");
+
+ List<BlameLine> blame = blameCommand.blame(baseDir.toPath(), DUMMY_JAVA);
+
+ Date revisionDate1 = DateUtils.parseDateTime("2012-07-17T16:12:48+0200");
+ String revision1 = "6b3aab35a3ea32c1636fee56f996e677653c48ea";
+ String author1 = "david@gageot.net";
+
+ // second commit, which has a commit date different than the author date
+ Date revisionDate2 = DateUtils.parseDateTime("2022-10-11T14:14:26+0200");
+ String revision2 = "7609f824d5ff7018bebf107cdbe4edcc901b574f";
+ String author2 = "duarte.meneses@sonarsource.com";
+
+ List<BlameLine> expectedBlame = new LinkedList<>();
+ for (int i = 0; i < 25; i++) {
+ expectedBlame.add(new BlameLine().revision(revision1).date(revisionDate1).author(author1));
+ }
+ for (int i = 0; i < 3; i++) {
+ expectedBlame.add(new BlameLine().revision(revision2).date(revisionDate2).author(author2));
+ }
+ for (int i = 0; i < 1; i++) {
+ expectedBlame.add(new BlameLine().revision(revision1).date(revisionDate1).author(author1));
+ }
+
+ assertThat(blame).isEqualTo(expectedBlame);
+ }
+
+ @Test
public void git_blame_uses_safe_local_repository() throws Exception {
File projectDir = createNewTempFolder();
File baseDir = new File(projectDir, "dummy-git");
diff --git a/sonar-scanner-engine/src/test/resources/org/sonar/scm/git/test-repos/dummy-git-different-committer.zip b/sonar-scanner-engine/src/test/resources/org/sonar/scm/git/test-repos/dummy-git-different-committer.zip
new file mode 100644
index 00000000000..a3cd5a99dea
--- /dev/null
+++ b/sonar-scanner-engine/src/test/resources/org/sonar/scm/git/test-repos/dummy-git-different-committer.zip
Binary files differ