Mercurial > hg > mercurial
changeset 444:a05eca69fc01
Ensure plugin works without revnums in revisions
author | Dmitry Neverov <dmitry.neverov@gmail.com> |
---|---|
date | Wed, 20 Jun 2012 22:54:13 +0400 |
parents | d0f80762461a |
children | b47cfe5cbaba |
files | mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/IdentifyCommand.java mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/RevisionFormatTest.java mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Util.java mercurial-tests/src/testng.xml |
diffstat | 6 files changed, 159 insertions(+), 23 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/IdentifyCommand.java Tue Jun 19 15:17:11 2012 +0400 +++ b/mercurial-common/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/command/IdentifyCommand.java Wed Jun 20 22:54:13 2012 +0400 @@ -34,11 +34,17 @@ private Integer myRevisionNumber; private AuthSettings myAuthSettings; private String myRepositoryUrl; + private String myNamedRevision; public IdentifyCommand(@NotNull String hgPath, @NotNull File workingDir, @NotNull AuthSettings authSettings) { super(hgPath, workingDir, authSettings); } + public IdentifyCommand namedRevision(@NotNull String name) { + myNamedRevision = name; + return this; + } + public IdentifyCommand revision(@NotNull String revision) { myChangeSet = new ChangeSet(revision); return this; @@ -83,6 +89,9 @@ } else if (myRevisionNumber != null) { cli.addParameter("--rev"); cli.addParameter(myRevisionNumber.toString()); + } else if (myNamedRevision != null) { + cli.addParameter("--rev"); + cli.addParameter(myNamedRevision); } CommandResult res = runCommand(cli, with().failureWhenStderrNotEmpty()); String output = res.getStdout().trim();
--- a/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Tue Jun 19 15:17:11 2012 +0400 +++ b/mercurial-server/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupport.java Wed Jun 20 22:54:13 2012 +0400 @@ -623,7 +623,7 @@ syncRepository(hgRoot); ChangeSet to = new ChangeSet(toVersion); if (fromVersion == null) { - buildFullPatch(hgRoot, new ChangeSet(toVersion), builder, checkoutRules); + buildFullPatch(hgRoot, to, builder, checkoutRules); } else { ChangeSet from = new ChangeSet(fromVersion); HgRepo repo = createRepo(hgRoot); @@ -632,7 +632,7 @@ cleanCheckoutDir(builder, checkoutRules); buildFullPatch(hgRoot, to, builder, checkoutRules); } else { - buildIncrementalPatch(hgRoot, new ChangeSet(fromVersion), new ChangeSet(toVersion), builder, checkoutRules); + buildIncrementalPatch(hgRoot, from, to, builder, checkoutRules); } } }
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Tue Jun 19 15:17:11 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/MercurialVcsSupportTest.java Wed Jun 20 22:54:13 2012 +0400 @@ -33,6 +33,7 @@ import java.util.*; import static com.intellij.openapi.util.io.FileUtil.*; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.buildPatch; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; @@ -120,20 +121,12 @@ assertEquals(normalizePath(files3.get(0).getRelativeFileName()), "dir1/file4.txt"); } - private ByteArrayOutputStream buildPatch(VcsRoot vcsRoot, String from, String to, CheckoutRules rules) throws IOException, VcsException { - final ByteArrayOutputStream output = new ByteArrayOutputStream(); - final PatchBuilderImpl builder = new PatchBuilderImpl(output); - myVcs.buildPatch(vcsRoot, from, to, builder, rules); - builder.close(); - return output; - } - @Test public void test_build_patch() throws IOException, VcsException { setName("cleanPatch1"); VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); - ByteArrayOutputStream output = buildPatch(vcsRoot, null, "4:b06a290a363b", new CheckoutRules("")); + ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, null, "4:b06a290a363b", new CheckoutRules("")); checkPatchResult(output.toByteArray()); File clonedReposParentDir = myPluginConfig.getCachesDir(); @@ -149,7 +142,7 @@ setName("patch1"); VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); - ByteArrayOutputStream output = buildPatch(vcsRoot, "3:9522278aa38d", "4:b06a290a363b", new CheckoutRules("")); + ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, "3:9522278aa38d", "4:b06a290a363b", new CheckoutRules("")); checkPatchResult(output.toByteArray()); } @@ -158,7 +151,7 @@ setName("patch1_checkout_rules"); VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); - ByteArrayOutputStream output = buildPatch(vcsRoot, "3:9522278aa38d", "4:b06a290a363b", new CheckoutRules("+:dir1=>path")); + ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, "3:9522278aa38d", "4:b06a290a363b", new CheckoutRules("+:dir1=>path")); checkPatchResult(output.toByteArray()); } @@ -167,7 +160,7 @@ setName("cleanPatch1_checkout_rules"); VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); - ByteArrayOutputStream output = buildPatch(vcsRoot, null, "4:b06a290a363b", new CheckoutRules("+:dir1/subdir=>.")); + ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, null, "4:b06a290a363b", new CheckoutRules("+:dir1/subdir=>.")); checkPatchResult(output.toByteArray()); } @@ -176,7 +169,7 @@ setName("patch2"); VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); - ByteArrayOutputStream output = buildPatch(vcsRoot, "3:9522278aa38d", "6:b9deb9a1c6f4", new CheckoutRules("")); + ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, "3:9522278aa38d", "6:b9deb9a1c6f4", new CheckoutRules("")); checkPatchResult(output.toByteArray()); } @@ -192,7 +185,7 @@ VcsRootImpl root = vcsRoot().withUrl(r1.getAbsolutePath()).build(); setName("clean_patch_with_subrepositories"); - checkPatchResult(buildPatch(root, null, "3:d350e7209906", CheckoutRules.DEFAULT).toByteArray()); + checkPatchResult(buildPatch(myVcs, root, null, "3:d350e7209906", CheckoutRules.DEFAULT).toByteArray()); } public void test_get_content() throws IOException, VcsException { @@ -338,7 +331,7 @@ setName("patch3"); VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch"); - ByteArrayOutputStream output = buildPatch(vcsRoot, null, "7:376dcf05cd2a", new CheckoutRules("")); + ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, null, "7:376dcf05cd2a", new CheckoutRules("")); checkPatchResult(output.toByteArray()); } @@ -347,7 +340,7 @@ setName("patch3_checkout_rules1"); VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch"); - ByteArrayOutputStream output = buildPatch(vcsRoot, null, "7:376dcf05cd2a", new CheckoutRules("+:.=>path")); + ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, null, "7:376dcf05cd2a", new CheckoutRules("+:.=>path")); checkPatchResult(output.toByteArray()); } @@ -356,7 +349,7 @@ setName("patch3_checkout_rules2"); VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch"); - ByteArrayOutputStream output = buildPatch(vcsRoot, null, "7:376dcf05cd2a", new CheckoutRules("+:dir1=>path/dir1\n+:dir with space")); + ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, null, "7:376dcf05cd2a", new CheckoutRules("+:dir1=>path/dir1\n+:dir with space")); checkPatchResult(output.toByteArray()); } @@ -365,7 +358,7 @@ setName("patch4"); VcsRootImpl vcsRoot = createVcsRoot(simpleRepo(), "test_branch"); - ByteArrayOutputStream output = buildPatch(vcsRoot, "7:376dcf05cd2a", "8:04c3ae4c6312", new CheckoutRules("")); + ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, "7:376dcf05cd2a", "8:04c3ae4c6312", new CheckoutRules("")); checkPatchResult(output.toByteArray()); } @@ -393,7 +386,7 @@ File cloneDir = myTempFiles.createTempDir(); vcsRoot.addProperty(Constants.SERVER_CLONE_PATH_PROP, cloneDir.getAbsolutePath()); - ByteArrayOutputStream output = buildPatch(vcsRoot, null, "4:b06a290a363b", new CheckoutRules("")); + ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, null, "4:b06a290a363b", new CheckoutRules("")); checkPatchResult(output.toByteArray()); @@ -403,14 +396,14 @@ public void build_patch_from_newer_revision_to_earlier() throws Exception { setName("patch5"); VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); - ByteArrayOutputStream output = buildPatch(vcsRoot, "6:b9deb9a1c6f4", "3:9522278aa38d", CheckoutRules.DEFAULT); + ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, "6:b9deb9a1c6f4", "3:9522278aa38d", CheckoutRules.DEFAULT); checkPatchResult(output.toByteArray()); } public void build_patch_from_unknown_revision() throws Exception { setName("patch6"); VcsRootImpl vcsRoot = createVcsRoot(simpleRepo()); - ByteArrayOutputStream output = buildPatch(vcsRoot, "6:hahahahahaha", "3:9522278aa38d", new CheckoutRules("+:.=>path")); + ByteArrayOutputStream output = buildPatch(myVcs, vcsRoot, "6:hahahahahaha", "3:9522278aa38d", new CheckoutRules("+:.=>path")); checkPatchResult(output.toByteArray()); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/RevisionFormatTest.java Wed Jun 20 22:54:13 2012 +0400 @@ -0,0 +1,115 @@ +package jetbrains.buildServer.buildTriggers.vcs.mercurial; + +import com.intellij.openapi.diagnostic.Logger; +import jetbrains.buildServer.TempFiles; +import jetbrains.buildServer.buildTriggers.vcs.mercurial.command.AuthSettings; +import jetbrains.buildServer.log.Log4jFactory; +import jetbrains.buildServer.vcs.CheckoutRules; +import jetbrains.buildServer.vcs.ModificationData; +import jetbrains.buildServer.vcs.VcsException; +import jetbrains.buildServer.vcs.VcsRoot; +import jetbrains.buildServer.vcs.impl.VcsRootImpl; +import jetbrains.buildServer.vcs.patches.PatchTestCase; +import org.jetbrains.annotations.NotNull; +import org.jmock.Mockery; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; + +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.IOException; +import java.util.List; + +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.buildPatch; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.Util.copyRepository; +import static jetbrains.buildServer.buildTriggers.vcs.mercurial.VcsRootBuilder.vcsRoot; + +@Test +public class RevisionFormatTest extends PatchTestCase { + + static { + Logger.setFactory(new Log4jFactory()); + } + + private TempFiles myTempFiles; + private MercurialVcsSupport myVcs; + private VcsRoot myRoot; + private File myRemoteRepoDir; + + @BeforeMethod + public void setUp() throws Exception { + myTempFiles = new TempFiles(); + Mockery context = new Mockery(); + ServerPluginConfig myPluginConfig = new ServerPluginConfigBuilder() + .cachesDir(myTempFiles.createTempDir()) + .build(); + myVcs = Util.createMercurialServerSupport(context, myPluginConfig); + + myRemoteRepoDir = copyRepository(myTempFiles, new File("mercurial-tests/testData/rep1").getAbsolutePath()); + myRoot = vcsRoot().withUrl(myRemoteRepoDir.getAbsolutePath()).build(); + } + + @AfterMethod + public void tearDown() { + myTempFiles.cleanup(); + } + + + public void collect_changes_result_does_not_depend_on_revnums() throws VcsException { + List<ModificationData> changesWithRevnums = myVcs.collectChanges(myRoot, + "1:1d446e82d356", "3:9522278aa38d", CheckoutRules.DEFAULT); + List<ModificationData> changesWithoutRevnums = myVcs.collectChanges(myRoot, + "1d446e82d356", "9522278aa38d", CheckoutRules.DEFAULT); + assertEquals(changesWithoutRevnums, changesWithRevnums); + } + + + public void labeling_does_not_depend_on_revnums() throws Exception { + myVcs.label("tag1", "3:9522278aa38d", myRoot, CheckoutRules.DEFAULT); + myVcs.label("tag2", "9522278aa38d", myRoot, CheckoutRules.DEFAULT); + HgRepo repo = createRepo(myRemoteRepoDir); + String tag1 = repo.id().inLocalRepository().namedRevision("tag1").call(); + String tag2 = repo.id().inLocalRepository().namedRevision("tag2").call(); + assertEquals(tag2, tag1); + } + + + public void get_file_content_does_not_depend_on_revnums() throws Exception { + byte[] contentWithRevnums = myVcs.getContent("dir1/file4.txt", myRoot, "2:7209b1f1d793"); + byte[] contentWithoutRevnums = myVcs.getContent("dir1/file4.txt", myRoot, "7209b1f1d793"); + assertEquals(contentWithoutRevnums, contentWithRevnums); + } + + + public void clean_patch_does_not_depend_on_revnums() throws Exception { + setName("cleanPatch1_checkout_rules"); + ByteArrayOutputStream output = buildPatch(myVcs, myRoot, null, "4:b06a290a363b", new CheckoutRules("+:dir1/subdir=>.")); + checkPatchResult(output.toByteArray()); + output = buildPatch(myVcs, myRoot, null, "b06a290a363b", new CheckoutRules("+:dir1/subdir=>.")); + checkPatchResult(output.toByteArray()); + } + + public void incremental_patch_does_not_depend_on_revnums() throws Exception { + setName("patch2"); + ByteArrayOutputStream output = buildPatch(myVcs, myRoot, "3:9522278aa38d", "6:b9deb9a1c6f4", CheckoutRules.DEFAULT); + checkPatchResult(output.toByteArray()); + output = buildPatch(myVcs, myRoot, "9522278aa38d", "6:b9deb9a1c6f4", CheckoutRules.DEFAULT); + checkPatchResult(output.toByteArray()); + output = buildPatch(myVcs, myRoot, "3:9522278aa38d", "b9deb9a1c6f4", CheckoutRules.DEFAULT); + checkPatchResult(output.toByteArray()); + output = buildPatch(myVcs, myRoot, "9522278aa38d", "b9deb9a1c6f4", CheckoutRules.DEFAULT); + checkPatchResult(output.toByteArray()); + } + + + @Override + protected String getTestDataPath() { + return "mercurial-tests/testData"; + } + + private HgRepo createRepo(@NotNull File dir) throws IOException { + return new HgRepo(dir, Util.getHgPath(), new AuthSettings()); + } + +}
--- a/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Util.java Tue Jun 19 15:17:11 2012 +0400 +++ b/mercurial-tests/src/jetbrains/buildServer/buildTriggers/vcs/mercurial/Util.java Wed Jun 20 22:54:13 2012 +0400 @@ -6,11 +6,17 @@ import jetbrains.buildServer.util.EventDispatcher; import jetbrains.buildServer.util.FileUtil; import jetbrains.buildServer.util.cache.ResetCacheRegister; +import jetbrains.buildServer.vcs.CheckoutRules; +import jetbrains.buildServer.vcs.VcsException; import jetbrains.buildServer.vcs.VcsManager; +import jetbrains.buildServer.vcs.VcsRoot; +import jetbrains.buildServer.vcs.patches.PatchBuilderImpl; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jmock.Expectations; import org.jmock.Mockery; +import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.util.concurrent.Executors; @@ -66,4 +72,16 @@ if (new File(dst, "hg").isDirectory()) FileUtil.rename(new File(dst, "hg"), new File(dst, ".hg")); } + + public static ByteArrayOutputStream buildPatch(@NotNull MercurialVcsSupport vcs, + @NotNull VcsRoot vcsRoot, + @Nullable String from, + @NotNull String to, + @NotNull CheckoutRules rules) throws IOException, VcsException { + ByteArrayOutputStream output = new ByteArrayOutputStream(); + PatchBuilderImpl builder = new PatchBuilderImpl(output); + vcs.buildPatch(vcsRoot, from, to, builder, rules); + builder.close(); + return output; + } }
--- a/mercurial-tests/src/testng.xml Tue Jun 19 15:17:11 2012 +0400 +++ b/mercurial-tests/src/testng.xml Wed Jun 20 22:54:13 2012 +0400 @@ -24,6 +24,7 @@ <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.MercurialResetCacheHandlerTest"/> <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.AgentMirrorCleanerTest"/> <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.ListFilesSupportTest"/> + <class name="jetbrains.buildServer.buildTriggers.vcs.mercurial.RevisionFormatTest"/> </classes> </test> </suite>