]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-17547 When creating a project, error is returned if key already exists in multi...
authorDuarte Meneses <duarte.meneses@sonarsource.com>
Mon, 31 Oct 2022 20:58:49 +0000 (15:58 -0500)
committersonartech <sonartech@sonarsource.com>
Tue, 1 Nov 2022 20:03:09 +0000 (20:03 +0000)
server/sonar-db-dao/src/main/resources/org/sonar/db/component/ComponentMapper.xml
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentDaoTest.java

index 5f67411da9d4ac31fece74132606b5a4d4b5bb47..6fd35693df0949818343a0723a7c5dd28f0e8298 100644 (file)
@@ -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">
index 706b10129175d88ebde6f902aab7bf0faaa9dd72..80904430f7c3bdcfc034b36ca8fc6fd6dc127522 100644 (file)
@@ -2065,6 +2065,18 @@ public class ComponentDaoTest {
     assertThat(result.getKey()).isEqualTo(projectKey);
   }
 
+  @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();