# HG changeset patch # User Dmitry Neverov # Date 1303224040 -14400 # Node ID 20817ebd1a05e9cc77f277fa7d05e4557aec8502 # Parent dbf671db463f87efb3753025c42d01ca8cf9e9b9 Fix TW-16278 diff -r dbf671db463f -r 20817ebd1a05 mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java --- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue Apr 19 18:35:37 2011 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue Apr 19 18:40:40 2011 +0400 @@ -27,6 +27,7 @@ import jetbrains.buildServer.util.filters.Filter; import jetbrains.buildServer.util.filters.FilterUtil; import jetbrains.buildServer.vcs.*; +import jetbrains.buildServer.vcs.impl.VcsRootImpl; import jetbrains.buildServer.vcs.patches.PatchBuilder; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -626,27 +627,28 @@ } public String label(@NotNull String label, @NotNull String version, @NotNull VcsRoot root, @NotNull CheckoutRules checkoutRules) throws VcsException { - syncClonedRepository(root); - - Settings settings = createSettings(root); + File tmpDir = null; + try { + tmpDir = createLabelingTmpDir(); + ((VcsRootImpl) root).addProperty(Constants.SERVER_CLONE_PATH_PROP, tmpDir.getAbsolutePath()); - // I do not know why but hg tag does not work correctly if - // update command was not invoked for the current repo - // in such case if there were no tags before Mercurial attempts to - // create new head when tag is pushed to the parent repository - UpdateCommand uc = new UpdateCommand(settings); - uc.execute(); + syncClonedRepository(root); + Settings settings = createSettings(root); + new UpdateCommand(settings).execute(); - String fixedTagname = fixTagName(label); - TagCommand tc = new TagCommand(settings); - tc.setRevId(new ChangeSet(version).getId()); - tc.setTag(fixedTagname); - tc.execute(); + String fixedTagname = fixTagName(label); + TagCommand tc = new TagCommand(settings); + tc.setRevId(new ChangeSet(version).getId()); + tc.setTag(fixedTagname); + tc.execute(); - PushCommand pc = new PushCommand(settings); -// pc.setForce(true); - pc.execute(); - return fixedTagname; + PushCommand pc = new PushCommand(settings); + pc.execute(); + return fixedTagname; + } finally { + if (tmpDir != null) + FileUtil.delete(tmpDir); + } } private String fixTagName(final String label) { @@ -690,4 +692,13 @@ public boolean isAgentSideCheckoutAvailable() { return true; } + + + private File createLabelingTmpDir() throws VcsException { + try { + return FileUtil.createTempDirectory("mercurial", "label"); + } catch (IOException e) { + throw new VcsException("Unable to create temporary directory"); + } + } }