Mercurial > hg > mercurial
changeset 910:26de7a765875 Hajipur-9.0.x
TW-39321 better error message when commit destination branch doesn't exist
author | Dmitry Neverov <dmitry.neverov@gmail.com> |
---|---|
date | Tue, 16 Dec 2014 20:11:05 +0100 |
parents | b2ecc56f456c |
children | 15fce0c26e18 |
files | mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCollectChangesPolicy.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitSupport.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitSupportTest.java |
diffstat | 4 files changed, 42 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCollectChangesPolicy.java Tue Dec 09 12:20:05 2014 +0100 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCollectChangesPolicy.java Tue Dec 16 20:11:05 2014 +0100 @@ -56,8 +56,12 @@ @NotNull public RepositoryStateData getCurrentState(@NotNull VcsRoot root) throws VcsException { + return getCurrentState(myHgVcsRootFactory.createHgRoot(root)); + } + + @NotNull + public RepositoryStateData getCurrentState(@NotNull final HgVcsRoot hgRoot) throws VcsException { final OperationContext context = new OperationContext(myVcs, myRepoFactory, createMercurialProgess()); - final HgVcsRoot hgRoot = myHgVcsRootFactory.createHgRoot(root); VcsCallable<Map<String, String>> cmd = new VcsCallable<Map<String, String>>() { public Map<String, String> call() throws VcsException { return getHeads(hgRoot, context); @@ -67,7 +71,7 @@ String defaultBranchName = hgRoot.getBranchName(); if (revisions.get(defaultBranchName) == null && !hgRoot.isIgnoreMissingDefaultBranch()) { throw new VcsException("Cannot find revision of the default branch '" + - defaultBranchName + "' of vcs root " + myVcs.describeVcsRoot(root)); + defaultBranchName + "' of vcs root " + myVcs.describeVcsRoot(hgRoot)); } return RepositoryStateData.createVersionState(defaultBranchName, revisions); }
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitSupport.java Tue Dec 09 12:20:05 2014 +0100 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitSupport.java Tue Dec 16 20:11:05 2014 +0100 @@ -25,7 +25,9 @@ import org.jetbrains.annotations.NotNull; import java.io.*; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; import java.util.Set; public class MercurialCommitSupport implements CommitSupport, MercurialServerExtension { @@ -130,9 +132,11 @@ @NotNull public CommitResult commit(@NotNull CommitSettings commitSettings) throws VcsException { try { - RepositoryStateData state = myVcs.getCollectChangesPolicy().getCurrentState(myRoot); + RepositoryStateData state = getCurrentState(); String defaultBranch = state.getDefaultBranchName(); String defaultBranchRevision = state.getBranchRevisions().get(defaultBranch); + if (defaultBranchRevision == null) + throw new VcsException("The '" + defaultBranch + "' destination branch doesn't exist"); new CheckoutRepository(myMirrorManager, myHgRepoFactory, myConfig.getPullTimeout(), myConfig.useTagsAsBranches(), myHgRoot, myCheckoutDir).setRevision(defaultBranchRevision).checkout(); @@ -164,10 +168,19 @@ return CommitResult.createSuccessResult(repo.getWorkingDirRevision()); } catch (Exception e) { + if (e instanceof VcsException) + throw (VcsException) e; throw new VcsException(e); } } + @NotNull + private RepositoryStateData getCurrentState() throws VcsException { + Map<String, String> props = new HashMap<String, String>(myHgRoot.getProperties()); + props.put(Constants.IGNORE_MISSING_DEFAULT_BRANCH, "true"); + return myVcs.getCollectChangesPolicy().getCurrentState(new HgVcsRoot(props)); + } + private String nonEmptyMessage(@NotNull CommitSettings commitSettings) { String msg = commitSettings.getDescription(); if (!StringUtil.isEmpty(msg))
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue Dec 09 12:20:05 2014 +0100 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue Dec 16 20:11:05 2014 +0100 @@ -180,6 +180,11 @@ return "mercurial: " + vcsRoot.getProperty(Constants.REPOSITORY_PROP); } + @NotNull + public String describeVcsRoot(@NotNull final HgVcsRoot vcsRoot) { + return "mercurial: " + vcsRoot.getProperty(Constants.REPOSITORY_PROP); + } + @Override @NotNull public TestConnectionSupport getTestConnectionSupport() {
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitSupportTest.java Tue Dec 09 12:20:05 2014 +0100 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialCommitSupportTest.java Tue Dec 16 20:11:05 2014 +0100 @@ -100,6 +100,23 @@ } + @TestFor(issues = "TW-39321") + public void should_throw_meaningful_error_if_destination_branch_doesnt_exist(@NotNull HgVersion _) throws Exception { + String nonExistingBranch = "nonExisting"; + VcsRoot root = vcsRoot().withUrl(myRepo).withBranch(nonExistingBranch).build(); + String description = "msg"; + String author = "Joe Doe <joe@some.org>"; + try { + CommitPatchBuilder patchBuilder = myCommitSupport.getCommitPatchBuilder(root); + patchBuilder.createFile("a/b/c", stream("test")); + patchBuilder.commit(new CommitSettingsImpl(author, description)); + patchBuilder.dispose(); + } catch (VcsException e) { + assertEquals("The '" + nonExistingBranch + "' destination branch doesn't exist", e.getMessage()); + } + } + + @NotNull private InputStream stream(@NotNull String content) { return new ByteArrayInputStream(content.getBytes());