# HG changeset patch # User Andreas Eisele # Date 1719499372 -7200 # Node ID 5b0a122e78a6854237bb14d38799a8976cfa1933 # Parent 17b119b3cb9a10caa3bb31e52493a1c316c9169f 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. diff -r 17b119b3cb9a -r 5b0a122e78a6 mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java --- a/mercurial-agent/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialIncludeRuleUpdater.java Thu Jun 06 15:27:42 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 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); + } + } + } + } } diff -r 17b119b3cb9a -r 5b0a122e78a6 mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSharedMirrorsTest.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/AgentSideCheckoutWithSharedMirrorsTest.java Thu Jun 06 15:27:42 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); + } + } + } + } }