Package org.tmatesoft.hg.repo

Examples of org.tmatesoft.hg.repo.HgLookup


  public void testPushToEmpty() throws Exception {
    File srcRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-push2empty-src", false);
    File dstRepoLoc = RepoUtils.initEmptyTempRepo("test-push2empty-dst");
    HgServer server = new HgServer().start(dstRepoLoc);
    try {
      final HgLookup hgLookup = new HgLookup();
      HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
      HgPushCommand cmd = new HgPushCommand(srcRepo);
      final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
      cmd.destination(dstRemote);
      cmd.execute();
      final HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
      checkRepositoriesAreSame(srcRepo, dstRepo);
      final List<Nodeid> outgoing = new HgOutgoingCommand(srcRepo).against(dstRemote).executeLite();
      errorCollector.assertTrue(outgoing.toString(), outgoing.isEmpty());
    } finally {
      server.stop();
View Full Code Here


    File dstRepoLoc = RepoUtils.cloneRepoToTempLocation("test-annotate", "test-push-dst", false);
    File f1 = new File(srcRepoLoc, "file1");
    assertTrue("[sanity]", f1.canWrite());
    HgServer server = new HgServer().start(dstRepoLoc);
    try {
      final HgLookup hgLookup = new HgLookup();
      final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
      final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
      RepoUtils.modifyFileAppend(f1, "change1");
      new HgCommitCommand(srcRepo).message("Commit 1").execute();
      new HgCheckoutCommand(srcRepo).changeset(7).clean(true).execute();
      assertEquals("[sanity]", "no-merge", srcRepo.getWorkingCopyBranchName());
      RepoUtils.modifyFileAppend(f1, "change2");
      new HgCommitCommand(srcRepo).message("Commit 2").execute();
      //
      new HgPushCommand(srcRepo).destination(dstRemote).execute();
      checkRepositoriesAreSame(srcRepo, hgLookup.detect(dstRepoLoc));
      final List<Nodeid> outgoing = new HgOutgoingCommand(srcRepo).against(dstRemote).executeLite();
      errorCollector.assertTrue(outgoing.toString(), outgoing.isEmpty());
    } finally {
      server.stop();
    }
View Full Code Here

    File dstRepoLoc = RepoUtils.initEmptyTempRepo("test-push-nopub-dst");
    File f1 = new File(srcRepoLoc, "hello.c");
    assertTrue("[sanity]", f1.canWrite());
    HgServer server = new HgServer().publishing(false).start(dstRepoLoc);
    try {
      final HgLookup hgLookup = new HgLookup();
      final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
      final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
      PhasesHelper phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
      final RevisionSet allDraft = phaseHelper.allDraft();
      assertFalse("[sanity]", allDraft.isEmpty());
      final int publicCsetToBranchAt = 4;
      assertEquals("[sanity]", HgPhase.Public, phaseHelper.getPhase(publicCsetToBranchAt, null));
      // in addition to existing draft csets, add one more draft, branching at some other public revision
      new HgCheckoutCommand(srcRepo).changeset(publicCsetToBranchAt).clean(true).execute();
      RepoUtils.modifyFileAppend(f1, "// aaa");
      final HgCommitCommand commitCmd = new HgCommitCommand(srcRepo).message("Commit aaa");
      assertTrue(commitCmd.execute().isOk());
      Nodeid newCommit = commitCmd.getCommittedRevision();
      //
      new HgPushCommand(srcRepo).destination(dstRemote).execute();
      HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
      final HgChangelog srcClog = srcRepo.getChangelog();
      final HgChangelog dstClog = dstRepo.getChangelog();
      // refresh PhasesHelper
      phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
      // check if phase didn't change
View Full Code Here

    // local: new draft from r4, push
    File srcRepoLoc = RepoUtils.copyRepoToTempLocation("test-phases", "test-push-phase-update-1-src");
    File dstRepoLoc = RepoUtils.copyRepoToTempLocation("test-phases", "test-push-phase-update-1-dst");
    File f1 = new File(srcRepoLoc, "hello.c");
    assertTrue("[sanity]", f1.canWrite());
    final HgLookup hgLookup = new HgLookup();
    final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
    final ExecHelper dstRun = new ExecHelper(new OutputParser.Stub(), dstRepoLoc);
    final int publicCsetToBranchAt = 4;
    final int r5 = 5, r6 = 6, r8 = 8;
    PhasesHelper srcPhase = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
    assertEquals("[sanity]", HgPhase.Draft, srcPhase.getPhase(r5, null));
    assertEquals("[sanity]", HgPhase.Secret, srcPhase.getPhase(r6, null));
    assertEquals("[sanity]", HgPhase.Draft, srcPhase.getPhase(r8, null));
    // change phases in repository of remote server:
    dstRun.exec("hg", "phase", "--public", String.valueOf(r5));
    assertEquals(0, dstRun.getExitValue());
    dstRun.exec("hg", "phase", "--draft", String.valueOf(r6));
    assertEquals(0, dstRun.getExitValue());
    dstRun.exec("hg", "phase", "--secret", "--force", String.valueOf(r8));
    assertEquals(0, dstRun.getExitValue());
    HgServer server = new HgServer().publishing(false).start(dstRepoLoc);
    try {
      final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
      // commit new draft head
      new HgCheckoutCommand(srcRepo).changeset(publicCsetToBranchAt).clean(true).execute();
      RepoUtils.modifyFileAppend(f1, "// aaa");
      final HgCommitCommand commitCmd = new HgCommitCommand(srcRepo).message("Commit aaa");
      assertTrue(commitCmd.execute().isOk());
      final Nodeid newCommit = commitCmd.getCommittedRevision();
      //
      new HgPushCommand(srcRepo).destination(dstRemote).execute();
      // refresh phase information
      srcPhase = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
      // r5 and r6 are changed to match server phases (more exposed)
      errorCollector.assertEquals(HgPhase.Public, srcPhase.getPhase(r5, null));
      errorCollector.assertEquals(HgPhase.Draft, srcPhase.getPhase(r6, null));
      // r8 is secret on server, locally can't make it less exposed though
      errorCollector.assertEquals(HgPhase.Draft, srcPhase.getPhase(r8, null));
      //
      HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
      final HgChangelog dstClog = dstRepo.getChangelog();
      assertTrue(dstClog.isKnown(newCommit));
      PhasesHelper dstPhase = new PhasesHelper(HgInternals.getImplementationRepo(dstRepo));
      errorCollector.assertEquals(HgPhase.Draft, dstPhase.getPhase(dstClog.getRevisionIndex(newCommit), newCommit));
      // the one that was secret is draft now
View Full Code Here

    File srcRepoLoc = RepoUtils.copyRepoToTempLocation("test-phases", "test-push-phase-update-2-src");
    File dstRepoLoc = RepoUtils.initEmptyTempRepo("test-push-phase-update-1-dst");
    final int r4 = 4, r5 = 5, r6 = 6, r9 = 9;
    HgServer server = new HgServer().publishing(false).start(dstRepoLoc);
    try {
      final HgLookup hgLookup = new HgLookup();
      final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
      final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
      new HgPushCommand(srcRepo).destination(dstRemote).execute();
      //
      // make sure pushed repository got same draft root
      final Nodeid r4PublicHead = srcRepo.getChangelog().getRevision(r4);
      final Nodeid r5DraftRoot = srcRepo.getChangelog().getRevision(r5);
      HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
      final HgChangelog dstClog = dstRepo.getChangelog();
      PhasesHelper dstPhase = new PhasesHelper(HgInternals.getImplementationRepo(dstRepo));
      assertEquals(HgPhase.Public, dstPhase.getPhase(dstClog.getRevisionIndex(r4PublicHead), r4PublicHead));
      assertEquals(HgPhase.Draft, dstPhase.getPhase(dstClog.getRevisionIndex(r5DraftRoot), r5DraftRoot));
      //
View Full Code Here

    // copy, not clone as latter updates phase information
    File srcRepoLoc = RepoUtils.copyRepoToTempLocation("test-phases", "test-push-pub-src");
    File dstRepoLoc = RepoUtils.initEmptyTempRepo("test-push-pub-dst");
    HgServer server = new HgServer().publishing(true).start(dstRepoLoc);
    try {
      final HgLookup hgLookup = new HgLookup();
      final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
      final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
      PhasesHelper phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
      final RevisionSet allDraft = phaseHelper.allDraft();
      assertFalse("[sanity]", allDraft.isEmpty());
      // push all changes
      new HgPushCommand(srcRepo).destination(dstRemote).execute();
      HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
      final HgChangelog srcClog = srcRepo.getChangelog();
      final HgChangelog dstClog = dstRepo.getChangelog();
      // refresh PhasesHelper
      phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
      for (Nodeid n : allDraft) {
View Full Code Here

    // copy, not clone as latter updates phase information
    File srcRepoLoc = RepoUtils.copyRepoToTempLocation("test-phases", "test-push-no-secret-src");
    File dstRepoLoc = RepoUtils.initEmptyTempRepo("test-push-no-secret-dst");
    HgServer server = new HgServer().start(dstRepoLoc);
    try {
      final HgLookup hgLookup = new HgLookup();
      final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
      final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
      PhasesHelper phaseHelper = new PhasesHelper(HgInternals.getImplementationRepo(srcRepo));
      final RevisionSet allSecret = phaseHelper.allSecret();
      assertFalse("[sanity]", allSecret.isEmpty());
      new HgPushCommand(srcRepo).destination(dstRemote).execute();
      HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
      final HgChangelog srcClog = srcRepo.getChangelog();
      final HgChangelog dstClog = dstRepo.getChangelog();
      errorCollector.assertEquals(srcClog.getRevisionCount() - allSecret.size(), dstClog.getRevisionCount());
      for (Nodeid n : allSecret) {   
        errorCollector.assertTrue(n.toString(), !dstClog.isKnown(n));
View Full Code Here

    // 5) bm5 - local bookmark, not known remotely
    srcRun.exec("hg", "bookmark", "-r", String.valueOf(bm_4_5), bm5);
    //
    HgServer server = new HgServer().start(dstRepoLoc);
    try {
      final HgLookup hgLookup = new HgLookup();
      final HgRepository srcRepo = hgLookup.detect(srcRepoLoc);
      final HgRemoteRepository dstRemote = hgLookup.detect(server.getURL());
      RepoUtils.modifyFileAppend(f1, "change1");
      final HgCommitCommand commitCmd = new HgCommitCommand(srcRepo).message("Commit 1");
      assertTrue(commitCmd.execute().isOk());
      assertEquals(bm1, srcRepo.getBookmarks().getActiveBookmarkName());
      assertEquals(commitCmd.getCommittedRevision(), srcRepo.getBookmarks().getRevision(bm1));
      //
      new HgPushCommand(srcRepo).destination(dstRemote).execute();
      Thread.sleep(300); // let the server perform the update
      //
      HgBookmarks srcBookmarks = srcRepo.getBookmarks();
      final HgChangelog srcClog = srcRepo.getChangelog();
      // first, check local bookmarks are intact
      errorCollector.assertEquals(srcClog.getRevision(bm2Local), srcBookmarks.getRevision(bm2));
      errorCollector.assertEquals(srcClog.getRevision(bm3Local), srcBookmarks.getRevision(bm3));
      errorCollector.assertEquals(null, srcBookmarks.getRevision(bm4));
      errorCollector.assertEquals(srcClog.getRevision(bm_4_5), srcBookmarks.getRevision(bm5));
      // now, check remote bookmarks were touched
      HgRepository dstRepo = hgLookup.detect(dstRepoLoc);
      HgBookmarks dstBookmarks = dstRepo.getBookmarks();
      final HgChangelog dstClog = dstRepo.getChangelog();
      // bm1 changed and points to newly pushed commit.
      // if the test fails (bm1 points to r8), chances are server didn't manage to update
      // bookmarks yet (there's Thread.sleep() above to give it a chance).
View Full Code Here

    new RepoInitializer().setRequires(requiresFlags).initEmptyRepository(repoDir);
    return getNewRepository();
  }
 
  public HgRepository getNewRepository() throws HgRepositoryNotFoundException {
    HgLookup l = hgLookup == null ? new HgLookup() : hgLookup;
    return l.detect(location);
  }
View Full Code Here

   *
   * @return <code>true</code> if found valid repository
   * @throws HgRepositoryNotFoundException if no repository found in working directory
   */
  public boolean init() throws HgRepositoryNotFoundException {
    repo = new HgLookup(context).detectFromWorkingDir();
    return repo != null && !repo.isInvalid();
  }
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.