# HG changeset patch # User Dmitry Neverov # Date 1494926964 -7200 # Node ID 1e352177601142158a454204ccf1b27ee8faf273 # Parent d0a236443fc967261e5e92d6d0740fd923e7a380# Parent c0f3096cfff636e8e48240ea1321943caded0300 Merge branch Indore-2017.1.x diff -r d0a236443fc9 -r 1e3521776011 mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java Mon May 15 18:19:44 2017 +0200 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Constants.java Tue May 16 11:29:24 2017 +0200 @@ -44,4 +44,6 @@ String SHOW_CUSTOM_CLONE_PATH = "teamcity.hg.showCustomClonePath"; String CUSTOM_CLONE_PATH_ENABLED = "teamcity.hg.customClonePathEnabled"; String CUSTOM_CACHES_DIR = "teamcity.hg.customCachesDir"; + String CUSTOM_HG_PATH_ENABLED = "teamcity.hg.customHgPathEnabled"; + String CUSTOM_HG_CONFIG_ENABLED = "teamcity.hg.customConfigEnabled"; } diff -r d0a236443fc9 -r 1e3521776011 mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java Mon May 15 18:19:44 2017 +0200 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/HgVcsRoot.java Tue May 16 11:29:24 2017 +0200 @@ -58,7 +58,7 @@ public HgVcsRoot(@NotNull Map vcsRootProperties) { myVcsRootProperties = vcsRootProperties; myRepository = getProperty(Constants.REPOSITORY_PROP); - myHgCommandPath = getProperty(Constants.HG_COMMAND_PATH_PROP); + myHgCommandPath = readHgCommandPath(); myBranchName = getProperty(Constants.BRANCH_NAME_PROP); myCustomClonePath = readCustomClonePath(); myUncompressedTransfer = "true".equals(getProperty(Constants.UNCOMPRESSED_TRANSFER)); @@ -70,10 +70,27 @@ myUseArchiveForPatch = Boolean.parseBoolean(getProperty(Constants.USE_ARCHIVE_FOR_PATCH)); myPurgePolicy = readPurgePolicy(vcsRootProperties); myIgnoreMissingDefaultBranch = Boolean.valueOf(getProperty(Constants.IGNORE_MISSING_DEFAULT_BRANCH, "false")); - myCustomHgConfig = getProperty(Constants.CUSTOM_HG_CONFIG_PROP, ""); + myCustomHgConfig = readCustomHgConfig(); myUseAgentMirrors = readUseSharedMirrors(); } + private String readHgCommandPath() { + if (TeamCityProperties.getBooleanOrTrue(Constants.CUSTOM_HG_PATH_ENABLED)) { + return getProperty(Constants.HG_COMMAND_PATH_PROP, "hg"); + } else { + return "hg"; + } + } + + @NotNull + private String readCustomHgConfig() { + if (TeamCityProperties.getBooleanOrTrue(Constants.CUSTOM_HG_CONFIG_ENABLED)) { + return getProperty(Constants.CUSTOM_HG_CONFIG_PROP, ""); + } else { + return ""; + } + } + @Nullable private Boolean readUseSharedMirrors() { String prop = getProperty(Constants.USE_AGENT_MIRRORS); diff -r d0a236443fc9 -r 1e3521776011 mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootTest.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootTest.java Mon May 15 18:19:44 2017 +0200 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVcsRootTest.java Tue May 16 11:29:24 2017 +0200 @@ -132,6 +132,29 @@ } } + public void disable_custom_hg_path() throws Exception { + VcsRoot root = vcsRoot().withUrl("http://some.org/repo").withHgPath("/some/path").build(); + assertEquals("/some/path", new HgVcsRoot(root).getHgPath()); + try { + System.setProperty(Constants.CUSTOM_HG_PATH_ENABLED, "false"); + assertEquals("hg", new HgVcsRoot(root).getHgPath()); + } finally { + System.getProperties().remove(Constants.CUSTOM_HG_PATH_ENABLED); + } + } + + public void disable_custom_hg_config() throws Exception { + String customConfig = "[extensions]\nsome.ext ="; + VcsRoot root = vcsRoot().withUrl("http://some.org/repo").withCustomConfig(customConfig).build(); + assertEquals(customConfig, new HgVcsRoot(root).getCustomHgConfig()); + try { + System.setProperty(Constants.CUSTOM_HG_CONFIG_ENABLED, "false"); + assertEquals("", new HgVcsRoot(root).getCustomHgConfig()); + } finally { + System.getProperties().remove(Constants.CUSTOM_HG_CONFIG_ENABLED); + } + } + private VcsRootImpl createVcsRoot(String url) { return createVcsRoot(url, "user", "pwd"); } diff -r d0a236443fc9 -r 1e3521776011 mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java Mon May 15 18:19:44 2017 +0200 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/VcsRootBuilder.java Tue May 16 11:29:24 2017 +0200 @@ -18,11 +18,8 @@ import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot; import jetbrains.buildServer.util.StringUtil; -import jetbrains.buildServer.vcs.SVcsRoot; import jetbrains.buildServer.vcs.impl.VcsRootImpl; import org.jetbrains.annotations.NotNull; -import org.jmock.Expectations; -import org.jmock.Mockery; import java.io.File; import java.io.IOException; @@ -47,6 +44,7 @@ private boolean myIncludeSubreposInPatch = true; private boolean myUseArchiveForPatch = false; private HgVcsRoot.PurgePolicy myPurgePolicy; + private String myCustomConfig; public static VcsRootBuilder vcsRoot() { return new VcsRootBuilder(); @@ -70,36 +68,12 @@ vcsRoot.addProperty(Constants.USE_TAGS_AS_BRANCHES, String.valueOf(myTagsAsBranches)); if (myPurgePolicy != null) vcsRoot.addProperty(Constants.PURGE_POLICY, myPurgePolicy.name()); + if (myCustomConfig != null) + vcsRoot.addProperty(Constants.CUSTOM_HG_CONFIG_PROP, myCustomConfig); return vcsRoot; } - public SVcsRoot build(Mockery context) { - final SVcsRoot root = context.mock(SVcsRoot.class, "SVcsRoot" + myRootId); - context.checking(new Expectations() {{ - allowing(root).describe(false); will(returnValue("toString")); - allowing(root).getVcsName(); will(returnValue(Constants.VCS_NAME)); - allowing(root).getProperty(with(Constants.REPOSITORY_PROP)); will(returnValue(myRepository)); - allowing(root).getProperty(with(Constants.HG_COMMAND_PATH_PROP)); will(returnValue(myHgPath)); - allowing(root).getProperty(with(Constants.BRANCH_NAME_PROP)); will(returnValue(myBranch)); - allowing(root).getProperty(with(Constants.SERVER_CLONE_PATH_PROP)); will(returnValue(null)); - allowing(root).getProperty(with(Constants.USERNAME)); will(returnValue(myUsername)); - allowing(root).getProperty(with(Constants.PASSWORD)); will(returnValue(myPassword)); - allowing(root).getProperty(with(Constants.UNCOMPRESSED_TRANSFER)); will(returnValue(null)); - allowing(root).getProperty(with(Constants.USER_FOR_TAG)); will(returnValue(myUserForTag)); - allowing(root).getProperty(with(Constants.DETECT_SUBREPO_CHANGES)); will(returnValue(String.valueOf(myDetectSubrepoChanges))); - allowing(root).getProperty(with(Constants.USE_TAGS_AS_BRANCHES)); will(returnValue(String.valueOf(myTagsAsBranches))); - allowing(root).getProperty(with(Constants.HG_EXTENSIONS)); will(returnValue(myExtensions)); - }}); - if (myCloneRepositoryTo != null) { - context.checking(new Expectations() {{ - allowing(root).getProperty(with(Constants.SERVER_CLONE_PATH_PROP)); will(returnValue(myCloneRepositoryTo.getAbsolutePath())); - }}); - } - return root; - } - - public VcsRootBuilder withUrl(@NotNull String repository) { myRepository = repository; return this; @@ -193,4 +167,10 @@ myPurgePolicy = policy; return this; } + + + public VcsRootBuilder withCustomConfig(String customConfig) { + myCustomConfig = customConfig; + return this; + } }