changeset 1130:a5e5de1ee625 development/2024.07.x

TW-84326: Stay compatible with updated share extension behavior. - Remove the "shared" extension from "requires" when disabling sharing. - Tests: ignore the "requires" file in shared repository stores. (grafted from 5b0a122e78a6854237bb14d38799a8976cfa1933)
author Andreas Eisele <andreas.eisele@jetbrains.com>
date Thu, 27 Jun 2024 16:42:52 +0200
parents 2a8601afb140
children a272ea98b4b7
files mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSharedMirrorsTest.java
diffstat 2 files changed, 33 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java	Mon Jun 24 11:18:45 2024 +0200
+++ b/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java	Thu Jun 27 16:42:52 2024 +0200
@@ -30,6 +30,7 @@
 import jetbrains.buildServer.buildTriggers.vcs.mercurial.ext.MercurialExtension;
 import jetbrains.buildServer.log.Loggers;
 import jetbrains.buildServer.util.FileUtil;
+import jetbrains.buildServer.util.StringUtil;
 import jetbrains.buildServer.vcs.IncludeRule;
 import jetbrains.buildServer.vcs.VcsException;
 import jetbrains.buildServer.vcs.VcsRoot;
@@ -38,7 +39,9 @@
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.charset.StandardCharsets;
 import java.util.ArrayList;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 
@@ -185,11 +188,24 @@
     }
   }
 
-  private void disableSharing(@NotNull File workingDir) {
+  private void disableSharing(@NotNull File workingDir) throws IOException {
     File dotHg = new File(workingDir, ".hg");
     File sharedpath = new File(dotHg, "sharedpath");
-    if (sharedpath.exists())
+    if (sharedpath.exists()) {
       FileUtil.delete(sharedpath);
+
+      // TW-84326: newer versions of mercurial fail to pull if "shared" is still required, but the sharedpath is gone
+      File requires = new File(dotHg, "requires");
+      if (requires.exists()) {
+        final List<String> lines = FileUtil.readFile(requires);
+        FileUtil.delete(requires);
+        for (String requirement : lines) {
+          if (!"shared".equals(requirement)) {
+            FileUtil.writeToFile(requires, (requirement + "\n").getBytes(StandardCharsets.UTF_8), true);
+          }
+        }
+      }
+    }
   }
 
 
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSharedMirrorsTest.java	Mon Jun 24 11:18:45 2024 +0200
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSharedMirrorsTest.java	Thu Jun 27 16:42:52 2024 +0200
@@ -31,6 +31,7 @@
 import jetbrains.buildServer.vcs.VcsRoot;
 import jetbrains.buildServer.vcs.impl.VcsRootImpl;
 import org.jetbrains.annotations.NotNull;
+import org.jetbrains.annotations.Nullable;
 import org.jmock.Expectations;
 import org.jmock.Mockery;
 import org.testng.SkipException;
@@ -98,7 +99,7 @@
     String version = "4:b06a290a363b";
     update(root, version);
     File workingDirStore = new File(new File(myWorkDir, ".hg"), "store");
-    assertTrue(!workingDirStore.exists() || listFiles(workingDirStore).length == 0);
+    assertStoreHasNoHistory(workingDirStore);
     checkWorkingDir("patch1/after", myWorkDir);
   }
 
@@ -111,16 +112,11 @@
     update(root, "34017377d9c3");
 
     File subrepoStore = new File(new File(new File(myWorkDir, "r2"), ".hg"), "store");
-    assertTrue(!subrepoStore.exists() || listFiles(subrepoStore).length == 0);
+    assertStoreHasNoHistory(subrepoStore);
   }
 
 
   public void turn_off_sharing() throws Exception {
-    // TODO: TW-84326: share extension doesn't work as expected on ARM agents
-    if (SystemInfo.isARM64) {
-      throw new SkipException("Ignore test on ARM64 machine");
-    }
-
     File myR1Dir = copy(new File("mercurial-tests/testData/subrepos/r1"));
     copy(new File("mercurial-tests/testData/subrepos/r2"));
     copy(new File("mercurial-tests/testData/subrepos/r3"));
@@ -213,4 +209,16 @@
     }
     return copyDir;
   }
+
+  private void assertStoreHasNoHistory(@Nullable File storeDir) {
+    if (storeDir != null) {
+      final File[] files = listFiles(storeDir);
+      for (File file : files) {
+        // TW-84326: newer mercurial versions keep a "requires" file in store
+        if (!"requires".equals(file.getName())) {
+          fail("store of shared repository at " + storeDir + " contains unexpected file: " + file);
+        }
+      }
+    }
+  }
 }