]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17524 changing default branch name for projects
authorLukasz Jarocki <lukasz.jarocki@sonarsource.com>
Mon, 31 Oct 2022 11:25:54 +0000 (12:25 +0100)
committersonartech <sonartech@sonarsource.com>
Tue, 1 Nov 2022 20:03:09 +0000 (20:03 +0000)
46 files changed:
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/BranchLoader.java
server/sonar-ce-task-projectanalysis/src/main/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImpl.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/analysis/AnalysisMetadataHolderImplTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/BranchLoaderTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/ComponentUuidFactoryWithMigrationTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/component/DefaultBranchImplTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/BuildComponentTreeStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/QualityGateEventsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ReportPersistComponentsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/SendIssueNotificationsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ValidateProjectStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectanalysis/step/ViewsPersistComponentsStepTest.java
server/sonar-ce-task-projectanalysis/src/test/java/org/sonar/ce/task/projectexport/branches/ExportBranchesStepTest.java
server/sonar-ce/src/main/java/org/sonar/ce/container/ComputeEngineContainerImpl.java
server/sonar-db-dao/src/main/java/org/sonar/db/component/BranchDto.java
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
server/sonar-db-dao/src/test/java/org/sonar/db/measure/LiveMeasureDaoTest.java
server/sonar-db-dao/src/testFixtures/java/org/sonar/db/component/ComponentTesting.java
server/sonar-server-common/src/main/java/org/sonar/server/project/DefaultBranchNameResolver.java [new file with mode: 0644]
server/sonar-webserver-es/src/test/java/org/sonar/server/issue/index/IssueQueryFactoryTest.java
server/sonar-webserver-webapi/src/main/java/org/sonar/server/component/ComponentUpdater.java
server/sonar-webserver-webapi/src/main/resources/org/sonar/server/branch/ws/list-example.json
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/azure/ImportAzureProjectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/bitbucketserver/ImportBitbucketServerProjectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/almintegration/ws/gitlab/ImportGitLabProjectActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/ListActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/branch/ws/SetAutomaticDeletionProtectionActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentFinderTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ComponentUpdaterTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/ShowActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/component/ws/TreeActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/PullTaintActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/issue/ws/SearchActionComponentsTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/measure/ws/ComponentTreeActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/ListActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/newcodeperiod/ws/SetActionTest.java
server/sonar-webserver-webapi/src/test/java/org/sonar/server/projectanalysis/ws/SetBaselineActionTest.java
server/sonar-webserver/src/main/java/org/sonar/server/platform/platformlevel/PlatformLevel4.java
sonar-scanner-engine/src/main/java/org/sonar/scanner/scan/branch/ProjectBranches.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/mediumtest/branch/BranchMediumTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/DefaultNewCodePeriodLoaderTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/repository/ReferenceBranchSupplierTest.java
sonar-scanner-engine/src/test/java/org/sonar/scanner/scan/branch/ProjectBranchesTest.java
sonar-scanner-engine/src/test/java/org/sonar/scm/git/GitScmProviderTest.java

index 3eb24b243ac83ee028a9bcae27bc87452715640a..b0e79f884900e569a74d327ffe8423eb47e0e431 100644 (file)
  */
 package org.sonar.ce.task.projectanalysis.component;
 
+import javax.annotation.Nullable;
+import javax.inject.Inject;
 import org.sonar.api.utils.MessageException;
 import org.sonar.ce.task.projectanalysis.analysis.MutableAnalysisMetadataHolder;
 import org.sonar.scanner.protocol.output.ScannerReport;
-import static org.sonar.scanner.protocol.output.ScannerReport.Metadata.BranchType.UNSET;
 
-import javax.annotation.Nullable;
-import javax.inject.Inject;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
+import static org.sonar.scanner.protocol.output.ScannerReport.Metadata.BranchType.UNSET;
 
 public class BranchLoader {
   private final MutableAnalysisMetadataHolder metadataHolder;
@@ -47,7 +48,7 @@ public class BranchLoader {
     } else if (hasBranchProperties(metadata)) {
       throw MessageException.of("Current edition does not support branch feature");
     } else {
-      metadataHolder.setBranch(new DefaultBranchImpl());
+      metadataHolder.setBranch(new DefaultBranchImpl(DEFAULT_PROJECT_MAIN_BRANCH_NAME));
     }
   }
 
index b7d3c0d5808b8ccfc887ac7b49b6b67dfcfc2a82..67f12196ef0f630efdfb93ca46c9def4dc76b897 100644 (file)
@@ -20,7 +20,6 @@
 package org.sonar.ce.task.projectanalysis.component;
 
 import org.sonar.ce.task.projectanalysis.analysis.Branch;
-import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.BranchType;
 
 /**
@@ -30,8 +29,8 @@ import org.sonar.db.component.BranchType;
 public class DefaultBranchImpl implements Branch {
   private final String branchName;
 
-  public DefaultBranchImpl() {
-    this.branchName = BranchDto.DEFAULT_MAIN_BRANCH_NAME;
+  public DefaultBranchImpl(String branch) {
+    this.branchName = branch;
   }
 
   @Override
index 0016009a0b30e9e4ace01883760897962b1afb9b..6362ab8ca685cc4a04b85ef4fe7f37723eb3608a 100644 (file)
@@ -38,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.core.platform.EditionProvider.Edition;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 
 @RunWith(DataProviderRunner.class)
@@ -210,9 +211,9 @@ public class AnalysisMetadataHolderImplTest {
   public void set_branch() {
     AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider);
 
-    underTest.setBranch(new DefaultBranchImpl());
+    underTest.setBranch(new DefaultBranchImpl(DEFAULT_PROJECT_MAIN_BRANCH_NAME));
 
-    assertThat(underTest.getBranch().getName()).isEqualTo("master");
+    assertThat(underTest.getBranch().getName()).isEqualTo("main");
   }
 
   @Test
@@ -225,9 +226,9 @@ public class AnalysisMetadataHolderImplTest {
   @Test
   public void setBranch_throws_ISE_when_called_twice() {
     AnalysisMetadataHolderImpl underTest = new AnalysisMetadataHolderImpl(editionProvider);
-    underTest.setBranch(new DefaultBranchImpl());
+    underTest.setBranch(new DefaultBranchImpl(DEFAULT_PROJECT_MAIN_BRANCH_NAME));
 
-    assertThatThrownBy(() -> underTest.setBranch(new DefaultBranchImpl()))
+    assertThatThrownBy(() -> underTest.setBranch(new DefaultBranchImpl("main")))
       .isInstanceOf(IllegalStateException.class)
       .hasMessage("Branch has already been set");
   }
index 1ef830545c32ea7814401cadcace0223c575c3d9..fd0787729acde5cd8b262a298d1cb350c81c55c8 100644 (file)
@@ -60,7 +60,7 @@ public class BranchLoaderTest {
 
     Branch branch = metadataHolder.getBranch();
     assertThat(branch.isMain()).isTrue();
-    assertThat(branch.getName()).isEqualTo(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
+    assertThat(branch.getName()).isEqualTo(BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME);
   }
 
   @Test
index 7f3839bab0f07ed53ab1902e3a39b35f95130d29..c2ff3c08ab73090e2a48f747ab56117d32ff2f3b 100644 (file)
@@ -32,9 +32,10 @@ import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 
 public class ComponentUuidFactoryWithMigrationTest {
-  private final Branch mainBranch = new DefaultBranchImpl();
+  private final Branch mainBranch = new DefaultBranchImpl(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
   private Function<String, String> pathToKey = path -> path != null ? "project:" + path : "project";
index b818211145956fe3d2e04efe2724ce3b0f3ced61..e8bfcd84658a4813f8d9f5a75e6c292027eb2524 100644 (file)
 package org.sonar.ce.task.projectanalysis.component;
 
 import org.junit.Test;
-import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.BranchType;
 import org.sonar.scanner.protocol.output.ScannerReport;
 import org.sonar.scanner.protocol.output.ScannerReport.Component.ComponentType;
 
 import static org.assertj.core.api.Assertions.assertThat;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 
 public class DefaultBranchImplTest {
   private static final String PROJECT_KEY = "P";
@@ -34,11 +34,11 @@ public class DefaultBranchImplTest {
 
   @Test
   public void default_branch_represents_the_project() {
-    DefaultBranchImpl branch = new DefaultBranchImpl();
+    DefaultBranchImpl branch = new DefaultBranchImpl(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
 
     assertThat(branch.isMain()).isTrue();
     assertThat(branch.getType()).isEqualTo(BranchType.BRANCH);
-    assertThat(branch.getName()).isEqualTo(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
+    assertThat(branch.getName()).isEqualTo(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
     assertThat(branch.supportsCrossProjectCpd()).isTrue();
 
     assertThat(branch.generateKey(PROJECT_KEY, null)).isEqualTo("P");
index b94d867192d31d7600ae9befe9f9e99f3d3dc167..00ab641116e1c4b96d4ac63d136dbf870a764ce2 100644 (file)
@@ -56,6 +56,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
@@ -558,7 +559,7 @@ public class BuildComponentTreeStepTest {
   }
 
   private void setAnalysisMetadataHolder(boolean isPr) {
-    Branch branch = isPr ? new PrBranch() : new DefaultBranchImpl();
+    Branch branch = isPr ? new PrBranch(DEFAULT_PROJECT_MAIN_BRANCH_NAME) : new DefaultBranchImpl(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
     analysisMetadataHolder.setRootComponentRef(ROOT_REF)
       .setAnalysisDate(ANALYSIS_DATE)
       .setBranch(branch)
@@ -575,6 +576,10 @@ public class BuildComponentTreeStepTest {
   }
 
   private static class PrBranch extends DefaultBranchImpl {
+    public PrBranch(String branch) {
+      super(branch);
+    }
+
     @Override
     public BranchType getType() {
       return BranchType.PULL_REQUEST;
index 0ae78766c0750f1fa86fd627403cc8df6db266c5..8b7bee5e2251f72160c822623317c9b1eb7e50be 100644 (file)
@@ -59,6 +59,7 @@ import static org.mockito.Mockito.when;
 import static org.sonar.api.measures.CoreMetrics.ALERT_STATUS_KEY;
 import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.ERROR;
 import static org.sonar.ce.task.projectanalysis.measure.Measure.Level.OK;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 
 public class QualityGateEventsStepTest {
   private static final String PROJECT_VERSION = randomAlphabetic(19);
@@ -250,7 +251,7 @@ public class QualityGateEventsStepTest {
 
   @Test
   public void verify_branch_name_is_not_set_in_notification_when_main() {
-    analysisMetadataHolder.setBranch(new DefaultBranchImpl());
+    analysisMetadataHolder.setBranch(new DefaultBranchImpl(DEFAULT_PROJECT_MAIN_BRANCH_NAME));
 
     when(measureRepository.getRawMeasure(PROJECT_COMPONENT, alertStatusMetric))
       .thenReturn(of(Measure.newMeasureBuilder().setQualityGateStatus(OK_QUALITY_GATE_STATUS).createNoValue()));
index ec94c78144125706b4c56f7f77e0d51b79e1a61e..f725c5437b227b204c5c2a852256d2887d566e26 100644 (file)
@@ -43,10 +43,8 @@ import org.sonar.ce.task.step.ComputationStep;
 import org.sonar.ce.task.step.TestComputationStepContext;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbTester;
-import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
-import org.sonar.db.project.ProjectDto;
 import org.sonar.server.project.Project;
 
 import static org.assertj.core.api.Assertions.assertThat;
@@ -57,6 +55,7 @@ import static org.sonar.ce.task.projectanalysis.component.Component.Type.DIRECTO
 import static org.sonar.ce.task.projectanalysis.component.Component.Type.FILE;
 import static org.sonar.ce.task.projectanalysis.component.Component.Type.PROJECT;
 import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
 import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
@@ -623,7 +622,7 @@ public class ReportPersistComponentsStepTest extends BaseStepTest {
   private ComponentDto prepareProject(Consumer<ComponentDto> populators) {
     ComponentDto dto = db.components().insertPrivateProject(populators);
     analysisMetadataHolder.setProject(Project.from(dto));
-    analysisMetadataHolder.setBranch(new DefaultBranchImpl());
+    analysisMetadataHolder.setBranch(new DefaultBranchImpl(DEFAULT_PROJECT_MAIN_BRANCH_NAME));
     return dto;
   }
 
index a0b7c98b26b86c43eb5e10e7ec22e9ecae58b096..d3e154885581c0e0219e959f33bff769a8aed335 100644 (file)
@@ -98,6 +98,7 @@ import static org.sonar.api.rules.RuleType.SECURITY_HOTSPOT;
 import static org.sonar.ce.task.projectanalysis.component.Component.Type;
 import static org.sonar.ce.task.projectanalysis.component.ReportComponent.builder;
 import static org.sonar.ce.task.projectanalysis.step.SendIssueNotificationsStep.NOTIF_TYPES;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.BranchType.BRANCH;
 import static org.sonar.db.component.BranchType.PULL_REQUEST;
 import static org.sonar.db.component.ComponentTesting.newBranchComponent;
@@ -127,7 +128,7 @@ public class SendIssueNotificationsStepTest extends BaseStepTest {
     .setRoot(PROJECT);
   @Rule
   public AnalysisMetadataHolderRule analysisMetadataHolder = new AnalysisMetadataHolderRule()
-    .setBranch(new DefaultBranchImpl())
+    .setBranch(new DefaultBranchImpl(DEFAULT_PROJECT_MAIN_BRANCH_NAME))
     .setAnalysisDate(new Date(ANALYSE_DATE));
   @Rule
   public TemporaryFolder temp = new TemporaryFolder();
index fdc355dfe2ac90eef8cb795ecdf42fe069b2eab7..a1eaf07b4c2bdc027d11f7b0c90aad3299b76328 100644 (file)
@@ -43,13 +43,14 @@ import org.sonar.db.component.SnapshotTesting;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 
 public class ValidateProjectStepTest {
   static long PAST_ANALYSIS_TIME = 1_420_088_400_000L; // 2015-01-01
   static long DEFAULT_ANALYSIS_TIME = 1_433_131_200_000L; // 2015-06-01
 
   static final String PROJECT_KEY = "PROJECT_KEY";
-  static final Branch DEFAULT_BRANCH = new DefaultBranchImpl();
+  static final Branch DEFAULT_BRANCH = new DefaultBranchImpl(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
 
   @Rule
   public DbTester db = DbTester.create(System2.INSTANCE);
index 52e02ab9b0aac776d0c1433fc637f4183c42a0b0..9690ef6f783272d2803a83c7ebfcb07e62ef47ec 100644 (file)
@@ -56,6 +56,7 @@ import static org.mockito.Mockito.when;
 import static org.sonar.ce.task.projectanalysis.component.ViewAttributes.Type.APPLICATION;
 import static org.sonar.ce.task.projectanalysis.component.ViewAttributes.Type.PORTFOLIO;
 import static org.sonar.ce.task.projectanalysis.component.ViewsComponent.builder;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.component.ComponentTesting.newProjectCopy;
 import static org.sonar.db.component.ComponentTesting.newSubPortfolio;
@@ -96,7 +97,7 @@ public class ViewsPersistComponentsStepTest extends BaseStepTest {
     now = DATE_FORMAT.parse("2015-06-02");
     when(system2.now()).thenReturn(now.getTime());
 
-    analysisMetadataHolder.setBranch(new DefaultBranchImpl());
+    analysisMetadataHolder.setBranch(new DefaultBranchImpl(DEFAULT_PROJECT_MAIN_BRANCH_NAME));
     BranchPersister branchPersister = mock(BranchPersister.class);
     ProjectPersister projectPersister = mock(ProjectPersister.class);
     underTest = new PersistComponentsStep(dbClient, treeRootHolder, system2, disabledComponentsHolder, analysisMetadataHolder, branchPersister, projectPersister);
index ace1622934d3d05c7df159d74ecb73ba298beb50..7e6226006045b92dcc1e9a5c90df3200cb475c59 100644 (file)
@@ -125,12 +125,12 @@ public class ExportBranchesStepTest {
       .stream()
       .collect(toMap(ProjectDump.Branch::getUuid, Function.identity()));
     assertThat(branches).hasSize(3);
-    ProjectDump.Branch masterBranch = branches.get(PROJECT_UUID);
-    assertThat(masterBranch).isNotNull();
-    assertThat(masterBranch.getKee()).isEqualTo("master");
-    assertThat(masterBranch.getProjectUuid()).isEqualTo(PROJECT_UUID);
-    assertThat(masterBranch.getMergeBranchUuid()).isEmpty();
-    assertThat(masterBranch.getBranchType()).isEqualTo("BRANCH");
+    ProjectDump.Branch mainBranch = branches.get(PROJECT_UUID);
+    assertThat(mainBranch).isNotNull();
+    assertThat(mainBranch.getKee()).isEqualTo(BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME);
+    assertThat(mainBranch.getProjectUuid()).isEqualTo(PROJECT_UUID);
+    assertThat(mainBranch.getMergeBranchUuid()).isEmpty();
+    assertThat(mainBranch.getBranchType()).isEqualTo("BRANCH");
     ProjectDump.Branch branch1 = branches.get("branch-1-uuid");
     assertThat(branch1.getKee()).isEqualTo("branch-1");
     assertThat(branch1.getProjectUuid()).isEqualTo(PROJECT_UUID);
index 8e5708e2589fafcd4845bfbd627ba968e9d4723f..c6e84e7209c697c31926eb4d2fe51bca0afdfe6f 100644 (file)
@@ -130,6 +130,7 @@ import org.sonar.server.platform.serverid.JdbcUrlSanitizer;
 import org.sonar.server.platform.serverid.ServerIdChecksum;
 import org.sonar.server.plugins.InstalledPluginReferentialFactory;
 import org.sonar.server.plugins.ServerExtensionInstaller;
+import org.sonar.server.project.DefaultBranchNameResolver;
 import org.sonar.server.property.InternalPropertiesImpl;
 import org.sonar.server.qualitygate.QualityGateEvaluatorImpl;
 import org.sonar.server.qualitygate.QualityGateFinder;
@@ -443,6 +444,7 @@ public class ComputeEngineContainerImpl implements ComputeEngineContainer {
       InternalPropertiesImpl.class,
       ProjectConfigurationFactory.class,
 
+      DefaultBranchNameResolver.class,
       // webhooks
       new WebhookModule(),
 
index 35d5e85fef7fd5566c25f331f4f4f88734087583..e0eb96b5ba945392912b1dd859639368b45a4b8a 100644 (file)
@@ -30,7 +30,8 @@ import org.sonar.db.protobuf.DbProjectBranches;
 import static com.google.common.base.Preconditions.checkArgument;
 
 public class BranchDto {
-  public static final String DEFAULT_MAIN_BRANCH_NAME = "master";
+  public static final String DEFAULT_PROJECT_MAIN_BRANCH_NAME = "main";
+  public static final String DEFAULT_APPLICATION_MAIN_BRANCH_NAME = "master";
 
   /**
    * Maximum length of column "kee"
index 80904430f7c3bdcfc034b36ca8fc6fd6dc127522..f9b8a6e69777b06adbc57ae761e69479b48b8bb9 100644 (file)
@@ -82,6 +82,7 @@ import static org.sonar.api.resources.Qualifiers.PROJECT;
 import static org.sonar.api.resources.Qualifiers.SUBVIEW;
 import static org.sonar.api.resources.Qualifiers.VIEW;
 import static org.sonar.api.utils.DateUtils.parseDate;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.BranchType.BRANCH;
 import static org.sonar.db.component.BranchType.PULL_REQUEST;
 import static org.sonar.db.component.ComponentTesting.newApplication;
@@ -234,7 +235,7 @@ public class ComponentDaoTest {
     ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("my_branch").setBranchType(BRANCH));
     ComponentDto file = db.components().insertComponent(newFileDto(branch));
 
-    assertThat(underTest.selectByKeyAndBranch(dbSession, project.getKey(), "master").get().uuid()).isEqualTo(project.uuid());
+    assertThat(underTest.selectByKeyAndBranch(dbSession, project.getKey(), DEFAULT_PROJECT_MAIN_BRANCH_NAME).get().uuid()).isEqualTo(project.uuid());
     assertThat(underTest.selectByKeyAndBranch(dbSession, branch.getKey(), "my_branch").get().uuid()).isEqualTo(branch.uuid());
     assertThat(underTest.selectByKeyAndBranch(dbSession, file.getKey(), "my_branch").get().uuid()).isEqualTo(file.uuid());
     assertThat(underTest.selectByKeyAndBranch(dbSession, "unknown", "my_branch")).isNotPresent();
index ac04aa4b4ae43dd3def8a8868e0f0e8b953bed60..d080a7223ba2767bf59cdde5b4ef96cf213c8480 100644 (file)
@@ -44,6 +44,7 @@ import static java.util.Collections.singletonList;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.groups.Tuple.tuple;
 import static org.sonar.api.measures.Metric.ValueType.INT;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newPrivateProjectDto;
 import static org.sonar.db.measure.MeasureTesting.newLiveMeasure;
@@ -332,11 +333,11 @@ public class LiveMeasureDaoTest {
     List<LargestBranchNclocDto> results = underTest.getLargestBranchNclocPerProject(db.getSession());
 
     assertThat(results).hasSize(5);
-    assertLocForProject(results.get(0), "projectWithTieOnBranchSize", "master", 250);
+    assertLocForProject(results.get(0), "projectWithTieOnBranchSize", DEFAULT_PROJECT_MAIN_BRANCH_NAME, 250);
     assertLocForProject(results.get(1), "projectWithTieOnOtherBranches", "tieBranch1", 230);
     assertLocForProject(results.get(2), "projectWithBranchBiggerThanMaster", "notMasterBranch", 200);
-    assertLocForProject(results.get(3), "simpleProject", "master", 10);
-    assertLocForProject(results.get(4), "projectWithLinesButNoLoc", "master", 0);
+    assertLocForProject(results.get(3), "simpleProject", DEFAULT_PROJECT_MAIN_BRANCH_NAME, 10);
+    assertLocForProject(results.get(4), "projectWithLinesButNoLoc", DEFAULT_PROJECT_MAIN_BRANCH_NAME, 0);
   }
 
   @Test
index b9d6e5c8b82dfd898f71a6acb23f746c4d611514..251bd2a73632f1d79c4c6bb79e4bcc570c9c77ef 100644 (file)
@@ -28,7 +28,8 @@ import org.sonar.db.project.ProjectDto;
 
 import static com.google.common.base.Preconditions.checkArgument;
 import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
-import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME;
+import static org.sonar.db.component.BranchDto.DEFAULT_APPLICATION_MAIN_BRANCH_NAME;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.ComponentDto.UUID_PATH_OF_ROOT;
 import static org.sonar.db.component.ComponentDto.UUID_PATH_SEPARATOR;
 import static org.sonar.db.component.ComponentDto.formatUuidPathFromParent;
@@ -218,7 +219,9 @@ public class ComponentTesting {
   public static BranchDto newBranchDto(ComponentDto branchComponent, BranchType branchType) {
     boolean isMain = branchComponent.getMainBranchProjectUuid() == null;
     String projectUuid = isMain ? branchComponent.uuid() : branchComponent.getMainBranchProjectUuid();
-    String key = isMain ? DEFAULT_MAIN_BRANCH_NAME : "branch_" + randomAlphanumeric(248);
+    String defaultBranchName = branchComponent.qualifier() != null && branchComponent.qualifier().equals("APP") ?
+      DEFAULT_APPLICATION_MAIN_BRANCH_NAME : DEFAULT_PROJECT_MAIN_BRANCH_NAME;
+    String key = isMain ? defaultBranchName : "branch_" + randomAlphanumeric(248);
 
     return new BranchDto()
       .setKey(key)
diff --git a/server/sonar-server-common/src/main/java/org/sonar/server/project/DefaultBranchNameResolver.java b/server/sonar-server-common/src/main/java/org/sonar/server/project/DefaultBranchNameResolver.java
new file mode 100644 (file)
index 0000000..bd93736
--- /dev/null
@@ -0,0 +1,38 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2022 SonarSource SA
+ * mailto:info AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
+ */
+package org.sonar.server.project;
+
+import org.sonar.api.config.Configuration;
+
+import static org.sonar.core.config.CorePropertyDefinitions.SONAR_PROJECTCREATION_MAINBRANCHNAME;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
+
+public class DefaultBranchNameResolver {
+
+  Configuration configuration;
+
+  public DefaultBranchNameResolver(Configuration configuration) {
+    this.configuration = configuration;
+  }
+
+  public String getEffectiveMainBranchName() {
+    return configuration.get(SONAR_PROJECTCREATION_MAINBRANCHNAME).orElse(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
+  }
+}
index adc23e044acc51a273526e4613b1bc625ca40c07..e77377b038fd2e4a8afd53944c8e2a4c21ab0781 100644 (file)
@@ -55,6 +55,7 @@ import static org.sonar.api.resources.Qualifiers.APP;
 import static org.sonar.api.utils.DateUtils.addDays;
 import static org.sonar.api.utils.DateUtils.parseDateTime;
 import static org.sonar.api.web.UserRole.USER;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newModuleDto;
@@ -608,12 +609,12 @@ public class IssueQueryFactoryTest {
 
     assertThat(underTest.create(new SearchRequest()
       .setProjects(singletonList(project.getKey()))
-      .setBranch("master")))
+      .setBranch(DEFAULT_PROJECT_MAIN_BRANCH_NAME)))
       .extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch)
       .containsOnly(project.uuid(), singletonList(project.uuid()), true);
     assertThat(underTest.create(new SearchRequest()
       .setComponents(singletonList(project.getKey()))
-      .setBranch("master")))
+      .setBranch(DEFAULT_PROJECT_MAIN_BRANCH_NAME)))
       .extracting(IssueQuery::branchUuid, query -> new ArrayList<>(query.projectUuids()), IssueQuery::isMainBranch)
       .containsOnly(project.uuid(), singletonList(project.uuid()), true);
   }
index 45da74e4fe3c366a1d978cfbb39fc3444af503cd..8aeea98aa5ad960ac8ca984b384725c3cae4777a 100644 (file)
@@ -98,6 +98,20 @@ public class ComponentUpdater {
     return componentDto;
   }
 
+  /**
+   * - Create component
+   * - Apply default permission template
+   * - Add component to favorite if the component has the 'Project Creators' permission
+   * - Index component in es indexes
+   */
+  public ComponentDto createApplicationOrPortfolio(DbSession dbSession, NewComponent newComponent, @Nullable String userUuid,
+    @Nullable String userLogin) {
+    ComponentDto componentDto = createWithoutCommit(dbSession, newComponent, userUuid, userLogin,
+      BranchDto.DEFAULT_APPLICATION_MAIN_BRANCH_NAME, c -> {});
+    commitAndIndex(dbSession, componentDto);
+    return componentDto;
+  }
+
   public void commitAndIndex(DbSession dbSession, ComponentDto componentDto) {
     projectIndexers.commitAndIndexComponents(dbSession, singletonList(componentDto), Cause.PROJECT_CREATION);
   }
@@ -218,7 +232,7 @@ public class ComponentUpdater {
     String branchKey = Optional.ofNullable(mainBranch)
       .or(() -> Optional.ofNullable(propertiesDao.selectGlobalProperty(session, CorePropertyDefinitions.SONAR_PROJECTCREATION_MAINBRANCHNAME))
         .map(PropertyDto::getValue))
-      .orElse(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
+      .orElse(BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME);
 
     BranchDto branch = new BranchDto()
       .setBranchType(BranchType.BRANCH)
index e37bdebc9f16a0e8805e62ca64ce7ed147ff38b4..a035d0569251d8e0d6d8499bf46c9b8aa0c1c5e2 100644 (file)
@@ -11,7 +11,7 @@
       "excludedFromPurge": false
     },
     {
-      "name": "master",
+      "name": "main",
       "isMain": true,
       "type": "BRANCH",
       "status": {
index 99671c08985caa73f4d6a51161b85bb0082c1642..3b020a99fb344bf814aac43e31128a1a43e67f08 100644 (file)
@@ -63,6 +63,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
 import static org.sonar.db.permission.GlobalPermission.SCAN;
 
@@ -173,7 +174,7 @@ public class ImportAzureProjectActionTest {
       .findFirst();
 
     assertThat(mainBranch).isPresent();
-    assertThat(mainBranch.get().getKey()).hasToString("master");
+    assertThat(mainBranch.get().getKey()).hasToString(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
   }
 
   @Test
@@ -183,7 +184,7 @@ public class ImportAzureProjectActionTest {
       .setParam("projectName", "project-name")
       .setParam("repositoryName", "repo-name");
 
-    assertThatThrownBy(() -> request.execute())
+    assertThatThrownBy(request::execute)
       .isInstanceOf(UnauthorizedException.class);
   }
 
index eb0e1a08fcf32059e86539a108db735db8c8591b..a1c5c348ecc70c50c432c4a274cf3b5c24486e49 100644 (file)
@@ -70,6 +70,7 @@ import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
 import static org.sonar.db.alm.integration.pat.AlmPatsTesting.newAlmPatDto;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
 import static org.sonar.db.permission.GlobalPermission.SCAN;
 
@@ -270,7 +271,7 @@ public class ImportBitbucketServerProjectActionTest {
     Collection<BranchDto> branchDtos = db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get());
     List<BranchDto> collect = branchDtos.stream().filter(BranchDto::isMain).collect(Collectors.toList());
     String mainBranchName = collect.iterator().next().getKey();
-    assertThat(mainBranchName).isEqualTo("master");
+    assertThat(mainBranchName).isEqualTo(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
   }
 
   @Test
index aa4820ecc316dfa96302b0a32290649ea0cc2b32..4f4204eb81c0d542e78b936c0301d55923dc3c11 100644 (file)
@@ -56,6 +56,7 @@ import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.verify;
 import static org.mockito.Mockito.when;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.permission.GlobalPermission.PROVISION_PROJECTS;
 import static org.sonar.server.tester.UserSessionRule.standalone;
 
@@ -188,7 +189,7 @@ public class ImportGitLabProjectActionTest {
 
     Assertions.assertThat(db.getDbClient().branchDao().selectByProject(db.getSession(), projectDto.get()))
       .extracting(BranchDto::getKey, BranchDto::isMain)
-      .containsExactlyInAnyOrder(tuple("master", true));
+      .containsExactlyInAnyOrder(tuple(DEFAULT_PROJECT_MAIN_BRANCH_NAME, true));
   }
 
 
index 1ef0af77e4d7c3868433cfbac842ae4a1f74b335..80ac0430697f4ffbb059b30d6ba3a9fe264260e3 100644 (file)
@@ -57,6 +57,7 @@ import static org.sonar.api.utils.DateUtils.dateToLong;
 import static org.sonar.api.utils.DateUtils.parseDateTime;
 import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.core.permission.GlobalPermissions.SCAN_EXECUTION;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.BranchType.BRANCH;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
 import static org.sonar.test.JsonAssert.assertJson;
@@ -161,7 +162,7 @@ public class ListActionTest {
 
     assertThat(response.getBranchesList())
       .extracting(Branch::getName, Branch::getIsMain, Branch::getType)
-      .containsExactlyInAnyOrder(tuple("master", true, BranchType.BRANCH));
+      .containsExactlyInAnyOrder(tuple(DEFAULT_PROJECT_MAIN_BRANCH_NAME, true, BranchType.BRANCH));
   }
 
   @Test
@@ -194,7 +195,7 @@ public class ListActionTest {
     assertThat(response.getBranchesList())
       .extracting(Branch::getName, Branch::getType)
       .containsExactlyInAnyOrder(
-        tuple("master", BranchType.BRANCH),
+        tuple(DEFAULT_PROJECT_MAIN_BRANCH_NAME, BranchType.BRANCH),
         tuple("feature/foo", BranchType.BRANCH),
         tuple("feature/bar", BranchType.BRANCH));
   }
index 626d75bda8b3d88b6efd36a781cf598c94ee0017..16174e399340d681c99398c1753b108af572b507 100644 (file)
@@ -40,6 +40,7 @@ import org.sonar.server.ws.WsActionTester;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.sonar.api.resources.Qualifiers.PROJECT;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 
 public class SetAutomaticDeletionProtectionActionTest {
 
@@ -124,7 +125,7 @@ public class SetAutomaticDeletionProtectionActionTest {
 
     assertThatThrownBy(() -> tester.newRequest()
       .setParam("project", project.getKey())
-      .setParam("branch", "master")
+      .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
       .setParam("value", "false")
       .execute())
       .isInstanceOf(IllegalArgumentException.class)
@@ -146,7 +147,7 @@ public class SetAutomaticDeletionProtectionActionTest {
 
     assertThat(db.countRowsOfTable("project_branches")).isEqualTo(2);
     Optional<BranchDto> mainBranch = db.getDbClient().branchDao().selectByUuid(db.getSession(), project.uuid());
-    assertThat(mainBranch.get().getKey()).isEqualTo("master");
+    assertThat(mainBranch.get().getKey()).isEqualTo(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
     assertThat(mainBranch.get().isExcludeFromPurge()).isTrue();
 
     Optional<BranchDto> branchDto = db.getDbClient().branchDao().selectByUuid(db.getSession(), branch.uuid());
index 0a5376d0d4a049cea6bfb9ac7a64649e49a66760..551f413890a3210ab19a13bb9aabc1d336765811 100644 (file)
@@ -30,6 +30,7 @@ import org.sonar.server.exceptions.NotFoundException;
 import static java.lang.String.format;
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.BranchType.PULL_REQUEST;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
@@ -217,7 +218,7 @@ public class ComponentFinderTest {
   public void get_by_key_and_branch_accept_main_branch() {
     ComponentDto project = db.components().insertPublicProject();
 
-    assertThat(underTest.getByKeyAndBranch(dbSession, project.getKey(), "master").uuid()).isEqualTo(project.uuid());
+    assertThat(underTest.getByKeyAndBranch(dbSession, project.getKey(), DEFAULT_PROJECT_MAIN_BRANCH_NAME).uuid()).isEqualTo(project.uuid());
   }
 
   @Test
index c958148c03fdef5a2631798d769fbcd5bd50b915..09263f5340a42fd794c4d6b2fa7adb3a6ed43d85 100644 (file)
@@ -99,7 +99,7 @@ public class ComponentUpdaterTest {
 
     Optional<BranchDto> branch = db.getDbClient().branchDao().selectByUuid(db.getSession(), returned.uuid());
     assertThat(branch).isPresent();
-    assertThat(branch.get().getKey()).isEqualTo(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
+    assertThat(branch.get().getKey()).isEqualTo(BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME);
     assertThat(branch.get().getMergeBranchUuid()).isNull();
     assertThat(branch.get().getBranchType()).isEqualTo(BranchType.BRANCH);
     assertThat(branch.get().getUuid()).isEqualTo(returned.uuid());
@@ -200,7 +200,7 @@ public class ComponentUpdaterTest {
     assertThat(projectIndexers.hasBeenCalled(loaded.uuid(), ProjectIndexer.Cause.PROJECT_CREATION)).isTrue();
     Optional<BranchDto> branch = db.getDbClient().branchDao().selectByUuid(db.getSession(), returned.uuid());
     assertThat(branch).isPresent();
-    assertThat(branch.get().getKey()).isEqualTo(BranchDto.DEFAULT_MAIN_BRANCH_NAME);
+    assertThat(branch.get().getKey()).isEqualTo(BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME);
     assertThat(branch.get().getMergeBranchUuid()).isNull();
     assertThat(branch.get().getBranchType()).isEqualTo(BranchType.BRANCH);
     assertThat(branch.get().getUuid()).isEqualTo(returned.uuid());
index 1793a77a430519aebcb4376c91ce2c881a890031..edea80d3e3dd6b46f6888b34f206ef1bd1320be0 100644 (file)
@@ -48,6 +48,7 @@ import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.utils.DateUtils.formatDateTime;
 import static org.sonar.api.utils.DateUtils.parseDateTime;
 import static org.sonar.api.web.UserRole.USER;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.BranchType.BRANCH;
 import static org.sonar.db.component.BranchType.PULL_REQUEST;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
@@ -288,11 +289,10 @@ public class ShowActionTest {
   public void dont_show_branch_if_main_branch() {
     ComponentDto project = db.components().insertPrivateProject();
     userSession.addProjectPermission(UserRole.USER, project);
-    String branchKey = "master";
 
     ShowWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, project.getKey())
-      .setParam(PARAM_BRANCH, branchKey)
+      .setParam(PARAM_BRANCH, DEFAULT_PROJECT_MAIN_BRANCH_NAME)
       .executeProtobuf(ShowWsResponse.class);
 
     assertThat(response.getComponent())
index c0564c6ed34237ddea94dc6603ae647638a547fe..6152d29a743ff0e33da5c023891d1441f62fa27f 100644 (file)
@@ -61,6 +61,7 @@ import static org.sonar.api.resources.Qualifiers.APP;
 import static org.sonar.api.resources.Qualifiers.FILE;
 import static org.sonar.api.resources.Qualifiers.PROJECT;
 import static org.sonar.api.resources.Qualifiers.UNIT_TEST_FILE;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.BranchType.PULL_REQUEST;
 import static org.sonar.db.component.ComponentTesting.newChildComponent;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
@@ -384,7 +385,7 @@ public class TreeActionTest {
 
     TreeWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, file.getKey())
-      .setParam(PARAM_BRANCH, "master")
+      .setParam(PARAM_BRANCH, DEFAULT_PROJECT_MAIN_BRANCH_NAME)
       .executeProtobuf(TreeWsResponse.class);
 
     assertThat(response.getBaseComponent()).extracting(Component::getKey, Component::getBranch)
index 2c2769ae308926c6c4ec7006d0dafa469b0f2905..b735139beb4ba6b95355c4ebb5d9ccaf6dd0b665 100644 (file)
@@ -57,6 +57,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.api.web.UserRole.USER;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 
 public class PullActionTest {
@@ -64,7 +65,7 @@ public class PullActionTest {
   private static final long NOW = 10_000_000_000L;
   private static final long PAST = 1_000_000_000L;
 
-  private static final String DEFAULT_BRANCH = "master";
+  private static final String DEFAULT_BRANCH = DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 
   @Rule
   public DbTester dbTester = DbTester.create();
index 29b0d0f7a2be0575fefba5d953a851a8243b8c8c..637b5c409105d4f7567930c3e5c2b16886dc1e4f 100644 (file)
@@ -58,13 +58,14 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
 import static org.sonar.api.web.UserRole.USER;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 
 public class PullTaintActionTest {
   private static final long NOW = 10_000_000_000L;
   private static final long PAST = 1_000_000_000L;
 
-  private static final String DEFAULT_BRANCH = "master";
+  private static final String DEFAULT_BRANCH = DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 
   @Rule
   public DbTester dbTester = DbTester.create();
index b77b308559e69090a6e8f35efea7bd82bd865960..f22493335fd2320d64cb3498bf36136a6220dfc2 100644 (file)
@@ -66,6 +66,7 @@ import static org.sonar.api.utils.DateUtils.parseDateTime;
 import static org.sonar.api.web.UserRole.USER;
 import static org.sonar.core.util.Uuids.UUID_EXAMPLE_01;
 import static org.sonar.core.util.Uuids.UUID_EXAMPLE_02;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.BranchType.BRANCH;
 import static org.sonar.db.component.BranchType.PULL_REQUEST;
 import static org.sonar.db.component.ComponentTesting.newDirectory;
@@ -668,7 +669,7 @@ public class SearchActionComponentsTest {
 
     SearchWsResponse result = ws.newRequest()
       .setParam(PARAM_COMPONENT_KEYS, project.getKey())
-      .setParam(PARAM_BRANCH, "master")
+      .setParam(PARAM_BRANCH, DEFAULT_PROJECT_MAIN_BRANCH_NAME)
       .executeProtobuf(SearchWsResponse.class);
 
     assertThat(result.getIssuesList())
index e3e8ecba3e7925622d92e26d639589d1da83ef38..08cae5ea7ea63d0d6055561505352b360a30afbb 100644 (file)
@@ -47,6 +47,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.Assertions.tuple;
 import static org.sonar.api.utils.DateUtils.parseDateTime;
 import static org.sonar.api.web.UserRole.USER;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.BranchType.PULL_REQUEST;
 import static org.sonar.db.component.ComponentTesting.newFileDto;
 import static org.sonar.db.component.ComponentTesting.newProjectCopy;
@@ -147,7 +148,7 @@ public class ComponentActionTest {
 
     ComponentWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, file.getKey())
-      .setParam(PARAM_BRANCH, "master")
+      .setParam(PARAM_BRANCH, DEFAULT_PROJECT_MAIN_BRANCH_NAME)
       .setParam(PARAM_METRIC_KEYS, "complexity")
       .executeProtobuf(ComponentWsResponse.class);
 
index 2de3079465f88351f872a2ff659203fd22de317e..241edc67f81a279319417d804819bf898ac0b1f9 100644 (file)
@@ -32,6 +32,7 @@ import org.sonar.core.util.stream.MoreCollectors;
 import org.sonar.db.DbClient;
 import org.sonar.db.DbSession;
 import org.sonar.db.DbTester;
+import org.sonar.db.component.BranchDto;
 import org.sonar.db.component.ComponentDto;
 import org.sonar.db.component.ComponentTesting;
 import org.sonar.db.component.ResourceTypesRule;
@@ -564,7 +565,7 @@ public class ComponentTreeActionTest {
 
     ComponentTreeWsResponse response = ws.newRequest()
       .setParam(PARAM_COMPONENT, file.getKey())
-      .setParam(PARAM_BRANCH, "master")
+      .setParam(PARAM_BRANCH, BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME)
       .setParam(PARAM_METRIC_KEYS, complexity.getKey())
       .executeProtobuf(ComponentTreeWsResponse.class);
 
index 8cee6bd9bdee530d1cb73268964d0b647627efcf..fab0c1bd5a69302eede62b51add45792fe1df2ba 100644 (file)
@@ -50,6 +50,7 @@ import org.sonarqube.ws.NewCodePeriods.ShowWSResponse;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.component.SnapshotTesting.newAnalysis;
 
 public class ListActionTest {
@@ -115,7 +116,7 @@ public class ListActionTest {
     assertThat(response).isNotNull();
     assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
     assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
-      .contains("master", "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
+      .contains(DEFAULT_PROJECT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
 
     //check if global default is set
     assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
@@ -138,7 +139,7 @@ public class ListActionTest {
     assertThat(response).isNotNull();
     assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
     assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
-      .contains("master", "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
+      .contains(DEFAULT_PROJECT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
 
     //check if global default is set
     assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
@@ -173,7 +174,7 @@ public class ListActionTest {
     assertThat(response).isNotNull();
     assertThat(response.getNewCodePeriodsCount()).isEqualTo(6);
     assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
-      .contains("master", "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
+      .contains(DEFAULT_PROJECT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4");
 
     //check if project setting is set
     assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
@@ -191,7 +192,7 @@ public class ListActionTest {
     assertThat(response).isNotNull();
     assertThat(response.getNewCodePeriodsCount()).isOne();
     assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
-      .containsOnly("master");
+      .containsOnly(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
 
     //check if global setting is set
     assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType)
@@ -227,7 +228,7 @@ public class ListActionTest {
     assertThat(response).isNotNull();
     assertThat(response.getNewCodePeriodsCount()).isEqualTo(3);
     assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
-      .contains("master", "OWN_SETTINGS", "GLOBAL_SETTINGS");
+      .contains(DEFAULT_PROJECT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "GLOBAL_SETTINGS");
 
     Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream()
       .filter(s -> !s.getInherited())
@@ -282,7 +283,7 @@ public class ListActionTest {
     assertThat(response).isNotNull();
     assertThat(response.getNewCodePeriodsCount()).isEqualTo(3);
     assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
-      .contains("master", "OWN_SETTINGS", "PROJECT_SETTINGS");
+      .contains(DEFAULT_PROJECT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "PROJECT_SETTINGS");
 
     Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream()
       .filter(s -> !s.getInherited())
@@ -343,7 +344,7 @@ public class ListActionTest {
     assertThat(response).isNotNull();
     assertThat(response.getNewCodePeriodsCount()).isEqualTo(2);
     assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey)
-      .containsOnly("master", "PROJECT_BRANCH");
+      .containsOnly(DEFAULT_PROJECT_MAIN_BRANCH_NAME, "PROJECT_BRANCH");
 
     ShowWSResponse result = response.getNewCodePeriodsList().get(0);
     assertThat(result.getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS);
index 8e1019fc690808caee2c2ce332980e551debe2ee..e0335b2a030472ece1de9c97a5167800318380f6 100644 (file)
@@ -54,6 +54,7 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy;
 import static org.assertj.core.api.Assertions.entry;
 import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.when;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 
 @RunWith(DataProviderRunner.class)
 public class SetActionTest {
@@ -130,7 +131,7 @@ public class SetActionTest {
 
     assertThatThrownBy(() -> ws.newRequest()
       .setParam("project", project.getKey())
-      .setParam("branch", "master")
+      .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
       .setParam("type", "number_of_days")
       .execute())
       .isInstanceOf(IllegalArgumentException.class)
@@ -145,7 +146,7 @@ public class SetActionTest {
     assertThatThrownBy(() -> ws.newRequest()
       .setParam("project", project.getKey())
       .setParam("type", "specific_analysis")
-      .setParam("branch", "master")
+      .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
       .execute())
       .isInstanceOf(IllegalArgumentException.class)
       .hasMessageContaining("New Code Period type 'SPECIFIC_ANALYSIS' requires a value");
@@ -159,7 +160,7 @@ public class SetActionTest {
     assertThatThrownBy(() -> ws.newRequest()
       .setParam("project", project.getKey())
       .setParam("type", "number_of_days")
-      .setParam("branch", "master")
+      .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
       .setParam("value", "unknown")
       .execute())
       .isInstanceOf(IllegalArgumentException.class)
@@ -174,7 +175,7 @@ public class SetActionTest {
     assertThatThrownBy(() -> ws.newRequest()
       .setParam("project", project.getKey())
       .setParam("type", "specific_analysis")
-      .setParam("branch", "master")
+      .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
       .setParam("value", "unknown")
       .execute())
       .isInstanceOf(NotFoundException.class)
@@ -194,11 +195,12 @@ public class SetActionTest {
     assertThatThrownBy(() -> ws.newRequest()
       .setParam("project", project.getKey())
       .setParam("type", "specific_analysis")
-      .setParam("branch", "master")
+      .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
       .setParam("value", analysisBranch.getUuid())
       .execute())
       .isInstanceOf(IllegalArgumentException.class)
-      .hasMessageContaining("Analysis '" + analysisBranch.getUuid() + "' does not belong to branch 'master' of project '" + project.getKey() + "'");
+      .hasMessageContaining("Analysis '" + analysisBranch.getUuid() + "' does not belong to branch '" + DEFAULT_PROJECT_MAIN_BRANCH_NAME +
+        "' of project '" + project.getKey() + "'");
   }
 
   // validation of project/branch
index 22629b3c0b93441b503777d5d62f3f6e56713ee3..664235f34e9274a18dfbb602b33755af77224887 100644 (file)
@@ -52,6 +52,7 @@ import org.sonar.server.ws.WsActionTester;
 
 import static org.assertj.core.api.Assertions.assertThat;
 import static org.assertj.core.api.Assertions.assertThatThrownBy;
+import static org.sonar.db.component.BranchDto.DEFAULT_PROJECT_MAIN_BRANCH_NAME;
 import static org.sonar.db.newcodeperiod.NewCodePeriodType.SPECIFIC_ANALYSIS;
 import static org.sonar.server.projectanalysis.ws.ProjectAnalysesWsParameters.PARAM_ANALYSIS;
 import static org.sonar.server.projectanalysis.ws.ProjectAnalysesWsParameters.PARAM_BRANCH;
@@ -116,7 +117,7 @@ public class SetBaselineActionTest {
     ComponentDto project = tester.insertPrivateProject();
     SnapshotDto analysis = db.components().insertSnapshot(project);
 
-    assertThatThrownBy(() -> call(project.getKey(), "master", analysis.getUuid()))
+    assertThatThrownBy(() -> call(project.getKey(), DEFAULT_PROJECT_MAIN_BRANCH_NAME, analysis.getUuid()))
       .isInstanceOf(ForbiddenException.class)
       .hasMessage("Insufficient privileges");
   }
@@ -178,7 +179,7 @@ public class SetBaselineActionTest {
     SnapshotDto analysis = db.components().insertSnapshot(project);
     logInAsProjectAdministrator(project);
 
-    ComponentDto otherProject = tester.insertPrivateProjectWithCustomBranch("main");
+    ComponentDto otherProject = tester.insertPrivateProjectWithCustomBranch("develop");
     BranchDto branchOfOtherProject = branchDao.selectByUuid(dbSession, otherProject.uuid()).get();
 
     assertThatThrownBy(() -> call(project.getKey(), branchOfOtherProject.getKey(), analysis.getUuid()))
index d30627adf7d237d7c01d6fc05a3bb162ff894f21..3f3c27434fe611afa2a64817b098899514e5e6a7 100644 (file)
@@ -178,6 +178,7 @@ import org.sonar.server.plugins.ws.PluginUpdateAggregator;
 import org.sonar.server.plugins.ws.PluginsWs;
 import org.sonar.server.plugins.ws.UninstallAction;
 import org.sonar.server.plugins.ws.UpdatesAction;
+import org.sonar.server.project.DefaultBranchNameResolver;
 import org.sonar.server.project.ProjectQGChangeEventListener;
 import org.sonar.server.project.ws.ProjectsWsModule;
 import org.sonar.server.projectanalysis.ws.ProjectAnalysisWsModule;
@@ -297,6 +298,7 @@ public class PlatformLevel4 extends PlatformLevel {
       IndexDefinitions.class,
       WebAnalyticsLoaderImpl.class,
       new MonitoringWsModule(),
+      DefaultBranchNameResolver.class,
 
       // batch
       new BatchWsModule(),
index d9ed8063cc8f9b0966f89149f36c6ae4c4ec2012..09236b076a44b7ed835edff6fe7c7740ced7c00b 100644 (file)
@@ -32,7 +32,7 @@ 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 static final String DEFAULT_MAIN_BRANCH_NAME = "main";
 
   private final Map<String, BranchInfo> branches;
   private final String defaultBranchName;
index 83a5bfb888fe87adf95526af17cde3cd05659a30..52f940f527a38ee369edb1d33e7df692c8f164aa 100644 (file)
@@ -111,7 +111,7 @@ public class BranchMediumTest {
   public void shouldSkipSensorForUnchangedFilesOnPr() throws Exception {
     AnalysisResult result = getResult(tester
             .setBranchName("myBranch")
-            .setBranchTarget("master")
+            .setBranchTarget("main")
             .setBranchType(BranchType.PULL_REQUEST));
     final DefaultInputFile file = (DefaultInputFile) result.inputFile(FILE_PATH);
 
@@ -125,7 +125,7 @@ public class BranchMediumTest {
   public void shouldNotSkipSensorForUnchangedFilesOnBranch() throws Exception {
     AnalysisResult result = getResult(tester
             .setBranchName("myBranch")
-            .setBranchTarget("master")
+            .setBranchTarget("main")
             .setBranchType(BranchType.BRANCH));
     final DefaultInputFile file = (DefaultInputFile) result.inputFile(FILE_PATH);
 
index 637669505635b20687634d3f307d05fb72f842d8..39d98c404e9d53f22950af98fc479d0b87dfe0bc 100644 (file)
@@ -47,7 +47,7 @@ public class DefaultNewCodePeriodLoaderTest {
   }
 
   private void prepareCallWithResults() throws IOException {
-    WsTestUtil.mockStream(wsClient, createResponse(NewCodePeriods.NewCodePeriodType.REFERENCE_BRANCH, "master"));
+    WsTestUtil.mockStream(wsClient, createResponse(NewCodePeriods.NewCodePeriodType.REFERENCE_BRANCH, "main"));
   }
 
   private InputStream createResponse(NewCodePeriods.NewCodePeriodType type, String value) throws IOException {
index 3b51bd63d6116dd9bb107670b424eb7966cf2cb0..1b270781d3d7b0d90b4e2274e715bdc40e60bdd3 100644 (file)
@@ -64,16 +64,16 @@ public class ReferenceBranchSupplierTest {
   public void get_returns_reference_branch_when_set() {
     when(branchConfiguration.branchType()).thenReturn(BranchType.BRANCH);
     when(branchConfiguration.branchName()).thenReturn(BRANCH_KEY);
-    when(newCodePeriodLoader.load(PROJECT_KEY, BRANCH_KEY)).thenReturn(createResponse(NewCodePeriods.NewCodePeriodType.REFERENCE_BRANCH, "master"));
+    when(newCodePeriodLoader.load(PROJECT_KEY, BRANCH_KEY)).thenReturn(createResponse(NewCodePeriods.NewCodePeriodType.REFERENCE_BRANCH, "main"));
 
-    assertThat(referenceBranchSupplier.get()).isEqualTo("master");
+    assertThat(referenceBranchSupplier.get()).isEqualTo("main");
   }
 
   @Test
   public void get_uses_scanner_property_with_higher_priority() {
     when(branchConfiguration.branchType()).thenReturn(BranchType.BRANCH);
     when(branchConfiguration.branchName()).thenReturn(BRANCH_KEY);
-    when(newCodePeriodLoader.load(PROJECT_KEY, BRANCH_KEY)).thenReturn(createResponse(NewCodePeriods.NewCodePeriodType.REFERENCE_BRANCH, "master"));
+    when(newCodePeriodLoader.load(PROJECT_KEY, BRANCH_KEY)).thenReturn(createResponse(NewCodePeriods.NewCodePeriodType.REFERENCE_BRANCH, "main"));
 
     when(configuration.get("sonar.newCode.referenceBranch")).thenReturn(Optional.of("master2"));
 
@@ -107,9 +107,9 @@ public class ReferenceBranchSupplierTest {
     when(branchConfiguration.branchType()).thenReturn(BranchType.BRANCH);
     when(branchConfiguration.branchName()).thenReturn(null);
     when(projectBranches.defaultBranchName()).thenReturn("default");
-    when(newCodePeriodLoader.load(PROJECT_KEY, "default")).thenReturn(createResponse(NewCodePeriods.NewCodePeriodType.REFERENCE_BRANCH, "master"));
+    when(newCodePeriodLoader.load(PROJECT_KEY, "default")).thenReturn(createResponse(NewCodePeriods.NewCodePeriodType.REFERENCE_BRANCH, "main"));
 
-    assertThat(referenceBranchSupplier.get()).isEqualTo("master");
+    assertThat(referenceBranchSupplier.get()).isEqualTo("main");
   }
 
   @Test
index 0c90cc469228ec9e175f8cc0bb2398bf7871409f..fcf85abca290dc6f44988e01415917cb9093c3a6 100644 (file)
@@ -70,6 +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");
+    assertThat(new ProjectBranches(Collections.emptyList()).defaultBranchName()).isEqualTo("main");
   }
 }
index e75152cdb74e6513dbcda28015b1b3006b4b7917..2a5252d760390f52724f69ba550d75bce5b866b5 100644 (file)
@@ -164,7 +164,7 @@ public class GitScmProviderTest {
     git.rm().addFilepattern(fileName).call();
     commit(renamedName);
 
-    Set<Path> files = newScmProvider().branchChangedFiles("master", worktree);
+    Set<Path> files = newScmProvider().branchChangedFiles("main", worktree);
 
     // no shared history, so no diff
     assertThat(files).isNull();
@@ -243,7 +243,7 @@ public class GitScmProviderTest {
     Repository repo = FileRepositoryBuilder.create(worktree.resolve(".git").toFile());
     git = new Git(repo);
 
-    assertThat(newScmProvider().branchChangedFiles("master", worktree)).isNull();
+    assertThat(newScmProvider().branchChangedFiles("main", worktree)).isNull();
   }
 
   @Test
@@ -375,7 +375,7 @@ public class GitScmProviderTest {
     git.checkout().setOrphan(true).setName("b1").call();
     createAndCommitFile("file-b1.xoo");
 
-    Map<Path, Set<Integer>> changedLines = newScmProvider().branchChangedLines("master", worktree, Collections.singleton(Paths.get("")));
+    Map<Path, Set<Integer>> changedLines = newScmProvider().branchChangedLines("main", worktree, Collections.singleton(Paths.get("")));
     assertThat(changedLines).isNull();
   }
 
@@ -476,7 +476,7 @@ public class GitScmProviderTest {
     Repository repo = FileRepositoryBuilder.create(worktree.resolve(".git").toFile());
     git = new Git(repo);
 
-    assertThat(newScmProvider().branchChangedLines("master", worktree, Collections.singleton(Paths.get("file")))).isNull();
+    assertThat(newScmProvider().branchChangedLines("main", worktree, Collections.singleton(Paths.get("file")))).isNull();
   }
 
   /**
@@ -602,14 +602,14 @@ public class GitScmProviderTest {
 
   @Test
   public void branchChangedFiles_should_throw_when_repo_nonexistent() {
-    assertThatThrownBy(() -> newScmProvider().branchChangedFiles("master", temp.newFolder().toPath()))
+    assertThatThrownBy(() -> newScmProvider().branchChangedFiles("main", temp.newFolder().toPath()))
       .isInstanceOf(MessageException.class)
       .hasMessageContaining("Not inside a Git work tree: ");
   }
 
   @Test
   public void branchChangedFiles_should_throw_when_dir_nonexistent() {
-    assertThatThrownBy(() -> newScmProvider().branchChangedFiles("master", temp.getRoot().toPath().resolve("nonexistent")))
+    assertThatThrownBy(() -> newScmProvider().branchChangedFiles("main", temp.getRoot().toPath().resolve("nonexistent")))
       .isInstanceOf(MessageException.class)
       .hasMessageContaining("Not inside a Git work tree: ");
   }