]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10455 Fix bulk update of project having branches containing "/"
authorJulien Lancelot <julien.lancelot@sonarsource.com>
Wed, 28 Mar 2018 15:42:43 +0000 (17:42 +0200)
committerJanos Gyerik <janos.gyerik@sonarsource.com>
Wed, 4 Apr 2018 12:40:51 +0000 (14:40 +0200)
server/sonar-db-dao/src/main/java/org/sonar/db/component/ComponentKeyUpdaterDao.java
server/sonar-db-dao/src/test/java/org/sonar/db/component/ComponentKeyUpdaterDaoTest.java

index c3a737369265b000620fa667ee63aab8508f223a..a83a1849105c84e4972c3f253b46d5acb48f22a2 100644 (file)
@@ -110,8 +110,9 @@ public class ComponentKeyUpdaterDao implements Dao {
     ComponentKeyUpdaterMapper mapper = session.getMapper(ComponentKeyUpdaterMapper.class);
     // must SELECT first everything
     Set<ResourceDto> modules = collectAllModules(projectUuid, stringToReplace, mapper);
+    checkNewNameOfAllModules(modules, stringToReplace, replacementString, mapper);
 
-    // add branches
+    // add branches (no check should be done as branch keys cannot be changed by the user)
     Map<String, String> branchBaseKeys = new HashMap<>();
     session.getMapper(BranchMapper.class).selectByProjectUuid(projectUuid)
       .stream()
@@ -122,7 +123,6 @@ public class ComponentKeyUpdaterDao implements Dao {
         branchModules.forEach(module -> branchBaseKeys.put(module.getKey(), branchBaseKey(module.getKey())));
       });
 
-    checkNewNameOfAllModules(modules, stringToReplace, replacementString, mapper);
     Map<ResourceDto, List<ResourceDto>> allResourcesByModuleMap = Maps.newHashMap();
     for (ResourceDto module : modules) {
       allResourcesByModuleMap.put(module, mapper.selectProjectResources(module.getUuid()));
index 3166d3aab8b22fa927a6254d498bc33e5977fcf3..2e39482e656dcd731f0d6a815d4a3243918a4720 100644 (file)
@@ -161,6 +161,18 @@ public class ComponentKeyUpdaterDaoTest {
       .forEach(map -> map.values().forEach(k -> assertThat(k.toString()).startsWith(newProjectKey)));
   }
 
+  @Test
+  public void bulk_updateKey_on_branch_containing_slash() {
+    ComponentDto project = db.components().insertMainBranch();
+    ComponentDto branch = db.components().insertProjectBranch(project, b -> b.setKey("branch/with/slash"));
+    String newKey = "newKey";
+
+    underTest.bulkUpdateKey(dbSession, project.uuid(), project.getKey(), newKey);
+
+    assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, newKey)).hasSize(1);
+    assertThat(dbClient.componentDao().selectAllComponentsFromProjectKey(dbSession, ComponentDto.generateBranchKey(newKey, branch.getBranch()))).hasSize(1);
+  }
+
   @Test
   public void bulk_updateKey_updates_pull_requests_too() {
     ComponentDto project = db.components().insertMainBranch();