Mercurial > hg > mercurial
changeset 749:63babe8e01a1
support auto-merge for bookmarks
author | Dmitry Neverov <dmitry.neverov@jetbrains.com> |
---|---|
date | Mon, 10 Feb 2014 20:26:24 +0100 |
parents | 54008dd23f2b |
children | c33aefd02111 |
files | mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PushCommand.java mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/UpdateBookmarkCommand.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialMergeSupport.java |
diffstat | 4 files changed, 84 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java Mon Feb 10 10:57:16 2014 +0100 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/HgRepo.java Mon Feb 10 20:26:24 2014 +0100 @@ -94,6 +94,10 @@ return new BookmarksCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings); } + public UpdateBookmarkCommand updateBookmark() { + return new UpdateBookmarkCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings); + } + public TagsCommand tags() { return new TagsCommand(myCommandSettingsFactory.create(), myHgPath, myWorkingDir, myAuthSettings); }
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PushCommand.java Mon Feb 10 10:57:16 2014 +0100 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/PushCommand.java Mon Feb 10 20:26:24 2014 +0100 @@ -25,6 +25,7 @@ */ public class PushCommand extends AuthCommand { + private String myBookmark; private String myRepositoryUrl; public PushCommand(@NotNull CommandSettings commandSettings, @@ -34,6 +35,11 @@ super(commandSettings, hgPath, workingDir, authSettings); } + public PushCommand bookmark(@NotNull String bookmark) { + myBookmark = bookmark; + return this; + } + public PushCommand toRepository(@NotNull String repositoryUrl) { myRepositoryUrl = repositoryUrl; return this; @@ -42,6 +48,9 @@ public void call() throws VcsException { MercurialCommandLine cli = createCommandLine(); cli.addParameter("push"); + if (myBookmark != null) { + cli.addParameters("-B", myBookmark); + } if (myRepositoryUrl.startsWith("http")) { addHttpAuthParams(cli); cli.addParameter(myRepositoryUrl);
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/UpdateBookmarkCommand.java Mon Feb 10 20:26:24 2014 +0100 @@ -0,0 +1,56 @@ +/* + * Copyright 2000-2014 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package jetbrains.buildServer.buildTriggers.vcs.mercurial.command; + +import jetbrains.buildServer.vcs.VcsException; +import org.jetbrains.annotations.NotNull; + +import java.io.File; + +public class UpdateBookmarkCommand extends VcsRootCommand { + + private String myBookmarkName; + private String myRevision; + + public UpdateBookmarkCommand(@NotNull CommandSettings commandSettings, + @NotNull String hgPath, + @NotNull File workingDir, + @NotNull AuthSettings authSettings) { + super(commandSettings, hgPath, workingDir, authSettings); + } + + public UpdateBookmarkCommand name(@NotNull String bookmarkName) { + myBookmarkName = bookmarkName; + return this; + } + + public UpdateBookmarkCommand setRevision(@NotNull String revision) { + myRevision = revision; + return this; + } + + public void call() throws VcsException { + MercurialCommandLine cmd = createCommandLine(); + cmd.addParameter("bookmark"); + if (myBookmarkName != null) + cmd.addParameter(myBookmarkName); + if (myRevision != null) { + cmd.addParameters("-r", myRevision); + } + runCommand(cmd); + } +}
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialMergeSupport.java Mon Feb 10 10:57:16 2014 +0100 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialMergeSupport.java Mon Feb 10 20:26:24 2014 +0100 @@ -18,6 +18,7 @@ import com.intellij.openapi.diagnostic.Logger; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.HgVcsRoot; +import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.PushCommand; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.exception.MergeConflictException; import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.exception.MergeWithWorkingDirAncestor; import jetbrains.buildServer.vcs.*; @@ -116,9 +117,15 @@ } repo.commit().by(hgRoot.getUserForTag()).message(message).call(); + boolean bookmark = isBookmark(repo, dstBranch); + if (bookmark) + repo.updateBookmark().name(dstBranch).call(); try { - repo.push().toRepository(hgRoot.getRepository()).call(); + PushCommand push = repo.push().toRepository(hgRoot.getRepository()); + if (bookmark) + push.bookmark(dstBranch); + push.call(); } catch (VcsException e) { LOG.info("Error while pushing a merge commit, root " + root + ", revision " + srcRevision + ", destination " + dstBranch, e); throw e; @@ -135,6 +142,13 @@ } + private boolean isBookmark(@NotNull HgRepo repo, @NotNull String branch) throws VcsException { + if (repo.branches().call().keySet().contains(branch)) + return false; + return repo.bookmarks().call().keySet().contains(branch); + } + + private List<String> detectConflicts(@NotNull HgVcsRoot root, @NotNull String prefix, @NotNull HgRepo repo) throws VcsException { List<String> conflicts = new ArrayList<String>(); for (String conflict : repo.resolve().call()) {