Ejemplo n.º 1
0
  private TreeFormatter createTreeFormatter(
      Map<SubtreeConfig, RevCommit> parentCommits, String commitMessage)
      throws MissingObjectException, IncorrectObjectTypeException, CorruptObjectException,
          IOException {
    TreeWalk treeWalk = new TreeWalk(repository);
    try {
      treeWalk.setRecursive(false);
      addTrees(parentCommits, treeWalk);

      TreeFormatter treeFormatter = new TreeFormatter();
      while (treeWalk.next()) {
        AbstractTreeIterator iterator = getSingleTreeIterator(treeWalk, commitMessage);
        if (iterator == null) {
          throw new IllegalStateException(
              "Tree walker did not return a single tree (should not happen): "
                  + treeWalk.getPathString());
        }
        treeFormatter.append(
            iterator.getEntryPathBuffer(),
            0,
            iterator.getEntryPathLength(),
            iterator.getEntryFileMode(),
            iterator.getEntryObjectId());
      }
      return treeFormatter;
    } finally {
      treeWalk.release();
    }
  }
Ejemplo n.º 2
0
 @NotNull
 private static ObjectId createFirstRevision(@NotNull Repository repository) throws IOException {
   final ObjectInserter inserter = repository.newObjectInserter();
   // Create commit tree.
   final TreeFormatter rootBuilder = new TreeFormatter();
   rootBuilder.append(
       ".gitattributes", FileMode.REGULAR_FILE, insertFile(inserter, "example/_gitattributes"));
   new ObjectChecker().checkTree(rootBuilder.toByteArray());
   final ObjectId rootId = inserter.insert(rootBuilder);
   // Create first commit with message.
   final CommitBuilder commitBuilder = new CommitBuilder();
   commitBuilder.setAuthor(new PersonIdent("", "", 0, 0));
   commitBuilder.setCommitter(new PersonIdent("", "", 0, 0));
   commitBuilder.setMessage("Initial commit");
   commitBuilder.setTreeId(rootId);
   final ObjectId commitId = inserter.insert(commitBuilder);
   inserter.flush();
   return commitId;
 }