Package org.tmatesoft.hg.repo

Examples of org.tmatesoft.hg.repo.HgLookup


   * perform few commits one by one, into different branches
   */
  @Test
  public void testSequentialCommits() throws Exception {
    File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-sequential-commits", false);
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    HgDataFile dfD = hgRepo.getFileNode("d");
    assertTrue("[sanity]", dfD.exists());
    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", fileD.canRead());
    //
View Full Code Here


  @Test
  public void testCommandBasics() throws Exception {
    File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit-cmd", false);
    // PhasesHelper relies on file existence to tell phase enablement
    RepoUtils.createFile(new File(repoLoc, HgRepositoryFiles.Phaseroots.getPath()), "");
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    HgDataFile dfB = hgRepo.getFileNode("b");
    assertTrue("[sanity]", dfB.exists());
    File fileB = new File(repoLoc, "b");
    assertTrue("[sanity]", fileB.canRead());
    RepoUtils.modifyFileAppend(fileB, " 1 \n");
View Full Code Here

    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

   * 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());
View Full Code Here

  @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();
View Full Code Here

  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());
View Full Code Here

    // 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");
View Full Code Here

  public void testPullToEmpty() throws Exception {
    File srcRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-pull2empty-src", false);
    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

    File srcRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-pull-src", false);
    File dstRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-pull-dst", false);
    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();
    }
    //
View Full Code Here

    // copy, not clone as latter updates phase information
    File srcRepoLoc = RepoUtils.copyRepoToTempLocation("test-phases", "test-pull-pub-src");
    File dstRepoLoc = RepoUtils.copyRepoToTempLocation("test-phases", "test-pull-pub-dst");
    File f1 = new File(dstRepoLoc, "hello.c");
    assertTrue("[sanity]", f1.canWrite());
    final HgLookup hgLookup = new HgLookup();
    HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
    PhasesHelper phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(dstRepo));
    //
    // new child revision for shared public parent
    assertEquals(HgPhase.Public, phaseHelper.getPhase(4, null));
    new HgCheckoutCommand(dstRepo).changeset(4).clean(true).execute();
    RepoUtils.modifyFileAppend(f1, "// aaa");
    HgCommitCommand commitCmd = new HgCommitCommand(dstRepo).message("Commit 1");
    assertTrue(commitCmd.execute().isOk());
    final Nodeid cmt1 = commitCmd.getCommittedRevision();
    //
    // new child rev for parent locally draft, remotely public
    assertEquals(HgPhase.Draft, phaseHelper.getPhase(5, null));
    assertEquals(HgPhase.Draft, phaseHelper.getPhase(7, null));
    assertEquals(HgPhase.Draft, phaseHelper.getPhase(8, null));
    new HgCheckoutCommand(dstRepo).changeset(8).clean(true).execute();
    RepoUtils.modifyFileAppend(f1, "// bbb");
    commitCmd = new HgCommitCommand(dstRepo).message("Commit 2");
    assertTrue(commitCmd.execute().isOk());
    final Nodeid cmt2 = commitCmd.getCommittedRevision();
    // both new revisions shall be draft
    phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(dstRepo)); // refresh PhasesHelper
    assertEquals(HgPhase.Draft, phaseHelper.getPhase(dstRepo.getChangelog().getRevisionIndex(cmt1), cmt1));
    assertEquals(HgPhase.Draft, phaseHelper.getPhase(dstRepo.getChangelog().getRevisionIndex(cmt2), cmt2));
    //

    HgServer server = new HgServer().publishing(true).start(srcRepoLoc);
    try {
      final HgRemoteRepository srcRemote = hgLookup.detect(server.getURL());
      new HgPullCommand(dstRepo).source(srcRemote).execute();
    } finally {
      server.stop();
    }
    // refresh PhasesHelper
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.repo.HgLookup

Copyright © 2018 www.massapicom. 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.