aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java7
-rw-r--r--sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesTest.java1
2 files changed, 7 insertions, 1 deletions
diff --git a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java
index 2c49da58963..9f53d9ad8a2 100644
--- a/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java
+++ b/sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java
@@ -22,6 +22,7 @@ package org.sonar.scanner.scan.branch;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.Objects;
import javax.annotation.CheckForNull;
import javax.annotation.concurrent.Immutable;
@@ -30,6 +31,9 @@ import javax.annotation.concurrent.Immutable;
*/
@Immutable
public class ProjectBranches {
+ // matches server-side default when creating a project. See BranchDto#DEFAULT_MAIN_BRANCH_NAME
+ private static final String DEFAULT_MAIN_BRANCH_NAME = "master";
+
private final Map<String, BranchInfo> branches;
private final String defaultBranchName;
@@ -43,7 +47,8 @@ public class ProjectBranches {
mainBranchName = branchName;
}
}
- this.defaultBranchName = mainBranchName;
+
+ this.defaultBranchName = Objects.requireNonNullElse(mainBranchName, DEFAULT_MAIN_BRANCH_NAME);
}
@CheckForNull
diff --git a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesTest.java b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesTest.java
index d9f07a3df16..42daac13391 100644
--- a/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesTest.java
+++ b/sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesTest.java
@@ -70,5 +70,6 @@ public class ProjectBranchesTest {
public void isEmpty() {
assertThat(underTest.isEmpty()).isFalse();
assertThat(new ProjectBranches(Collections.emptyList()).isEmpty()).isTrue();
+ assertThat(new ProjectBranches(Collections.emptyList()).defaultBranchName()).isEqualTo("master");
}
}