Package org.tmatesoft.hg.core

Examples of org.tmatesoft.hg.core.HgStatusCommand$Mediator


    if (!hgRepo.init(cmdLineOpts.findRepository())) {
      System.err.printf("Can't find repository in: %s\n", hgRepo.getRepository().getLocation());
      return;
    }
    //
    HgStatusCommand cmd = hgRepo.createStatusCommand();
    if (cmdLineOpts.getBoolean("-A", "--all")) {
      cmd.all();
    } else {
      // default: mardu
      cmd.modified(cmdLineOpts.getBoolean(true, "-m", "--modified"));
      cmd.added(cmdLineOpts.getBoolean(true, "-a", "--added"));
      cmd.removed(cmdLineOpts.getBoolean(true, "-r", "--removed"));
      cmd.deleted(cmdLineOpts.getBoolean(true, "-d", "--deleted"));
      cmd.unknown(cmdLineOpts.getBoolean(true, "-u", "--unknonwn"));
      cmd.clean(cmdLineOpts.getBoolean("-c", "--clean"));
      cmd.ignored(cmdLineOpts.getBoolean("-i", "--ignored"));
    }
//    cmd.subrepo(cmdLineOpts.getBoolean("-S", "--subrepos"))
    final boolean noStatusPrefix = cmdLineOpts.getBoolean("-n", "--no-status");
    final boolean showCopies = cmdLineOpts.getBoolean("-C", "--copies");
    class StatusHandler implements HgStatusHandler {
     
      final EnumMap<HgStatus.Kind, List<Path>> data = new EnumMap<HgStatus.Kind, List<Path>>(HgStatus.Kind.class);
      final Map<Path, Path> copies = showCopies ? new HashMap<Path,Path>() : null;
     
      public void status(HgStatus s) {
        List<Path> l = data.get(s.getKind());
        if (l == null) {
          l = new LinkedList<Path>();
          data.put(s.getKind(), l);
        }
        l.add(s.getPath());
        if (s.isCopy() && showCopies) {
          copies.put(s.getPath(), s.getOriginalPath());
        }
      }
     
      public void error(Path file, Outcome s) {
        System.out.printf("FAILURE: %s %s\n", s.getMessage(), file);
        s.getException().printStackTrace(System.out);
      }
     
      public void dump() {
        sortAndPrint('M', data.get(Kind.Modified), null);
        sortAndPrint('A', data.get(Kind.Added), copies);
        sortAndPrint('R', data.get(Kind.Removed), null);
        sortAndPrint('?', data.get(Kind.Unknown), null);
        sortAndPrint('I', data.get(Kind.Ignored), null);
        sortAndPrint('C', data.get(Kind.Clean), null);
        sortAndPrint('!', data.get(Kind.Missing), null);
      }

      private void sortAndPrint(char prefix, List<Path> ul, Map<Path, Path> copies) {
        if (ul == null) {
          return;
        }
        ArrayList<Path> sortList = new ArrayList<Path>(ul);
        Collections.sort(sortList);
        for (Path s : sortList)  {
          if (!noStatusPrefix) {
            System.out.print(prefix);
            System.out.print(' ');
          }
          System.out.println(s);
          if (copies != null && copies.containsKey(s)) {
            System.out.println("  " + copies.get(s));
          }
        }
      }
    };

    StatusHandler statusHandler = new StatusHandler();
    int changeRev = cmdLineOpts.getSingleInt(BAD_REVISION, "--change");
    if (changeRev != BAD_REVISION) {
      cmd.change(changeRev);
    } else {
      List<String> revisions = cmdLineOpts.getList("--rev");
      int size = revisions.size();
      if (size > 1) {
        cmd.base(Integer.parseInt(revisions.get(size - 2))).revision(Integer.parseInt(revisions.get(size - 1)));
      } else if (size > 0) {
        cmd.base(Integer.parseInt(revisions.get(0)));
      }
    }
    cmd.execute(statusHandler);
    statusHandler.dump();
  }
View Full Code Here


    errorCollector.assertTrue(r.isOk());
    Nodeid c1 = cmd.getCommittedRevision();
   
    // check that modified files are no longer reported as such
    TestStatus.StatusCollector status = new TestStatus.StatusCollector();
    new HgStatusCommand(hgRepo).all().execute(status);
    errorCollector.assertTrue(status.getErrors().isEmpty());
    errorCollector.assertTrue(status.get(Kind.Modified).isEmpty());
    errorCollector.assertEquals(1, status.get(dfB.getPath()).size());
    errorCollector.assertTrue(status.get(dfB.getPath()).contains(Kind.Clean));
   
View Full Code Here

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

    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));
    errorCollector.assertTrue(status.get(Kind.Modified).contains(dfB.getPath()));
    errorCollector.assertTrue(status.get(Kind.Removed).contains(dfD.getPath()));
   
View Full Code Here

  public void testStatusCommand() throws Exception {
    repo = Configuration.get().find("status-subrepo");
    statusParser = new StatusOutputParser();
    eh = new ExecHelper(statusParser, repo.getWorkingDir());
    TestStatus.StatusReporter sr = new TestStatus.StatusReporter(errorCollector, statusParser);
    HgStatusCommand cmd = new HgStatusCommand(repo).all();
    TestStatus.StatusCollector sc;

    eh.run("hg", "status", "-A", "-S");
    cmd.subrepo(true);
    cmd.execute(sc = new TestStatus.StatusCollector());
    sr.report("status -A -S", sc);
   
    eh.run("hg", "status", "-A", "-S");
    cmd.subrepo(false);
    cmd.execute(sc = new TestStatus.StatusCollector());
    sr.report("status -A", sc);
   
  }
View Full Code Here

        errorCollector.fail("There's no conflict in changesets 1 and 2 merge");
      }
    });
    RepoUtils.assertHgVerifyOk(errorCollector, repoLoc1);
    TestStatus.StatusCollector status = new TestStatus.StatusCollector();
    new HgStatusCommand(repo).all().execute(status);
    final List<Path> clean = status.get(Kind.Clean);
    final List<Path> modified = status.get(Kind.Modified);
    Collections.sort(clean);
    Collections.sort(modified);
    errorCollector.assertEquals(new Path[] {create("file1"), create("file3"), create("file4")}, clean.toArray());
    errorCollector.assertEquals(new Path[] {create("file2"), create("file5")}, modified.toArray());
    repo = new HgLookup().detect(repoLoc2);
    cmd = new HgMergeCommand(repo);
    cmd.changeset(3).execute(new HgMergeCommand.MediatorBase());
    RepoUtils.assertHgVerifyOk(errorCollector, repoLoc2);
    new HgStatusCommand(repo).all().execute(status = new TestStatus.StatusCollector());
    errorCollector.assertEquals(1, status.get(Kind.Modified).size());
    errorCollector.assertEquals(create("file1"), status.get(Kind.Modified).get(0));
    final HgMergeState ms = repo.getMergeState();
    ms.refresh();
    errorCollector.assertTrue(ms.isMerging());
View Full Code Here

    sr.report("status -A --rev " + revision, r);
  }

  @Test
  public void testStatusCommand() throws Exception {
    final HgStatusCommand sc = new HgStatusCommand(repo).all();
    StatusCollector r;
    statusParser.reset();
    eh.run("hg", "status", "-A");
    sc.execute(r = new StatusCollector());
    sr.report("hg status -A", r);
    //
    statusParser.reset();
    int revision = 3;
    eh.run("hg", "status", "-A", "--rev", String.valueOf(revision));
    sc.base(revision).execute(r = new StatusCollector());
    sr.report("status -A --rev " + revision, r);
    //
    statusParser.reset();
    eh.run("hg", "status", "-A", "--change", String.valueOf(revision));
    sc.base(TIP).revision(revision).execute(r = new StatusCollector());
    sr.report("status -A --change " + revision, r);

    // TODO check not -A, but defaults()/custom set of modifications
  }
View Full Code Here

   */
  @Test
  public void testRemovedAgainstBaseWithoutIt() throws Exception {
    // check very end of WCStatusCollector, foreach left knownEntry, collect == null || baseRevFiles.contains()
    repo = Configuration.get().find("status-1");
    HgStatusCommand cmd = new HgStatusCommand(repo);
    StatusCollector sc = new StatusCollector();
    cmd.all().base(7).execute(sc);
    assertTrue(sc.getErrors().isEmpty());
    Path file5 = Path.create("dir/file5");
    // shall not be listed at all
    assertTrue(sc.get(file5).isEmpty());
  }
View Full Code Here

   * Shall be reported as modified.
   */
  @Test
  public void testTrackedModifiedIgnored() throws Exception {
    repo = Configuration.get().find("status-1");
    HgStatusCommand cmd = new HgStatusCommand(repo);
    StatusCollector sc = new StatusCollector();
    cmd.all().execute(sc);
    assertTrue(sc.getErrors().isEmpty());
    final Path file2 = Path.create("file2");
    assertTrue(sc.get(file2).contains(Modified));
    assertTrue(sc.get(file2).size() == 1);
  }
View Full Code Here

   * (despite both rev 3 and WC's parent has file4, there are different paths in the code for wc against parent and wc against rev)
   */
  @Test
  public void testMarkedRemovedButStillInWC() throws Exception {
    repo = Configuration.get().find("status-1");
    HgStatusCommand cmd = new HgStatusCommand(repo);
    StatusCollector sc = new StatusCollector();
    cmd.all().execute(sc);
    assertTrue(sc.getErrors().isEmpty());
    Path file4 = Path.create("dir/file4");
    assertTrue(sc.get(file4).contains(Removed));
    assertTrue(sc.get(file4).size() == 1);
    //
    // different code path (collect != null)
    cmd.base(3).execute(sc = new StatusCollector());
    assertTrue(sc.getErrors().isEmpty());
    assertTrue(sc.get(file4).contains(Removed));
    assertTrue(sc.get(file4).size() == 1);
    //
    // wasn't there in rev 2, shall not be reported at all
    cmd.base(2).execute(sc = new StatusCollector());
    assertTrue(sc.getErrors().isEmpty());
    assertTrue(sc.get(file4).isEmpty());
  }
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.core.HgStatusCommand$Mediator

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.