Examples of HgRepository


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

    } else {
      errorCollector.assertTrue(!l.isCommitted());
      errorCollector.assertTrue(l.getRevision() == null);
    }
    errorCollector.assertEquals(topRepo, l.getOwner());
    HgRepository r = l.getRepo();
    String expectedSubRepoLoc = new File(topRepo.getLocation(), expectedLocation.toString()).toString();
    errorCollector.assertEquals(expectedSubRepoLoc, r.getLocation());
    errorCollector.assertTrue(r.getChangelog().getRevisionCount() > 0);
    if (isCommitted) {
      errorCollector.assertEquals(r.getChangelog().getRevision(TIP), l.getRevision());
    }
  }
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

    String ext2_key = "ext.disabled"; // disabled
    String ext3_key = "hgext.two"; // check if found by "two" key
    String hgrcContent = String.format("#comment\n[ui]\nusername = %s\n\n[paths]\n%s = %s\ndefault=%3$s\n\n[extensions]\n%s = \n%s = !\n%s=\n", username, path1_key, path1_value, ext1_key, ext2_key, ext3_key);
    RepoUtils.createFile(hgrc, hgrcContent);
    //
    HgRepository repo = new HgLookup().detect(repoLoc);
    final HgRepoConfig cfg = repo.getConfiguration();
    assertNotNull(cfg.getPaths());
    assertNotNull(cfg.getExtensions());
    final Section dne = cfg.getSection("does-not-exist");
    assertNotNull(dne);
    assertFalse(dne.exists());
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

  public void testCommitToNonEmpty() throws Exception {
    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();
    //
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

    File repoLoc = RepoUtils.initEmptyTempRepo("test-commit2empty");
    String fname = "file1";
    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);
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

  }
 
  @Test
  public void testCommitIntoBranch() throws Exception {
    File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-commit2branch", 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());
    final int parentCsetRevIndex = hgRepo.getChangelog().getLastRevision();
    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);
    errorCollector.assertEquals(c1.getNodeid(), commitRev1);
    errorCollector.assertEquals("branch1", c1.getBranch());
    errorCollector.assertEquals("FIRST", c1.getComment());
    //
    // check if cached value in hgRepo got updated
    errorCollector.assertEquals("branch1", hgRepo.getWorkingCopyBranchName());
    //
    RepoUtils.assertHgVerifyOk(errorCollector, repoLoc);
  }
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

   * use own add and remove commands and then commit
   */
  @Test
  public void testCommitWithAddRemove() throws Exception {
    File repoLoc = RepoUtils.cloneRepoToTempLocation("log-1", "test-add-remove-commit", false);
    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();
View Full Code Here

Examples of org.tmatesoft.hg.repo.HgRepository

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

Examples of org.tmatesoft.hg.repo.HgRepository

  @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");

    HgCommitCommand cmd = new HgCommitCommand(hgRepo);
    assertFalse(cmd.isMergeCommit());
    Outcome r = cmd.message("FIRST").execute();
    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));
   
    HgDataFile dfD = hgRepo.getFileNode("d");
    assertTrue("[sanity]", dfD.exists());
    File fileD = new File(repoLoc, "d");
    assertTrue("[sanity]", fileD.canRead());
    //
    RepoUtils.modifyFileAppend(fileD, " 1 \n");
    cmd = new HgCommitCommand(hgRepo);
    assertFalse(cmd.isMergeCommit());
    r = cmd.message("SECOND").execute();
    errorCollector.assertTrue(r.isOk());
    Nodeid c2 = cmd.getCommittedRevision();
    //
    errorCollector.assertEquals("SECOND", hgRepo.getCommitLastMessage());
    //
    int lastRev = hgRepo.getChangelog().getLastRevision();
    List<HgChangeset> csets = new HgLogCommand(hgRepo).range(lastRev-1, lastRev).execute();
    errorCollector.assertEquals(csets.get(0).getNodeid(), c1);
    errorCollector.assertEquals(csets.get(1).getNodeid(), c2);
    errorCollector.assertEquals(csets.get(0).getComment(), "FIRST");
    errorCollector.assertEquals(csets.get(1).getComment(), "SECOND");
    RepoUtils.assertHgVerifyOk(errorCollector, repoLoc);
    // new commits are drafts by default, check our commit respects this
    // TODO more tests with children of changesets with draft, secret or public phases (latter -
    // new commit is child of public, but there are other commits with draft/secret phases - ensure they are intact)
    assertEquals(HgPhase.Draft, HgPhase.parse(hgRepo.getConfiguration().getStringValue("phases", "new-commit", HgPhase.Draft.mercurialString())));
    errorCollector.assertEquals(HgPhase.Draft, csets.get(0).getPhase());
    errorCollector.assertEquals(HgPhase.Draft, csets.get(1).getPhase());
  }
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.