public void testBuildEmpty() throws Exception { CommitBuilder b = new CommitBuilder(); try { b.build(); fail("expected IllegalStateException on null tree id"); } catch (IllegalStateException e) { assertTrue(e.getMessage().contains("tree")); } }
@Test public void testCommitSerialization() throws IOException { RevCommit commit = testCommit.build(); testCommit(commit); }
@Test public void testCommitSerializationMultipleLinesMessage() throws IOException { testCommit.setMessage("this\n is a \n multiple lines\n message"); RevCommit commit = testCommit.build(); testCommit(commit); }
@Test public void testCommitSerializationNoParents() throws IOException { testCommit.setParentIds(null); RevCommit commit = testCommit.build(); testCommit(commit); }
@Test public void testCommitSerializationNoMessage() throws IOException { testCommit.setMessage(null); RevCommit commit = testCommit.build(); testCommit(commit); }
builder.setTreeId(newTreeId); RevCommit mapped = builder.build(); repository.objectDatabase().put(mapped); return mapped;
@Override protected RevCommit read(ObjectId id, BufferedReader reader, TYPE type) throws IOException { Preconditions.checkArgument(TYPE.COMMIT.equals(type), "Wrong type: %s", type.name()); String tree = parseLine(requireLine(reader), "tree"); List<String> parents = newArrayList(Splitter.on(' ').omitEmptyStrings() .split(parseLine(requireLine(reader), "parents"))); RevPerson author = parsePerson(requireLine(reader), "author"); RevPerson committer = parsePerson(requireLine(reader), "committer"); String message = parseMessage(reader); CommitBuilder builder = new CommitBuilder(); builder.setAuthor(author.getName().orNull()); builder.setAuthorEmail(author.getEmail().orNull()); builder.setAuthorTimestamp(author.getTimestamp()); builder.setAuthorTimeZoneOffset(author.getTimeZoneOffset()); builder.setCommitter(committer.getName().orNull()); builder.setCommitterEmail(committer.getEmail().orNull()); builder.setCommitterTimestamp(committer.getTimestamp()); builder.setCommitterTimeZoneOffset(committer.getTimeZoneOffset()); builder.setMessage(message); List<ObjectId> parentIds = Lists.transform(parents, (str) -> ObjectId.valueOf(str)); builder.setParentIds(parentIds); builder.setTreeId(ObjectId.valueOf(tree)); RevCommit commit = builder.build(); return commit; }
@Test public void testCommitSerializationNoCommitter() throws IOException { testCommit.setCommitter(null); testCommit.setCommitterEmail(null); RevCommit commit = testCommit.build(); testCommit(commit); }
@Test public void testCommitSerializationNoAuthor() throws IOException { testCommit.setAuthor(null); testCommit.setAuthorEmail(null); RevCommit commit = testCommit.build(); testCommit(commit); }
testCommit.build(), //
@Test public void testCommitSerializationMultipleParents() throws IOException { testCommit.setParentIds(ImmutableList.of(RevObjectTestSupport.hashString("parent1"), RevObjectTestSupport.hashString("parent2"), RevObjectTestSupport.hashString("parent3"), RevObjectTestSupport.hashString("parent4"))); RevCommit commit = testCommit.build(); testCommit(commit); }
builder.setCommitterTimeZoneOffset(platform.timeZoneOffset(timestamp)); RevCommit newCommit = builder.build(); replacedCommits.put(commit.getId(), newCommit.getId()); objectDatabase().put(newCommit);
public static List<RevCommit> createCommits(final int numCommits, @Nullable Platform platform) { LinkedList<RevCommit> commits = new LinkedList<>(); // much faster way of creating several fake commits than running CommitOp N times CommitBuilder builder = platform == null ? new CommitBuilder() : new CommitBuilder(platform); long timeStamp = System.currentTimeMillis(); builder.setAuthor("gabe").setAuthorEmail("gabe@example.com").setCommitter("me") .setCommitterEmail("me@too.com").setCommitterTimestamp(timeStamp) .setCommitterTimeZoneOffset(-1).setAuthorTimestamp(timeStamp) .setAuthorTimeZoneOffset(-3).setTreeId(RevTree.EMPTY_TREE_ID); ObjectId parent = null; for (int i = 1; i <= numCommits; i++) { ++timeStamp; builder.setAuthorTimestamp(timeStamp).setCommitterTimestamp(timeStamp); List<ObjectId> parents = parent == null ? null : ImmutableList.of(parent); RevCommit commit = builder.setParentIds(parents).setMessage("commit " + i).build(); commits.addFirst(commit); parent = commit.getId(); } return commits; } }
@Test public void testNoMessage() throws Exception { CommitBuilder b = new CommitBuilder(); b.setAuthor("groldan"); b.setAuthorEmail("groldan@boundlessgeo.com"); b.setCommitter("jdeolive"); b.setCommitterEmail("jdeolive@boundlessgeo.com"); b.setMessage(null); b.setAuthorTimestamp(1000); ObjectId treeId = RevObjectTestSupport.hashString("fake tree content"); b.setTreeId(treeId); ObjectId parentId1 = RevObjectTestSupport.hashString("fake parent content 1"); ObjectId parentId2 = RevObjectTestSupport.hashString("fake parent content 2"); List<ObjectId> parentIds = ImmutableList.of(parentId1, parentId2); b.setParentIds(parentIds); assertEquals(null, b.getMessage()); RevCommit commit2 = b.build(); assertEquals("", commit2.getMessage()); }
private void createCommit(RevCommit commit) { // write new tree ObjectId newTreeId = command(WriteTree2.class).call(); long timestamp = platform().currentTimeMillis(); String committerName = resolveCommitter(); String committerEmail = resolveCommitterEmail(); // Create new commit CommitBuilder builder = new CommitBuilder(); builder.setParentIds(Arrays.asList(revertHead)); builder.setTreeId(newTreeId); builder.setCommitterTimestamp(timestamp); builder.setMessage( "Revert '" + commit.getMessage() + "'\nThis reverts " + commit.getId().toString()); builder.setCommitter(committerName); builder.setCommitterEmail(committerEmail); builder.setAuthor(committerName); builder.setAuthorEmail(committerEmail); RevCommit newCommit = builder.build(); objectDatabase().put(newCommit); revertHead = newCommit.getId(); command(UpdateRef.class).setName(currentBranch).setNewValue(revertHead).call(); command(UpdateSymRef.class).setName(Ref.HEAD).setNewValue(currentBranch).call(); workingTree().updateWorkHead(newTreeId); stagingArea().updateStageHead(newTreeId); }
builder.setParentIds(parents); RevCommit cmtIn = builder.build(); assertNotNull(cmtIn);
private RevTree createHeadTree(NodeRef... treeRefs) { RevTree root = createFromRefs(objectDb, treeRefs); objectDb.put(root); CommitBuilder cb = new CommitBuilder(geogig.getPlatform()); ObjectId treeId = root.getId(); RevCommit commit = cb.setTreeId(treeId).setCommitter("Gabriel Roldan") .setAuthor("Gabriel Roldan").build(); objectDb.put(commit); SymRef head = (SymRef) geogig.command(RefParse.class).setName(Ref.HEAD).call().get(); final String currentBranch = head.getTarget(); geogig.command(UpdateRef.class).setName(currentBranch).setNewValue(commit.getId()).call(); verifyRepositoryTree(NodeRef.ROOT, treeId); verifyTreeStructure(treeId, treeRefs); return root; }
b.setParentIds(parentIds); RevCommit build = b.build(); assertNotNull(build.getId()); assertFalse(build.getId().isNull());
cb.setAuthorTimestamp(now); cb.setCommitterTimestamp(now); mergeCommit = cb.build();