Examples of HgRepository


Examples of org.tmatesoft.hg.repo.HgRepository

    File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit-bookmark-update", false);
    ExecHelper eh = new ExecHelper(new OutputParser.Stub(), repoLoc);
    String activeBookmark = "bm1";
    eh.run("hg", "bookmarks", activeBookmark);

    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    assertEquals("[sanity]", activeBookmark, hgRepo.getBookmarks().getActiveBookmarkName());
    Nodeid activeBookmarkRevision = hgRepo.getBookmarks().getRevision(activeBookmark);
    assertEquals("[sanity]", activeBookmarkRevision, hgRepo.getWorkingCopyParents().first());
   
    HgDataFile dfD = hgRepo.getFileNode("d");
    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", dfD.exists());
    assertTrue("[sanity]", fileD.canRead());

    RepoUtils.modifyFileAppend(fileD, " 1 \n");
    HgCommitCommand cmd = new HgCommitCommand(hgRepo).message("FIRST");
    Outcome r = cmd.execute();
    errorCollector.assertTrue(r.isOk());
    Nodeid c = cmd.getCommittedRevision();
   
    errorCollector.assertEquals(activeBookmark, hgRepo.getBookmarks().getActiveBookmarkName());
    errorCollector.assertEquals(c, hgRepo.getBookmarks().getRevision(activeBookmark));
    // reload repo, and repeat the check
    hgRepo = new HgLookup().detect(repoLoc);
    errorCollector.assertEquals(activeBookmark, hgRepo.getBookmarks().getActiveBookmarkName());
    errorCollector.assertEquals(c, hgRepo.getBookmarks().getRevision(activeBookmark));
  }
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

   * Synopsis: commit 1 (c1), hg bookmark active (points to commit1), make commit 2, hg bookmark -f -r c1 active, commit 3, check active still points to c1
   */
  @Test
  public void testNoBookmarkUpdate() throws Exception {
    File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-no-bookmark-upd", false);
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    assertNull("[sanity]", hgRepo.getBookmarks().getActiveBookmarkName());
    ExecHelper eh = new ExecHelper(new OutputParser.Stub(), repoLoc);
    String activeBookmark = "bm1";
    eh.run("hg", "bookmarks", activeBookmark);
    assertEquals("Bookmarks has to reload", activeBookmark, hgRepo.getBookmarks().getActiveBookmarkName());
    Nodeid initialBookmarkRevision = hgRepo.getBookmarks().getRevision(activeBookmark); // c1
    assertEquals("[sanity]", initialBookmarkRevision, hgRepo.getWorkingCopyParents().first());

    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", fileD.canRead());
    RepoUtils.modifyFileAppend(fileD, " 1 \n");
    HgCommitCommand cmd = new HgCommitCommand(hgRepo).message("FIRST");
    Outcome r = cmd.execute();
    errorCollector.assertTrue(r.isOk());
    Nodeid c2 = cmd.getCommittedRevision();
    errorCollector.assertEquals(c2, hgRepo.getBookmarks().getRevision(activeBookmark));
    //
    if (!Internals.runningOnWindows()) {
      // need change to happen not the same moment as the last commit (and read of bookmark file)
      Thread.sleep(1000); // XXX remove once better file change detection in place
    }
    eh.run("hg", "bookmark", activeBookmark, "--force", "--rev", initialBookmarkRevision.toString());
    //
    RepoUtils.modifyFileAppend(fileD, " 2 \n");
    cmd = new HgCommitCommand(hgRepo).message("SECOND");
    r = cmd.execute();
    errorCollector.assertTrue(r.isOk());
    //Nodeid c3 = cmd.getCommittedRevision();
    errorCollector.assertEquals(initialBookmarkRevision, hgRepo.getBookmarks().getRevision(activeBookmark));
  }
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

  @Test
  public void testRefreshTagsAndBranches() throws Exception {
    File repoLoc = RepoUtils.cloneRepoToTempLocation("log-branches", "test-refresh-after-commit", false);
    final String tag = "tag.refresh", branch = "branch-refresh";
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    assertFalse(hgRepo.getTags().getAllTags().containsKey(tag));
    assertNull(hgRepo.getBranches().getBranch(branch));
    RepoUtils.modifyFileAppend(new File(repoLoc, "a"), "whatever");
    //
    final int parentCsetRevIndex = hgRepo.getChangelog().getLastRevision();
    // HgCommitCommand can't do branch yet
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), parentCsetRevIndex);
    cf.add(hgRepo.getFileNode("a"), new FileContentSupplier(hgRepo, new File(repoLoc, "a")));
    cf.branch(branch);
    Transaction tr = newTransaction(hgRepo);
    Nodeid commit = cf.commit("FIRST",  tr);
    tr.commit();
    errorCollector.assertEquals("commit with branch shall update WC", branch, hgRepo.getWorkingCopyBranchName());
   
    ExecHelper eh = new ExecHelper(new OutputParser.Stub(), repoLoc);
    eh.run("hg", "tag", tag);
    assertEquals("[sanity]", 0, eh.getExitValue());
   
    errorCollector.assertTrue(hgRepo.getTags().getAllTags().containsKey(tag));
    errorCollector.assertFalse(hgRepo.getBranches().getBranch(branch) == null);
    errorCollector.assertTrue(hgRepo.getTags().tagged(tag).contains(commit));
    errorCollector.assertTrue(hgRepo.getTags().tags(commit).contains(tag));
  }
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

  public void testAddedFilesGetStream() throws Exception {
    File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit-addfile-stream", false);
    final File newFile = new File(repoLoc, "xx");
    final byte[] newFileContent = "xyz".getBytes();
    RepoUtils.createFile(newFile, newFileContent);
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    new HgAddRemoveCommand(hgRepo).add(Path.create("xx")).execute();
    // save the reference to HgDataFile without valid RevlogStream (entry in the dirstate
    // doesn't make it valid)
    final HgDataFile newFileNode = hgRepo.getFileNode("xx");
    assertFalse(newFileNode.exists());
    HgCommitCommand cmd = new HgCommitCommand(hgRepo).message("FIRST");
    Outcome r = cmd.execute();
    errorCollector.assertTrue(r.isOk());
    TestStatus.StatusCollector status = new TestStatus.StatusCollector();
    new HgStatusCommand(hgRepo).all().execute(status);
    errorCollector.assertTrue(status.getErrors().isEmpty());
    errorCollector.assertTrue(status.get(Kind.Added).isEmpty());
    errorCollector.assertTrue(status.get(newFileNode.getPath()).contains(Kind.Clean));
    //
    errorCollector.assertTrue(newFileNode.exists());
    final ByteArrayChannel read1 = new ByteArrayChannel();
    newFileNode.content(0, read1);
    errorCollector.assertEquals("Read from existing HgDataFile instance", newFileContent, read1.toArray());
    final ByteArrayChannel read2 = new ByteArrayChannel();
    hgRepo.getFileNode(newFileNode.getPath()).content(0, read2);
    errorCollector.assertEquals("Read from fresh HgDataFile instance", newFileContent, read2.toArray());
  }
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

    // approach shall be abandoned.
    File repoLoc = RepoUtils.copyRepoToTempLocation("log-1", "test-commit-rollback");
    final Path newFilePath = Path.create("xx");
    final File newFile = new File(repoLoc, newFilePath.toString());
    RepoUtils.createFile(newFile, "xyz");
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    HgDataFile dfB = hgRepo.getFileNode("b");
    HgDataFile dfD = hgRepo.getFileNode("d");
    assertTrue("[sanity]", dfB.exists());
    assertTrue("[sanity]", dfD.exists());
    final File modifiedFile = new File(repoLoc, "b");
    RepoUtils.modifyFileAppend(modifiedFile, " 1 \n");
    //
    new HgAddRemoveCommand(hgRepo).add(newFilePath).remove(dfD.getPath()).execute();
    //
    TestStatus.StatusCollector status = new TestStatus.StatusCollector();
    new HgStatusCommand(hgRepo).all().execute(status);
    assertTrue(status.getErrors().isEmpty());
    assertTrue(status.get(Kind.Added).contains(newFilePath));
    assertTrue(status.get(Kind.Modified).contains(dfB.getPath()));
    assertTrue(status.get(Kind.Removed).contains(dfD.getPath()));
    assertEquals(DEFAULT_BRANCH_NAME, hgRepo.getWorkingCopyBranchName());
    //
    final int lastClogRevision = hgRepo.getChangelog().getLastRevision();
    final int lastManifestRev = hgRepo.getManifest().getLastRevision();
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), lastClogRevision);
    cf.add(hgRepo.getFileNode("xx"), new FileContentSupplier(hgRepo, newFile));
    cf.add(dfB, new FileContentSupplier(hgRepo, modifiedFile));
    cf.forget(dfD);
    cf.branch("another-branch");
    Transaction tr = newTransaction(hgRepo);
    Nodeid commitRev = cf.commit("Commit to fail",  tr);
    tr.rollback();
    //
    errorCollector.assertEquals(lastClogRevision, hgRepo.getChangelog().getLastRevision());
    errorCollector.assertEquals(lastManifestRev, hgRepo.getManifest().getLastRevision());
    errorCollector.assertEquals(DEFAULT_BRANCH_NAME, DirstateReader.readBranch(Internals.getInstance(hgRepo)));
    errorCollector.assertFalse(hgRepo.getChangelog().isKnown(commitRev));
    errorCollector.assertFalse(hgRepo.getFileNode("xx").exists());
    // check dirstate
    status = new TestStatus.StatusCollector();
    new HgStatusCommand(hgRepo).all().execute(status);
    errorCollector.assertTrue(status.getErrors().isEmpty());
    errorCollector.assertTrue(status.get(Kind.Added).contains(newFilePath));
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

  @Rule
  public ErrorCollectorExt errorCollector = new ErrorCollectorExt();

  @Test
  public void testParentChildMap() throws HgException {
    final HgRepository repo = Configuration.get().find("test-annotate");
    Nodeid[] allRevs = RepoUtils.allRevisions(repo);
    HgParentChildMap<HgChangelog> parentHelper = new HgParentChildMap<HgChangelog>(repo.getChangelog());
    parentHelper.init();
    errorCollector.assertEquals(Arrays.asList(allRevs), parentHelper.all());
    for (Nodeid n : allRevs) {
      errorCollector.assertTrue(parentHelper.knownNode(n));
      // parents
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

  }

  @Test
  public void testRevisionMap() throws HgException {
    // XXX this test may benefit from external huge repository
    final HgRepository repo = Configuration.get().find("test-annotate");
    Nodeid[] allRevs = RepoUtils.allRevisions(repo);
    final HgChangelog clog = repo.getChangelog();
    final HgRevisionMap<HgChangelog> rmap = new HgRevisionMap<HgChangelog>(clog).init();
    doTestRevisionMap(allRevs, rmap);
  }
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

    doTestRevisionMap(allRevs, rmap);
  }

  @Test
  public void testRevisionMapFromParentChildMap() throws HgException {
    final HgRepository repo = Configuration.get().find("test-annotate");
    Nodeid[] allRevs = RepoUtils.allRevisions(repo);
    HgParentChildMap<HgChangelog> parentHelper = new HgParentChildMap<HgChangelog>(repo.getChangelog());
    parentHelper.init();
    doTestRevisionMap(allRevs, parentHelper.getRevisionMap());
  }
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

    File dstRepoLoc = RepoUtils.initEmptyTempRepo("test-pull2empty-dst");
    HgServer server = new HgServer().start(srcRepoLoc);
    try {
      final HgLookup hgLookup = new HgLookup();
      final HgRemoteRepository srcRemote = hgLookup.detect(server.getURL());
      final HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
      HgPullCommand cmd = new HgPullCommand(dstRepo).source(srcRemote);
      cmd.execute();
      final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
      checkRepositoriesAreSame(srcRepo, dstRepo);
      final List<Nodeid> incoming = new HgIncomingCommand(dstRepo).against(srcRemote).executeLite();
      errorCollector.assertTrue(incoming.toString(), incoming.isEmpty());
      RepoUtils.assertHgVerifyOk(errorCollector, dstRepoLoc);
    } finally {
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

    File f1 = new File(srcRepoLoc, "file1");
    assertTrue("[sanity]", f1.canWrite());
    final HgLookup hgLookup = new HgLookup();
    // add two commits, one with new file at different branch
    // commit 1
    final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
    assertEquals("[sanity]", "default", srcRepo.getWorkingCopyBranchName());
    RepoUtils.modifyFileAppend(f1, "change1");
    HgCommitCommand commitCmd = new HgCommitCommand(srcRepo).message("Commit 1");
    assertTrue(commitCmd.execute().isOk());
    final Nodeid cmt1 = commitCmd.getCommittedRevision();
    // commit 2
    new HgCheckoutCommand(srcRepo).changeset(7).clean(true).execute();
    assertEquals("[sanity]", "no-merge", srcRepo.getWorkingCopyBranchName());
    RepoUtils.createFile(new File(srcRepoLoc, "file-new"), "whatever");
    new HgAddRemoveCommand(srcRepo).add(Path.create("file-new")).execute();
    commitCmd = new HgCommitCommand(srcRepo).message("Commit 2");
    assertTrue(commitCmd.execute().isOk());
    final Nodeid cmt2 = commitCmd.getCommittedRevision();
    //
    // pull
    HgServer server = new HgServer().start(srcRepoLoc);
    final HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
    try {
      final HgRemoteRepository srcRemote = hgLookup.detect(server.getURL());
      new HgPullCommand(dstRepo).source(srcRemote).execute();
    } finally {
      server.stop();
    }
    //
    errorCollector.assertTrue(dstRepo.getChangelog().isKnown(cmt1));
    errorCollector.assertTrue(dstRepo.getChangelog().isKnown(cmt2));
    checkRepositoriesAreSame(srcRepo, dstRepo);
    RepoUtils.assertHgVerifyOk(errorCollector, dstRepoLoc);
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.