aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2022-10-31 15:58:49 -0500
committersonartech <sonartech@sonarsource.com>2022-11-01 20:03:09 +0000
commitb309ce1704e490af7daef2a0d0ab1bbba8c930b8 (patch)
treebf8ce049aff31eebfd40938ece5d0130a7a76282
parentb2bd6c19dd260a5fcdc124c8eee8b5c10ae34693 (diff)
downloadsonarqube-b309ce1704e490af7daef2a0d0ab1bbba8c930b8.tar.gz
sonarqube-b309ce1704e490af7daef2a0d0ab1bbba8c930b8.zip
SONAR-17547 When creating a project, error is returned if key already exists in multiple branches
-rw-r--r--server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml1
-rw-r--r--server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java12
2 files changed, 13 insertions, 0 deletions
diff --git a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
index 5f67411da9d..6fd35693df0 100644
--- a/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
+++ b/server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
@@ -39,6 +39,7 @@
FROM components p
where
lower(p.kee)=lower(#{key,jdbcType=VARCHAR})
+ and p.main_branch_project_uuid is null
</select>
<select id="selectByKeyAndBranchKey" parameterType="String" resultType="Component">
diff --git a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
index 706b1012917..80904430f7c 100644
--- a/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
+++ b/server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java
@@ -2066,6 +2066,18 @@ public class ComponentDaoTest {
}
@Test
+ public void selectByKeyCaseInsensitive_should_not_match_non_main_branch() {
+ String projectKey = randomAlphabetic(5).toLowerCase();
+ ProjectDto project = db.components().insertPrivateProjectDto(c -> c.setKey(projectKey));
+ BranchDto projectBranch = db.components().insertProjectBranch(project);
+ ComponentDto file = db.components().insertFile(projectBranch);
+
+ ComponentDto result = underTest.selectByKeyCaseInsensitive(db.getSession(), file.getKey()).orElse(null);
+
+ assertThat(result).isNull();
+ }
+
+ @Test
public void selectByKeyCaseInsensitive_shouldNotFindProject_whenKeyIsDifferent() {
String projectKey = randomAlphabetic(5).toLowerCase();
db.components().insertPrivateProject(c -> c.setKey(projectKey));