Package org.tmatesoft.hg.internal

Examples of org.tmatesoft.hg.internal.CommitFacility


    File repoLoc = RepoUtils.initEmptyTempRepo("test-commit2non-empty");
    RepoUtils.createFile(new File(repoLoc, "file1"), "hello\n");
    new ExecHelper(new OutputParser.Stub(), repoLoc).run("hg", "commit", "--addremove", "-m", "FIRST");
    //
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), 0);
    HgDataFile df = hgRepo.getFileNode("file1");
    cf.add(df, new ByteArrayDataSource("hello\nworld".getBytes()));
    Transaction tr = newTransaction(hgRepo);
    Nodeid secondRev = cf.commit("SECOND", tr);
    tr.commit();
    //
    List<HgChangeset> commits = new HgLogCommand(hgRepo).execute();
    errorCollector.assertEquals(2, commits.size());
    HgChangeset c1 = commits.get(0);
View Full Code Here


    RepoUtils.createFile(new File(repoLoc, fname), null);
    new ExecHelper(new OutputParser.Stub(), repoLoc).run("hg", "add", fname);
    //
    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    assertEquals("[sanity]", 0, new HgLogCommand(hgRepo).execute().size());
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), NO_REVISION);
    HgDataFile df = hgRepo.getFileNode(fname);
    final byte[] initialContent = "hello\nworld".getBytes();
    cf.add(df, new ByteArrayDataSource(initialContent));
    String comment = "commit 1";
    Transaction tr = newTransaction(hgRepo);
    Nodeid c1Rev = cf.commit(comment,  tr);
    tr.commit();
    List<HgChangeset> commits = new HgLogCommand(hgRepo).execute();
    errorCollector.assertEquals(1, commits.size());
    HgChangeset c1 = commits.get(0);
    errorCollector.assertEquals(1, c1.getAffectedFiles().size());
View Full Code Here

    HgChangeset parentCset = new HgLogCommand(hgRepo).range(parentCsetRevIndex, parentCsetRevIndex).execute().get(0);
    assertEquals("[sanity]", DEFAULT_BRANCH_NAME, parentCset.getBranch());
    assertEquals("[sanity]", DEFAULT_BRANCH_NAME, hgRepo.getWorkingCopyBranchName());
    //
    RepoUtils.modifyFileAppend(fileD, "A CHANGE\n");
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), parentCsetRevIndex);
    FileContentSupplier contentProvider = new FileContentSupplier(hgRepo, fileD);
    cf.add(dfD, contentProvider);
    cf.branch("branch1");
    Transaction tr = newTransaction(hgRepo);
    Nodeid commitRev1 = cf.commit("FIRST",  tr);
    tr.commit();
    //
    List<HgChangeset> commits = new HgLogCommand(hgRepo).range(parentCsetRevIndex+1, TIP).execute();
    assertEquals(1, commits.size());
    HgChangeset c1 = commits.get(0);
View Full Code Here

    HgRepository hgRepo = new HgLookup().detect(repoLoc);
    assertTrue("[sanity]", hgRepo.getFileNode("d").exists());
    assertTrue("[sanity]", new File(repoLoc, "d").canRead());
    RepoUtils.createFile(new File(repoLoc, "xx"), "xyz");
    new HgAddRemoveCommand(hgRepo).add(Path.create("xx")).remove(Path.create("d")).execute();
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), hgRepo.getChangelog().getLastRevision());
    FileContentSupplier contentProvider = new FileContentSupplier(hgRepo, new File(repoLoc, "xx"));
    cf.add(hgRepo.getFileNode("xx"), contentProvider);
    cf.forget(hgRepo.getFileNode("d"));
    Transaction tr = newTransaction(hgRepo);
    Nodeid commitRev = cf.commit("Commit with add/remove cmd",  tr);
    tr.commit();
    //
    List<HgChangeset> commits = new HgLogCommand(hgRepo).changeset(commitRev).execute();
    HgChangeset cmt = commits.get(0);
    errorCollector.assertEquals(1, cmt.getAddedFiles().size());
View Full Code Here

    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", fileD.canRead());
    //
    RepoUtils.modifyFileAppend(fileD, " 1 \n");
    final int parentCsetRevIndex = hgRepo.getChangelog().getLastRevision();
    CommitFacility cf = new CommitFacility(Internals.getInstance(hgRepo), parentCsetRevIndex);
    FileContentSupplier contentProvider = new FileContentSupplier(hgRepo, fileD);
    cf.add(dfD, contentProvider);
    cf.branch("branch1");
    Transaction tr = newTransaction(hgRepo);
    Nodeid commitRev1 = cf.commit("FIRST",  tr);
    //
    RepoUtils.modifyFileAppend(fileD, " 2 \n");
    cf.add(dfD, contentProvider = new FileContentSupplier(hgRepo, fileD));
    cf.branch("branch2");
    Nodeid commitRev2 = cf.commit("SECOND",  tr);
    //
    RepoUtils.modifyFileAppend(fileD, " 2 \n");
    cf.add(dfD, contentProvider = new FileContentSupplier(hgRepo, fileD));
    cf.branch(DEFAULT_BRANCH_NAME);
    Nodeid commitRev3 = cf.commit("THIRD",  tr);
    tr.commit();
    //
    List<HgChangeset> commits = new HgLogCommand(hgRepo).range(parentCsetRevIndex+1, TIP).execute();
    assertEquals(3, commits.size());
    HgChangeset c1 = commits.get(0);
View Full Code Here

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

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

      if (status.getModified().size() == 0 && status.getAdded().size() == 0 && status.getRemoved().size() == 0) {
        newRevision = Nodeid.NULL;
        return new Outcome(Kind.Failure, "nothing to add");
      }
      final Internals implRepo = Internals.getInstance(repo);
      CommitFacility cf = new CommitFacility(implRepo, parentRevs[0], parentRevs[1]);
      for (Path m : status.getModified()) {
        HgDataFile df = repo.getFileNode(m);
        cf.add(df, new WorkingCopyContent(df));
      }
      for (Path a : status.getAdded()) {
        HgDataFile df = repo.getFileNode(a); // TODO need smth explicit, like repo.createNewFileNode(Path) here
        // XXX might be an interesting exercise not to demand a content supplier, but instead return a "DataRequester"
        // object, that would indicate interest in data, and this code would "push" it to requester, so that any exception
        // is handled here, right away, and won't need to travel supplier and CommitFacility. (although try/catch inside
        // supplier.read (with empty throws declaration)
        cf.add(df, new FileContentSupplier(repo, a));
      }
      for (Path r : status.getRemoved()) {
        HgDataFile df = repo.getFileNode(r);
        cf.forget(df);
      }
      cf.branch(detectBranch());
      cf.user(detectUser());
      Transaction.Factory trFactory = implRepo.getTransactionFactory();
      Transaction tr = trFactory.create(repo);
      try {
        newRevision = cf.commit(message, tr);
        tr.commit();
      } catch (RuntimeException ex) {
        tr.rollback();
        throw ex;
      } catch (HgException ex) {
View Full Code Here

TOP

Related Classes of org.tmatesoft.hg.internal.CommitFacility

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.