# HG changeset patch # User Dmitry Neverov # Date 1494864973 -7200 # Node ID e4332192fc0d1a81524a69d4699fcc63a17c0c00 # Parent e9987cf08919d57bda9dd12e344504ea07fb953b TW-50033 handle tag and branch name clash during labeling diff -r e9987cf08919 -r e4332192fc0d mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVersion.java --- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVersion.java Fri Apr 28 19:19:15 2017 +0200 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVersion.java Mon May 15 18:16:13 2017 +0200 @@ -55,6 +55,11 @@ } + public boolean isLessThan(@NotNull HgVersion other) { + return compareTo(other) < 0; + } + + @Override public String toString() { return myMajor + "." + myMinor + "." + myThird; diff -r e9987cf08919 -r e4332192fc0d mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Fri Apr 28 19:19:15 2017 +0200 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Mon May 15 18:16:13 2017 +0200 @@ -708,14 +708,26 @@ syncRepository(hgRoot); HgRepo repo = createRepo(hgRoot); String branchName = getCommitBranch(repo, version); - repo.update().branch(branchName).call(); + HgVersion hgVersion = repo.version().call(); + if (hgVersion.isEqualsOrGreaterThan(ServerHgRepo.REVSET_HG_VERSION)) { + repo.update().branch("branch('" + branchName + "') and head()").call(); + } else { + repo.update().branch(branchName).call(); + } String fixedTagname = fixTagName(label); - repo.tag().revision(version) - .tagName(fixedTagname) - .byUser(hgRoot.getUserForTag()) - .call(); - + try { + repo.tag().revision(version) + .tagName(fixedTagname) + .byUser(hgRoot.getUserForTag()) + .call(); + } catch (VcsException e) { + String msg = e.getMessage(); + if (msg != null && msg.contains("not at a branch head") && hgVersion.isLessThan(ServerHgRepo.REVSET_HG_VERSION)) { + Loggers.VCS.warn("Please upgrade mercurial to the version supporting revsets(" + ServerHgRepo.REVSET_HG_VERSION + "+), current version: " + hgVersion); + } + throw e; + } repo.push().toRepository(hgRoot.getRepository()).call(); return fixedTagname; } finally { diff -r e9987cf08919 -r e4332192fc0d mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java Fri Apr 28 19:19:15 2017 +0200 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java Mon May 15 18:16:13 2017 +0200 @@ -36,7 +36,7 @@ */ public class ServerHgRepo extends HgRepo { - private final static HgVersion REVSET_HG_VERSION = new HgVersion(1, 7, 0); + public final static HgVersion REVSET_HG_VERSION = new HgVersion(1, 7, 0); private final CommandSettingsFactory myCommandSettingsFactory; private final ServerPluginConfig myConfig; protected final MercurialClasspathTemplate myLogTemplate = new MercurialClasspathTemplate("/buildServerResources/log.template", "hg.log.template"); diff -r e9987cf08919 -r e4332192fc0d mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialPatchTestCase.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialPatchTestCase.java Fri Apr 28 19:19:15 2017 +0200 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialPatchTestCase.java Mon May 15 18:16:13 2017 +0200 @@ -15,9 +15,12 @@ */ package jetbrains.buildServer.buildTriggers.vcs.mercurial; +import jetbrains.buildServer.serverSide.BasePropertiesModel; +import jetbrains.buildServer.serverSide.TeamCityProperties; import jetbrains.buildServer.vcs.impl.VcsRootImpl; import jetbrains.buildServer.vcs.patches.PatchTestCase; import org.jetbrains.annotations.NotNull; +import org.testng.annotations.BeforeMethod; import java.io.File; import java.io.IOException; @@ -29,6 +32,13 @@ * Date: 31.07.2008 */ public abstract class BaseMercurialPatchTestCase extends PatchTestCase { + @Override + @BeforeMethod + protected void setUp() throws Exception { + super.setUp(); + new TeamCityProperties() {{ setModel(new BasePropertiesModel() {});}}; + } + protected VcsRootImpl createVcsRoot(@NotNull String repPath) throws IOException { File repository = copyRepository(myTempFiles, repPath); return new VcsRootBuilder().withUrl(repository.getAbsolutePath()).build(); diff -r e9987cf08919 -r e4332192fc0d mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java --- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Fri Apr 28 19:19:15 2017 +0200 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Mon May 15 18:16:13 2017 +0200 @@ -308,6 +308,21 @@ } + @TestFor(issues = "TW-50033") + public void labeling_with_branch_tag_clash() throws Exception { + VcsRootImpl vcsRoot = createVcsRoot(new File("mercurial-tests/testData/rep2").getAbsolutePath(), "default"); + RepositoryStateData s1 = myVcs.getCollectChangesPolicy().getCurrentState(vcsRoot); + //repository contains the 'topic' branch, create tag on non-last revision in this branch + myVcs.label("topic", "26:27184c50d7ef", vcsRoot, CheckoutRules.DEFAULT); + RepositoryStateData s2 = myVcs.getCollectChangesPolicy().getCurrentState(vcsRoot); + //retrieve tag into local clone + myVcs.getCollectChangesPolicy().collectChanges(vcsRoot, s1, s2, CheckoutRules.DEFAULT); + + //tag another commit from the 'topic' branch + myVcs.label("v1", "27:2a368008e4d9", vcsRoot, CheckoutRules.DEFAULT); + } + + public void tag_should_be_created_in_branch_to_which_tagged_revision_belongs() throws Exception { File remoteRepo = copyRepository(myTempFiles, myRep2Path); VcsRoot root = vcsRoot().withUrl(remoteRepo.getCanonicalPath()).withBranch("default").build();