*/
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;
} 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));
}
}
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;
/**
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
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)
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
@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");
}
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
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";
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";
@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");
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;
}
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)
}
private static class PrBranch extends DefaultBranchImpl {
+ public PrBranch(String branch) {
+ super(branch);
+ }
+
@Override
public BranchType getType() {
return BranchType.PULL_REQUEST;
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);
@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()));
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;
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;
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;
}
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;
.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();
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);
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;
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);
.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);
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;
InternalPropertiesImpl.class,
ProjectConfigurationFactory.class,
+ DefaultBranchNameResolver.class,
// webhooks
new WebhookModule(),
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"
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;
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();
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;
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
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;
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)
--- /dev/null
+/*
+ * 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);
+ }
+}
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;
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);
}
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);
}
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)
"excludedFromPurge": false
},
{
- "name": "master",
+ "name": "main",
"isMain": true,
"type": "BRANCH",
"status": {
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;
.findFirst();
assertThat(mainBranch).isPresent();
- assertThat(mainBranch.get().getKey()).hasToString("master");
+ assertThat(mainBranch.get().getKey()).hasToString(DEFAULT_PROJECT_MAIN_BRANCH_NAME);
}
@Test
.setParam("projectName", "project-name")
.setParam("repositoryName", "repo-name");
- assertThatThrownBy(() -> request.execute())
+ assertThatThrownBy(request::execute)
.isInstanceOf(UnauthorizedException.class);
}
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;
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
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;
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));
}
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;
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
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));
}
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 {
assertThatThrownBy(() -> tester.newRequest()
.setParam("project", project.getKey())
- .setParam("branch", "master")
+ .setParam("branch", DEFAULT_PROJECT_MAIN_BRANCH_NAME)
.setParam("value", "false")
.execute())
.isInstanceOf(IllegalArgumentException.class)
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());
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;
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
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());
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());
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;
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())
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;
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)
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 {
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();
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();
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;
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())
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;
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);
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;
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);
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 {
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)
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)
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)
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)
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())
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())
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);
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 {
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)
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");
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)
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)
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
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;
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");
}
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()))
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;
IndexDefinitions.class,
WebAnalyticsLoaderImpl.class,
new MonitoringWsModule(),
+ DefaultBranchNameResolver.class,
// batch
new BatchWsModule(),
@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;
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);
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);
}
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 {
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"));
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
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");
}
}
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();
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
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();
}
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();
}
/**
@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: ");
}