changeset 965:d0a236443fc9

Merge branch Indore-2017.1.x
author Dmitry Neverov <dmitry.neverov@gmail.com>
date Mon, 15 May 2017 18:19:44 +0200
parents 3e7fde939ccc (current diff) e4332192fc0d (diff)
children 1e3521776011
files
diffstat 6 files changed, 50 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/README.txt	Tue Apr 25 13:01:25 2017 +0200
+++ b/README.txt	Mon May 15 18:19:44 2017 +0200
@@ -6,3 +6,4 @@
 TeamCity 4.x and later
 
 Download mercurial-server.zip and put it into the .BuildServer/plugins folder. Restart server.
+
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVersion.java	Tue Apr 25 13:01:25 2017 +0200
+++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgVersion.java	Mon May 15 18:19:44 2017 +0200
@@ -55,6 +55,11 @@
   }
 
 
+  public boolean isLessThan(@NotNull HgVersion other) {
+    return compareTo(other) < 0;
+  }
+
+
   @Override
   public String toString() {
     return myMajor + "." + myMinor + "." + myThird;
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Tue Apr 25 13:01:25 2017 +0200
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java	Mon May 15 18:19:44 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 {
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java	Tue Apr 25 13:01:25 2017 +0200
+++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/ServerHgRepo.java	Mon May 15 18:19:44 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");
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialPatchTestCase.java	Tue Apr 25 13:01:25 2017 +0200
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/BaseMercurialPatchTestCase.java	Mon May 15 18:19:44 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();
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Tue Apr 25 13:01:25 2017 +0200
+++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java	Mon May 15 18:19:44 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();