2 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4 * Copyright 2009 Jonas Fonseca <fonseca@diku.dk>
6 * The contents of this file are subject to the terms of either the GNU
7 * General Public License Version 2 only ("GPL") or the Common
8 * Development and Distribution License("CDDL") (collectively, the
9 * "License"). You may not use this file except in compliance with the
10 * License. You can obtain a copy of the License at
11 * http://www.netbeans.org/cddl-gplv2.html. See the License for the
12 * specific language governing permissions and limitations under the
13 * License. When distributing the software, include this License Header
14 * Notice in each file.
16 * This particular file is subject to the "Classpath" exception as provided
17 * by Sun in the GPL Version 2 section of the License file that
18 * accompanied this code. If applicable, add the following below the
19 * License Header, with the fields enclosed by brackets [] replaced by
20 * your own identifying information:
21 * "Portions Copyrighted [year] [name of copyright owner]"
25 * If you wish your version of this file to be governed by only the CDDL
26 * or only the GPL Version 2, indicate your decision by adding
27 * "[Contributor] elects to include this software in this distribution
28 * under the [CDDL or GPL Version 2] license." If you do not indicate a
29 * single choice of license, a recipient has the option to distribute
30 * your version of this file under either the CDDL, the GPL Version 2 or
31 * to extend the choice of license to its licensees as provided above.
32 * However, if you add GPL Version 2 code and therefore, elected the GPL
33 * Version 2 license, then the option applies only if the new code is
34 * made subject to such option by the copyright holder.
36 package org
.nbgit
.client
;
38 import org
.nbgit
.junit
.RepositoryTestCase
;
39 import org
.eclipse
.jgit
.lib
.Commit
;
40 import org
.eclipse
.jgit
.lib
.ObjectId
;
41 import org
.eclipse
.jgit
.lib
.Tree
;
42 import org
.eclipse
.jgit
.lib
.TreeEntry
;
44 public class CommitBuilderTest
extends RepositoryTestCase
{
46 public CommitBuilderTest() {
47 super(CommitBuilderTest
.class.getSimpleName());
50 public void testCreate() throws Exception
{
51 assertNotNull(CommitBuilder
.create(repository
));
52 assertNotNull(CommitBuilder
.create(workDir
));
55 public void testEmptyCommit() throws Exception
{
56 CommitBuilder
.create(repository
).
57 time(getTime(), getTimeZone()).
64 public void testNonEmptyCommit() throws Exception
{
65 CommitBuilder
.create(repository
).
66 time(getTime(), getTimeZone()).
68 addAll(toFiles(workDir
, "a")).
74 public void testInitialEmptyCommit() throws Exception
{
75 toGitDirFile("packed-refs").delete();
76 CommitBuilder
.create(repository
).
77 time(getTime(), getTimeZone()).
84 public void testInitialNonEmptyCommit() throws Exception
{
85 toGitDirFile("packed-refs").delete();
86 CommitBuilder
.create(repository
).
87 time(getTime(), getTimeZone()).
89 addAll(toFiles(workDir
, "a")).
95 private String
message() {
96 return getName() + "\n";
99 private void compareCommitFiles() throws Exception
{
100 refCommit(repository
.mapCommit("HEAD"));
101 compareReferenceFiles();
104 private void refCommit(Commit commit
) throws Exception
{
105 refCommitLine("commit", commit
.getCommitId().name());
106 refCommitLine("tree", commit
.getTreeId().name());
107 for (ObjectId id
: commit
.getParentIds())
108 refCommitLine("parent", id
.name());
109 refCommitLine("author", commit
.getAuthor().toExternalString());
110 refCommitLine("committer", commit
.getCommitter().toExternalString());
113 for (String line
: commit
.getMessage().split("\n")) {
117 if (commit
.getTree().memberCount() > 0)
119 refTree(commit
.getTree());
122 private void refCommitLine(String name
, String value
) {
123 ref(name
+ " " + value
);
126 private void refTree(Tree tree
) throws Exception
{
127 for (TreeEntry entry
: tree
.members()) {
128 if (entry
instanceof Tree
) {
136 private void refTreeEntry(TreeEntry entry
) throws Exception
{
137 ref(String
.format("%o blob %s\t%s",
138 entry
.getMode().getBits(), entry
.getId().name(), entry
.getFullName()));