Package org.eclipse.jgit.lib

Examples of org.eclipse.jgit.lib.CommitBuilder


   * @return a new commit visible only within this merger's RevWalk.
   * @throws IOException
   */
  private RevCommit createCommitForTree(ObjectId tree, List<RevCommit> parents)
      throws IOException {
    CommitBuilder c = new CommitBuilder();
    c.setTreeId(tree);
    c.setParentIds(parents);
    c.setAuthor(mockAuthor(parents));
    c.setCommitter(c.getAuthor());
    return RevCommit.parse(walk, c.build());
  }
View Full Code Here


        builder.finish();
        ObjectId treeId = index.writeTree(inserter);

        // Create a Commit object, populate it and write it
        ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}"); //$NON-NLS-1$
        CommitBuilder commit = new CommitBuilder();
        commit.setTreeId(treeId);
        if (headId != null)
          commit.setParentIds(headId);
        commit.setAuthor(author);
        commit.setCommitter(author);
        commit.setMessage(RepoText.get().repoCommitMessage);

        ObjectId commitId = inserter.insert(commit);
        inserter.flush();

        RefUpdate ru = repo.updateRef(Constants.HEAD);
View Full Code Here

  }

  private static ObjectId commit(final ObjectInserter odi,
      final DirCache treeB,
      final ObjectId[] parentIds) throws Exception {
    final CommitBuilder c = new CommitBuilder();
    c.setTreeId(treeB.writeTree(odi));
    c.setAuthor(new PersonIdent("A U Thor", "a.u.thor", 1L, 0));
    c.setCommitter(c.getAuthor());
    c.setParentIds(parentIds);
    c.setMessage("Tree " + c.getTreeId().name());
    ObjectId id = odi.insert(c);
    odi.flush();
    return id;
  }
View Full Code Here

      oi.release();
    }
    assertEquals(ObjectId
        .fromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"), treeId);

    final CommitBuilder c1 = new CommitBuilder();
    c1.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
    c1.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
    c1.setMessage("A Commit\n");
    c1.setTreeId(treeId);
    assertEquals(treeId, c1.getTreeId());
    ObjectId actid1 = insertCommit(c1);
    final ObjectId cmtid1 = ObjectId
        .fromString("803aec4aba175e8ab1d666873c984c0308179099");
    assertEquals(cmtid1, actid1);

    final CommitBuilder c2 = new CommitBuilder();
    c2.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
    c2.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
    c2.setMessage("A Commit 2\n");
    c2.setTreeId(treeId);
    assertEquals(treeId, c2.getTreeId());
    c2.setParentIds(actid1);
    ObjectId actid2 = insertCommit(c2);
    final ObjectId cmtid2 = ObjectId
        .fromString("95d068687c91c5c044fb8c77c5154d5247901553");
    assertEquals(cmtid2, actid2);

    RevCommit rm2 = parseCommit(cmtid2);
    assertNotSame(c2, rm2); // assert the parsed objects is not from the
    // cache
    assertEquals(c2.getAuthor(), rm2.getAuthorIdent());
    assertEquals(actid2, rm2.getId());
    assertEquals(c2.getMessage(), rm2.getFullMessage());
    assertEquals(c2.getTreeId(), rm2.getTree().getId());
    assertEquals(1, rm2.getParentCount());
    assertEquals(actid1, rm2.getParent(0));

    final CommitBuilder c3 = new CommitBuilder();
    c3.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
    c3.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
    c3.setMessage("A Commit 3\n");
    c3.setTreeId(treeId);
    assertEquals(treeId, c3.getTreeId());
    c3.setParentIds(actid1, actid2);
    ObjectId actid3 = insertCommit(c3);
    final ObjectId cmtid3 = ObjectId
        .fromString("ce6e1ce48fbeeb15a83f628dc8dc2debefa066f4");
    assertEquals(cmtid3, actid3);

    RevCommit rm3 = parseCommit(cmtid3);
    assertNotSame(c3, rm3); // assert the parsed objects is not from the
    // cache
    assertEquals(c3.getAuthor(), rm3.getAuthorIdent());
    assertEquals(actid3, rm3.getId());
    assertEquals(c3.getMessage(), rm3.getFullMessage());
    assertEquals(c3.getTreeId(), rm3.getTree().getId());
    assertEquals(2, rm3.getParentCount());
    assertEquals(actid1, rm3.getParent(0));
    assertEquals(actid2, rm3.getParent(1));

    final CommitBuilder c4 = new CommitBuilder();
    c4.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
    c4.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
    c4.setMessage("A Commit 4\n");
    c4.setTreeId(treeId);
    assertEquals(treeId, c3.getTreeId());
    c4.setParentIds(actid1, actid2, actid3);
    ObjectId actid4 = insertCommit(c4);
    final ObjectId cmtid4 = ObjectId
        .fromString("d1fca9fe3fef54e5212eb67902c8ed3e79736e27");
    assertEquals(cmtid4, actid4);

    RevCommit rm4 = parseCommit(cmtid4);
    assertNotSame(c4, rm3); // assert the parsed objects is not from the
    // cache
    assertEquals(c4.getAuthor(), rm4.getAuthorIdent());
    assertEquals(actid4, rm4.getId());
    assertEquals(c4.getMessage(), rm4.getFullMessage());
    assertEquals(c4.getTreeId(), rm4.getTree().getId());
    assertEquals(3, rm4.getParentCount());
    assertEquals(actid1, rm4.getParent(0));
    assertEquals(actid2, rm4.getParent(1));
    assertEquals(actid3, rm4.getParent(2));
  }
View Full Code Here

  @Test
  public void testParse_PublicParseMethod()
      throws UnsupportedEncodingException {
    ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
    CommitBuilder src = new CommitBuilder();
    src.setTreeId(fmt.idFor(Constants.OBJ_TREE, new byte[] {}));
    src.setAuthor(author);
    src.setCommitter(committer);
    src.setMessage("Test commit\n\nThis is a test.\n");

    RevCommit p = RevCommit.parse(src.build());
    assertEquals(src.getTreeId(), p.getTree());
    assertEquals(0, p.getParentCount());
    assertEquals(author, p.getAuthorIdent());
    assertEquals(committer, p.getCommitterIdent());
    assertEquals("Test commit", p.getShortMessage());
    assertEquals(src.getMessage(), p.getFullMessage());
  }
View Full Code Here

  }

  private static ObjectId commit(final ObjectInserter odi,
      final DirCache treeB,
      final ObjectId[] parentIds) throws Exception {
    final CommitBuilder c = new CommitBuilder();
    c.setTreeId(treeB.writeTree(odi));
    c.setAuthor(new PersonIdent("A U Thor", "a.u.thor", 1L, 0));
    c.setCommitter(c.getAuthor());
    c.setParentIds(parentIds);
    c.setMessage("Tree " + c.getTreeId().name());
    ObjectId id = odi.insert(c);
    odi.flush();
    return id;
  }
View Full Code Here

  }

  @Test
  public void test009_CreateCommitOldFormat() throws IOException {
    final ObjectId treeId = insertTree(new TreeFormatter());
    final CommitBuilder c = new CommitBuilder();
    c.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
    c.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
    c.setMessage("A Commit\n");
    c.setTreeId(treeId);
    assertEquals(treeId, c.getTreeId());

    ObjectId actid = insertCommit(c);

    final ObjectId cmtid = ObjectId
        .fromString("9208b2459ea6609a5af68627cc031796d0d9329b");
    assertEquals(cmtid, actid);

    // Verify the commit we just wrote is in the correct format.
    ObjectDatabase odb = db.getObjectDatabase();
    assertTrue("is ObjectDirectory", odb instanceof ObjectDirectory);
    final XInputStream xis = new XInputStream(new FileInputStream(
        ((ObjectDirectory) odb).fileFor(cmtid)));
    try {
      assertEquals(0x78, xis.readUInt8());
      assertEquals(0x9c, xis.readUInt8());
      assertEquals(0, 0x789c % 31);
    } finally {
      xis.close();
    }

    // Verify we can read it.
    RevCommit c2 = parseCommit(actid);
    assertNotNull(c2);
    assertEquals(c.getMessage(), c2.getFullMessage());
    assertEquals(c.getTreeId(), c2.getTree());
    assertEquals(c.getAuthor(), c2.getAuthorIdent());
    assertEquals(c.getCommitter(), c2.getCommitterIdent());
  }
View Full Code Here

    final ObjectId emptyId = insertEmptyBlob();
    final Tree almostEmptyTree = new Tree(db);
    almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId,
        "empty".getBytes(), false));
    final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree);
    final CommitBuilder almostEmptyCommit = new CommitBuilder();
    almostEmptyCommit.setAuthor(new PersonIdent(author, 1154236443000L,
        -2 * 60)); // not exactly the same
    almostEmptyCommit.setCommitter(new PersonIdent(author, 1154236443000L,
        -2 * 60));
    almostEmptyCommit.setMessage("test022\n");
    almostEmptyCommit.setTreeId(almostEmptyTreeId);
    ObjectId almostEmptyCommitId = insertCommit(almostEmptyCommit);
    final TagBuilder t = new TagBuilder();
    t.setObjectId(almostEmptyCommitId, Constants.OBJ_COMMIT);
    t.setTag("test022");
    t.setTagger(new PersonIdent(author, 1154236443000L, -4 * 60));
 
View Full Code Here

    final ObjectId emptyId = insertEmptyBlob();
    final Tree almostEmptyTree = new Tree(db);
    almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId,
        "empty".getBytes(), false));
    final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree);
    CommitBuilder commit = new CommitBuilder();
    commit.setTreeId(almostEmptyTreeId);
    commit.setAuthor(new PersonIdent("Joe H\u00e4cker", "joe@example.com",
        4294967295000L, 60));
    commit.setCommitter(new PersonIdent("Joe Hacker", "joe2@example.com",
        4294967295000L, 60));
    commit.setEncoding("UTF-8");
    commit.setMessage("\u00dcbergeeks");
    ObjectId cid = insertCommit(commit);
    assertEquals("4680908112778718f37e686cbebcc912730b3154", cid.name());

    RevCommit loadedCommit = parseCommit(cid);
    assertEquals(commit.getMessage(), loadedCommit.getFullMessage());
  }
View Full Code Here

    final ObjectId emptyId = insertEmptyBlob();
    final Tree almostEmptyTree = new Tree(db);
    almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId,
        "empty".getBytes(), false));
    final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree);
    CommitBuilder commit = new CommitBuilder();
    commit.setTreeId(almostEmptyTreeId);
    commit.setAuthor(new PersonIdent("Joe H\u00e4cker", "joe@example.com",
        4294967295000L, 60));
    commit.setCommitter(new PersonIdent("Joe Hacker", "joe2@example.com",
        4294967295000L, 60));
    commit.setEncoding("ISO-8859-1");
    commit.setMessage("\u00dcbergeeks");
    ObjectId cid = insertCommit(commit);
    assertEquals("2979b39d385014b33287054b87f77bcb3ecb5ebf", cid.name());
  }
View Full Code Here

TOP

Related Classes of org.eclipse.jgit.lib.CommitBuilder

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.