Browse Source

Remove deprecated WriteTree from tests

These tests doesn't need to use WriteTree anymore.  There are
other means of creating tree objects in the repository that aren't
deprecated, so use those instead.

Change-Id: I89cd8ab54c66964a5fddc0a045f1c0f1c7c49055
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
stable-0.11
Shawn O. Pearce 14 years ago committed by Chris Aniszczyk
parent
commit
d02f01e7c8
  1. 26
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
  2. 283
      org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java

26
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java

@ -63,11 +63,9 @@ public class ReflogConfigTest extends RepositoryTestCase {
// do one commit and check that reflog size is 0: no reflogs should be // do one commit and check that reflog size is 0: no reflogs should be
// written // written
final Tree t = new Tree(db); commit("A Commit\n", new PersonIdent(author, commitTime, tz),
addFileToTree(t, "i-am-a-file", "and this is the data in me\n");
commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz),
new PersonIdent(committer, commitTime, tz)); new PersonIdent(committer, commitTime, tz));
commitTime += 100; commitTime += 60 * 1000;
assertTrue( assertTrue(
"Reflog for HEAD still contain no entry", "Reflog for HEAD still contain no entry",
db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 0); db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 0);
@ -78,10 +76,9 @@ public class ReflogConfigTest extends RepositoryTestCase {
assertTrue(cfg.get(CoreConfig.KEY).isLogAllRefUpdates()); assertTrue(cfg.get(CoreConfig.KEY).isLogAllRefUpdates());
// do one commit and check that reflog size is increased to 1 // do one commit and check that reflog size is increased to 1
addFileToTree(t, "i-am-another-file", "and this is other data in me\n"); commit("A Commit\n", new PersonIdent(author, commitTime, tz),
commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz),
new PersonIdent(committer, commitTime, tz)); new PersonIdent(committer, commitTime, tz));
commitTime += 100; commitTime += 60 * 1000;
assertTrue( assertTrue(
"Reflog for HEAD should contain one entry", "Reflog for HEAD should contain one entry",
db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 1); db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 1);
@ -92,32 +89,23 @@ public class ReflogConfigTest extends RepositoryTestCase {
assertFalse(cfg.get(CoreConfig.KEY).isLogAllRefUpdates()); assertFalse(cfg.get(CoreConfig.KEY).isLogAllRefUpdates());
// do one commit and check that reflog size is 2 // do one commit and check that reflog size is 2
addFileToTree(t, "i-am-anotheranother-file", commit("A Commit\n", new PersonIdent(author, commitTime, tz),
"and this is other other data in me\n");
commit(t, "A Commit\n", new PersonIdent(author, commitTime, tz),
new PersonIdent(committer, commitTime, tz)); new PersonIdent(committer, commitTime, tz));
assertTrue( assertTrue(
"Reflog for HEAD should contain two entries", "Reflog for HEAD should contain two entries",
db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 2); db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 2);
} }
private void addFileToTree(final Tree t, String filename, String content) private void commit(String commitMsg, PersonIdent author,
throws IOException {
FileTreeEntry f = t.addFile(filename);
writeTrashFile(f.getName(), content);
t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
}
private void commit(final Tree t, String commitMsg, PersonIdent author,
PersonIdent committer) throws IOException { PersonIdent committer) throws IOException {
final CommitBuilder commit = new CommitBuilder(); final CommitBuilder commit = new CommitBuilder();
commit.setAuthor(author); commit.setAuthor(author);
commit.setCommitter(committer); commit.setCommitter(committer);
commit.setMessage(commitMsg); commit.setMessage(commitMsg);
commit.setTreeId(t.getTreeId());
ObjectInserter inserter = db.newObjectInserter(); ObjectInserter inserter = db.newObjectInserter();
ObjectId id; ObjectId id;
try { try {
commit.setTreeId(inserter.insert(new TreeFormatter()));
id = inserter.insert(commit); id = inserter.insert(commit);
inserter.flush(); inserter.flush();
} finally { } finally {

283
org.eclipse.jgit.test/tst/org/eclipse/jgit/storage/file/T0003_Basic.java

@ -59,6 +59,7 @@ import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.AnyObjectId; import org.eclipse.jgit.lib.AnyObjectId;
import org.eclipse.jgit.lib.CommitBuilder; import org.eclipse.jgit.lib.CommitBuilder;
import org.eclipse.jgit.lib.Constants; import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.FileMode;
import org.eclipse.jgit.lib.FileTreeEntry; import org.eclipse.jgit.lib.FileTreeEntry;
import org.eclipse.jgit.lib.ObjectDatabase; import org.eclipse.jgit.lib.ObjectDatabase;
import org.eclipse.jgit.lib.ObjectId; import org.eclipse.jgit.lib.ObjectId;
@ -69,8 +70,7 @@ import org.eclipse.jgit.lib.Repository;
import org.eclipse.jgit.lib.SampleDataRepositoryTestCase; import org.eclipse.jgit.lib.SampleDataRepositoryTestCase;
import org.eclipse.jgit.lib.TagBuilder; import org.eclipse.jgit.lib.TagBuilder;
import org.eclipse.jgit.lib.Tree; import org.eclipse.jgit.lib.Tree;
import org.eclipse.jgit.lib.TreeEntry; import org.eclipse.jgit.lib.TreeFormatter;
import org.eclipse.jgit.lib.WriteTree;
import org.eclipse.jgit.revwalk.RevCommit; import org.eclipse.jgit.revwalk.RevCommit;
import org.eclipse.jgit.revwalk.RevTag; import org.eclipse.jgit.revwalk.RevTag;
import org.eclipse.jgit.revwalk.RevWalk; import org.eclipse.jgit.revwalk.RevWalk;
@ -103,9 +103,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
new FileRepositoryBuilder().build(); new FileRepositoryBuilder().build();
fail("Must pass either GIT_DIR or GIT_WORK_TREE"); fail("Must pass either GIT_DIR or GIT_WORK_TREE");
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
assertEquals( assertEquals(JGitText.get().eitherGitDirOrWorkTreeRequired, e
JGitText.get().eitherGitDirOrWorkTreeRequired, .getMessage());
e.getMessage());
} }
} }
@ -117,27 +116,32 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
*/ */
public void test000_openrepo_default_gitDirSet() throws IOException { public void test000_openrepo_default_gitDirSet() throws IOException {
File repo1Parent = new File(trash.getParentFile(), "r1"); File repo1Parent = new File(trash.getParentFile(), "r1");
Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); Repository repo1initial = new FileRepository(new File(repo1Parent,
Constants.DOT_GIT));
repo1initial.create(); repo1initial.create();
repo1initial.close(); repo1initial.close();
File theDir = new File(repo1Parent, Constants.DOT_GIT); File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build(); FileRepository r = new FileRepositoryBuilder().setGitDir(theDir)
.build();
assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(repo1Parent, r.getWorkTree()); assertEqualsPath(repo1Parent, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase().getDirectory()); assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase()
.getDirectory());
} }
/** /**
* Check that we can pass both a git directory and a work tree * Check that we can pass both a git directory and a work tree repo when the
* repo when the gitDir is given. * gitDir is given.
* *
* @throws IOException * @throws IOException
*/ */
public void test000_openrepo_default_gitDirAndWorkTreeSet() throws IOException { public void test000_openrepo_default_gitDirAndWorkTreeSet()
throws IOException {
File repo1Parent = new File(trash.getParentFile(), "r1"); File repo1Parent = new File(trash.getParentFile(), "r1");
Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); Repository repo1initial = new FileRepository(new File(repo1Parent,
Constants.DOT_GIT));
repo1initial.create(); repo1initial.create();
repo1initial.close(); repo1initial.close();
@ -147,7 +151,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(repo1Parent.getParentFile(), r.getWorkTree()); assertEqualsPath(repo1Parent.getParentFile(), r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase().getDirectory()); assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase()
.getDirectory());
} }
/** /**
@ -158,16 +163,19 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
*/ */
public void test000_openrepo_default_workDirSet() throws IOException { public void test000_openrepo_default_workDirSet() throws IOException {
File repo1Parent = new File(trash.getParentFile(), "r1"); File repo1Parent = new File(trash.getParentFile(), "r1");
Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); Repository repo1initial = new FileRepository(new File(repo1Parent,
Constants.DOT_GIT));
repo1initial.create(); repo1initial.create();
repo1initial.close(); repo1initial.close();
File theDir = new File(repo1Parent, Constants.DOT_GIT); File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = new FileRepositoryBuilder().setWorkTree(repo1Parent).build(); FileRepository r = new FileRepositoryBuilder().setWorkTree(repo1Parent)
.build();
assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(repo1Parent, r.getWorkTree()); assertEqualsPath(repo1Parent, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase().getDirectory()); assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase()
.getDirectory());
} }
/** /**
@ -180,7 +188,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File repo1Parent = new File(trash.getParentFile(), "r1"); File repo1Parent = new File(trash.getParentFile(), "r1");
File workdir = new File(trash.getParentFile(), "rw"); File workdir = new File(trash.getParentFile(), "rw");
workdir.mkdir(); workdir.mkdir();
FileRepository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); FileRepository repo1initial = new FileRepository(new File(repo1Parent,
Constants.DOT_GIT));
repo1initial.create(); repo1initial.create();
final FileBasedConfig cfg = repo1initial.getConfig(); final FileBasedConfig cfg = repo1initial.getConfig();
cfg.setString("core", null, "worktree", workdir.getAbsolutePath()); cfg.setString("core", null, "worktree", workdir.getAbsolutePath());
@ -188,11 +197,13 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
repo1initial.close(); repo1initial.close();
File theDir = new File(repo1Parent, Constants.DOT_GIT); File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build(); FileRepository r = new FileRepositoryBuilder().setGitDir(theDir)
.build();
assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(workdir, r.getWorkTree()); assertEqualsPath(workdir, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase().getDirectory()); assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase()
.getDirectory());
} }
/** /**
@ -205,7 +216,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File repo1Parent = new File(trash.getParentFile(), "r1"); File repo1Parent = new File(trash.getParentFile(), "r1");
File workdir = new File(trash.getParentFile(), "rw"); File workdir = new File(trash.getParentFile(), "rw");
workdir.mkdir(); workdir.mkdir();
FileRepository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); FileRepository repo1initial = new FileRepository(new File(repo1Parent,
Constants.DOT_GIT));
repo1initial.create(); repo1initial.create();
final FileBasedConfig cfg = repo1initial.getConfig(); final FileBasedConfig cfg = repo1initial.getConfig();
cfg.setString("core", null, "worktree", "../../rw"); cfg.setString("core", null, "worktree", "../../rw");
@ -213,11 +225,13 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
repo1initial.close(); repo1initial.close();
File theDir = new File(repo1Parent, Constants.DOT_GIT); File theDir = new File(repo1Parent, Constants.DOT_GIT);
FileRepository r = new FileRepositoryBuilder().setGitDir(theDir).build(); FileRepository r = new FileRepositoryBuilder().setGitDir(theDir)
.build();
assertEqualsPath(theDir, r.getDirectory()); assertEqualsPath(theDir, r.getDirectory());
assertEqualsPath(workdir, r.getWorkTree()); assertEqualsPath(workdir, r.getWorkTree());
assertEqualsPath(new File(theDir, "index"), r.getIndexFile()); assertEqualsPath(new File(theDir, "index"), r.getIndexFile());
assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase().getDirectory()); assertEqualsPath(new File(theDir, "objects"), r.getObjectDatabase()
.getDirectory());
} }
/** /**
@ -232,7 +246,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File indexFile = new File(trash, "idx"); File indexFile = new File(trash, "idx");
File objDir = new File(trash, "../obj"); File objDir = new File(trash, "../obj");
File altObjDir = db.getObjectDatabase().getDirectory(); File altObjDir = db.getObjectDatabase().getDirectory();
Repository repo1initial = new FileRepository(new File(repo1Parent, Constants.DOT_GIT)); Repository repo1initial = new FileRepository(new File(repo1Parent,
Constants.DOT_GIT));
repo1initial.create(); repo1initial.create();
repo1initial.close(); repo1initial.close();
@ -264,10 +279,11 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
// object (as it already exists in the pack). // object (as it already exists in the pack).
// //
final Repository newdb = createBareRepository(); final Repository newdb = createBareRepository();
final Tree t = new Tree(newdb); final ObjectInserter oi = newdb.newObjectInserter();
t.accept(new WriteTree(trash, newdb), TreeEntry.MODIFIED_ONLY); final ObjectId treeId = oi.insert(new TreeFormatter());
assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.getId() oi.release();
.name());
assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", treeId.name());
final File o = new File(new File(new File(newdb.getDirectory(), final File o = new File(new File(new File(newdb.getDirectory(),
"objects"), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904"); "objects"), "4b"), "825dc642cb6eb9a060e54bf8d69288fbee4904");
assertTrue("Exists " + o, o.isFile()); assertTrue("Exists " + o, o.isFile());
@ -277,36 +293,14 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
public void test002_WriteEmptyTree2() throws IOException { public void test002_WriteEmptyTree2() throws IOException {
// File shouldn't exist as it is in a test pack. // File shouldn't exist as it is in a test pack.
// //
final Tree t = new Tree(db); final ObjectId treeId = insertTree(new TreeFormatter());
t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", treeId.name());
assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", t.getId()
.name());
final File o = new File(new File( final File o = new File(new File(
new File(db.getDirectory(), "objects"), "4b"), new File(db.getDirectory(), "objects"), "4b"),
"825dc642cb6eb9a060e54bf8d69288fbee4904"); "825dc642cb6eb9a060e54bf8d69288fbee4904");
assertFalse("Exists " + o, o.isFile()); assertFalse("Exists " + o, o.isFile());
} }
public void test003_WriteShouldBeEmptyTree() throws IOException {
final Tree t = new Tree(db);
final ObjectId emptyId = insertEmptyBlob();
t.addFile("should-be-empty").setId(emptyId);
t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
assertEquals("7bb943559a305bdd6bdee2cef6e5df2413c3d30a", t.getId()
.name());
File o;
o = new File(new File(new File(db.getDirectory(), "objects"), "7b"),
"b943559a305bdd6bdee2cef6e5df2413c3d30a");
assertTrue("Exists " + o, o.isFile());
assertTrue("Read-only " + o, !o.canWrite());
o = new File(new File(new File(db.getDirectory(), "objects"), "e6"),
"9de29bb2d1d6434b8b29ae775ad8c2e48c5391");
assertTrue("Exists " + o, o.isFile());
assertTrue("Read-only " + o, !o.canWrite());
}
public void test006_ReadUglyConfig() throws IOException, public void test006_ReadUglyConfig() throws IOException,
ConfigInvalidException { ConfigInvalidException {
final File cfg = new File(db.getDirectory(), "config"); final File cfg = new File(db.getDirectory(), "config");
@ -320,8 +314,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
write(cfg, configStr); write(cfg, configStr);
c.load(); c.load();
assertEquals("yes", c.getString("core", null, "filemode")); assertEquals("yes", c.getString("core", null, "filemode"));
assertEquals("A U Thor <thor@example.com>", c assertEquals("A U Thor <thor@example.com>", c.getString("user", null,
.getString("user", null, "email")); "email"));
assertEquals("A Thor \\ \"\t ", c.getString("user", null, "name")); assertEquals("A Thor \\ \"\t ", c.getString("user", null, "name"));
assertEquals("a many line\ncomment\n to test", c.getString("user", assertEquals("a many line\ncomment\n to test", c.getString("user",
null, "defaultCheckInComment")); null, "defaultCheckInComment"));
@ -336,7 +330,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
public void test007_Open() throws IOException { public void test007_Open() throws IOException {
final FileRepository db2 = new FileRepository(db.getDirectory()); final FileRepository db2 = new FileRepository(db.getDirectory());
assertEquals(db.getDirectory(), db2.getDirectory()); assertEquals(db.getDirectory(), db2.getDirectory());
assertEquals(db.getObjectDatabase().getDirectory(), db2.getObjectDatabase().getDirectory()); assertEquals(db.getObjectDatabase().getDirectory(), db2
.getObjectDatabase().getDirectory());
assertNotSame(db.getConfig(), db2.getConfig()); assertNotSame(db.getConfig(), db2.getConfig());
} }
@ -357,24 +352,18 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
} }
public void test009_CreateCommitOldFormat() throws IOException { public void test009_CreateCommitOldFormat() throws IOException {
final Tree t = new Tree(db); final ObjectId treeId = insertTree(new TreeFormatter());
final FileTreeEntry f = t.addFile("i-am-a-file");
writeTrashFile(f.getName(), "and this is the data in me\n");
t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY);
assertEquals(ObjectId.fromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"),
t.getTreeId());
final CommitBuilder c = new CommitBuilder(); final CommitBuilder c = new CommitBuilder();
c.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); c.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
c.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c.setMessage("A Commit\n"); c.setMessage("A Commit\n");
c.setTreeId(t.getTreeId()); c.setTreeId(treeId);
assertEquals(t.getTreeId(), c.getTreeId()); assertEquals(treeId, c.getTreeId());
ObjectId actid = insertCommit(c); ObjectId actid = insertCommit(c);
final ObjectId cmtid = ObjectId.fromString( final ObjectId cmtid = ObjectId
"803aec4aba175e8ab1d666873c984c0308179099"); .fromString("9208b2459ea6609a5af68627cc031796d0d9329b");
assertEquals(cmtid, actid); assertEquals(cmtid, actid);
// Verify the commit we just wrote is in the correct format. // Verify the commit we just wrote is in the correct format.
@ -414,9 +403,11 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
e3.setId(emptyBlob); e3.setId(emptyBlob);
e4.setId(emptyBlob); e4.setId(emptyBlob);
t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); final Tree a = (Tree) t.findTreeMember("a");
assertEquals(ObjectId.fromString("b47a8f0a4190f7572e11212769090523e23eb1ea"), a.setId(insertTree(a));
t.getId()); assertEquals(ObjectId
.fromString("b47a8f0a4190f7572e11212769090523e23eb1ea"),
insertTree(t));
} }
public void test020_createBlobTag() throws IOException { public void test020_createBlobTag() throws IOException {
@ -432,14 +423,17 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
RevTag mapTag = parseTag(actid); RevTag mapTag = parseTag(actid);
assertEquals(Constants.OBJ_BLOB, mapTag.getObject().getType()); assertEquals(Constants.OBJ_BLOB, mapTag.getObject().getType());
assertEquals("test020 tagged\n", mapTag.getFullMessage()); assertEquals("test020 tagged\n", mapTag.getFullMessage());
assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getTaggerIdent()); assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag
assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag.getObject().getId().name()); .getTaggerIdent());
assertEquals("e69de29bb2d1d6434b8b29ae775ad8c2e48c5391", mapTag
.getObject().getId().name());
} }
public void test021_createTreeTag() throws IOException { public void test021_createTreeTag() throws IOException {
final ObjectId emptyId = insertEmptyBlob(); final ObjectId emptyId = insertEmptyBlob();
final Tree almostEmptyTree = new Tree(db); final Tree almostEmptyTree = new Tree(db);
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false)); almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId,
"empty".getBytes(), false));
final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree); final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree);
final TagBuilder t = new TagBuilder(); final TagBuilder t = new TagBuilder();
t.setObjectId(almostEmptyTreeId, Constants.OBJ_TREE); t.setObjectId(almostEmptyTreeId, Constants.OBJ_TREE);
@ -452,23 +446,28 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
RevTag mapTag = parseTag(actid); RevTag mapTag = parseTag(actid);
assertEquals(Constants.OBJ_TREE, mapTag.getObject().getType()); assertEquals(Constants.OBJ_TREE, mapTag.getObject().getType());
assertEquals("test021 tagged\n", mapTag.getFullMessage()); assertEquals("test021 tagged\n", mapTag.getFullMessage());
assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getTaggerIdent()); assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag
assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag.getObject().getId().name()); .getTaggerIdent());
assertEquals("417c01c8795a35b8e835113a85a5c0c1c77f67fb", mapTag
.getObject().getId().name());
} }
public void test022_createCommitTag() throws IOException { public void test022_createCommitTag() throws IOException {
final ObjectId emptyId = insertEmptyBlob(); final ObjectId emptyId = insertEmptyBlob();
final Tree almostEmptyTree = new Tree(db); final Tree almostEmptyTree = new Tree(db);
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false)); almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId,
"empty".getBytes(), false));
final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree); final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree);
final CommitBuilder almostEmptyCommit = new CommitBuilder(); final CommitBuilder almostEmptyCommit = new CommitBuilder();
almostEmptyCommit.setAuthor(new PersonIdent(author, 1154236443000L, -2 * 60)); // not exactly the same almostEmptyCommit.setAuthor(new PersonIdent(author, 1154236443000L,
almostEmptyCommit.setCommitter(new PersonIdent(author, 1154236443000L, -2 * 60)); -2 * 60)); // not exactly the same
almostEmptyCommit.setCommitter(new PersonIdent(author, 1154236443000L,
-2 * 60));
almostEmptyCommit.setMessage("test022\n"); almostEmptyCommit.setMessage("test022\n");
almostEmptyCommit.setTreeId(almostEmptyTreeId); almostEmptyCommit.setTreeId(almostEmptyTreeId);
ObjectId almostEmptyCommitId = insertCommit(almostEmptyCommit); ObjectId almostEmptyCommitId = insertCommit(almostEmptyCommit);
final TagBuilder t = new TagBuilder(); final TagBuilder t = new TagBuilder();
t.setObjectId(almostEmptyCommitId,Constants.OBJ_COMMIT); t.setObjectId(almostEmptyCommitId, Constants.OBJ_COMMIT);
t.setTag("test022"); t.setTag("test022");
t.setTagger(new PersonIdent(author, 1154236443000L, -4 * 60)); t.setTagger(new PersonIdent(author, 1154236443000L, -4 * 60));
t.setMessage("test022 tagged\n"); t.setMessage("test022 tagged\n");
@ -478,19 +477,24 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
RevTag mapTag = parseTag(actid); RevTag mapTag = parseTag(actid);
assertEquals(Constants.OBJ_COMMIT, mapTag.getObject().getType()); assertEquals(Constants.OBJ_COMMIT, mapTag.getObject().getType());
assertEquals("test022 tagged\n", mapTag.getFullMessage()); assertEquals("test022 tagged\n", mapTag.getFullMessage());
assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag.getTaggerIdent()); assertEquals(new PersonIdent(author, 1154236443000L, -4 * 60), mapTag
assertEquals("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag.getObject().getId().name()); .getTaggerIdent());
assertEquals("b5d3b45a96b340441f5abb9080411705c51cc86c", mapTag
.getObject().getId().name());
} }
public void test023_createCommitNonAnullii() throws IOException { public void test023_createCommitNonAnullii() throws IOException {
final ObjectId emptyId = insertEmptyBlob(); final ObjectId emptyId = insertEmptyBlob();
final Tree almostEmptyTree = new Tree(db); final Tree almostEmptyTree = new Tree(db);
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false)); almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId,
"empty".getBytes(), false));
final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree); final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree);
CommitBuilder commit = new CommitBuilder(); CommitBuilder commit = new CommitBuilder();
commit.setTreeId(almostEmptyTreeId); commit.setTreeId(almostEmptyTreeId);
commit.setAuthor(new PersonIdent("Joe H\u00e4cker","joe@example.com",4294967295000L,60)); commit.setAuthor(new PersonIdent("Joe H\u00e4cker", "joe@example.com",
commit.setCommitter(new PersonIdent("Joe Hacker","joe2@example.com",4294967295000L,60)); 4294967295000L, 60));
commit.setCommitter(new PersonIdent("Joe Hacker", "joe2@example.com",
4294967295000L, 60));
commit.setEncoding("UTF-8"); commit.setEncoding("UTF-8");
commit.setMessage("\u00dcbergeeks"); commit.setMessage("\u00dcbergeeks");
ObjectId cid = insertCommit(commit); ObjectId cid = insertCommit(commit);
@ -503,12 +507,15 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
public void test024_createCommitNonAscii() throws IOException { public void test024_createCommitNonAscii() throws IOException {
final ObjectId emptyId = insertEmptyBlob(); final ObjectId emptyId = insertEmptyBlob();
final Tree almostEmptyTree = new Tree(db); final Tree almostEmptyTree = new Tree(db);
almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId, "empty".getBytes(), false)); almostEmptyTree.addEntry(new FileTreeEntry(almostEmptyTree, emptyId,
"empty".getBytes(), false));
final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree); final ObjectId almostEmptyTreeId = insertTree(almostEmptyTree);
CommitBuilder commit = new CommitBuilder(); CommitBuilder commit = new CommitBuilder();
commit.setTreeId(almostEmptyTreeId); commit.setTreeId(almostEmptyTreeId);
commit.setAuthor(new PersonIdent("Joe H\u00e4cker","joe@example.com",4294967295000L,60)); commit.setAuthor(new PersonIdent("Joe H\u00e4cker", "joe@example.com",
commit.setCommitter(new PersonIdent("Joe Hacker","joe2@example.com",4294967295000L,60)); 4294967295000L, 60));
commit.setCommitter(new PersonIdent("Joe Hacker", "joe2@example.com",
4294967295000L, 60));
commit.setEncoding("ISO-8859-1"); commit.setEncoding("ISO-8859-1");
commit.setMessage("\u00dcbergeeks"); commit.setMessage("\u00dcbergeeks");
ObjectId cid = insertCommit(commit); ObjectId cid = insertCommit(commit);
@ -524,38 +531,47 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
} }
public void test026_CreateCommitMultipleparents() throws IOException { public void test026_CreateCommitMultipleparents() throws IOException {
final Tree t = new Tree(db); final ObjectId treeId;
final FileTreeEntry f = t.addFile("i-am-a-file"); final ObjectInserter oi = db.newObjectInserter();
writeTrashFile(f.getName(), "and this is the data in me\n"); try {
t.accept(new WriteTree(trash, db), TreeEntry.MODIFIED_ONLY); final ObjectId blobId = oi.insert(Constants.OBJ_BLOB,
assertEquals(ObjectId.fromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"), "and this is the data in me\n".getBytes(Constants.CHARSET));
t.getTreeId()); TreeFormatter fmt = new TreeFormatter();
fmt.append("i-am-a-file", FileMode.REGULAR_FILE, blobId);
treeId = oi.insert(fmt);
oi.flush();
} finally {
oi.release();
}
assertEquals(ObjectId
.fromString("00b1f73724f493096d1ffa0b0f1f1482dbb8c936"), treeId);
final CommitBuilder c1 = new CommitBuilder(); final CommitBuilder c1 = new CommitBuilder();
c1.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); c1.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
c1.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c1.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c1.setMessage("A Commit\n"); c1.setMessage("A Commit\n");
c1.setTreeId(t.getTreeId()); c1.setTreeId(treeId);
assertEquals(t.getTreeId(), c1.getTreeId()); assertEquals(treeId, c1.getTreeId());
ObjectId actid1 = insertCommit(c1); ObjectId actid1 = insertCommit(c1);
final ObjectId cmtid1 = ObjectId.fromString( final ObjectId cmtid1 = ObjectId
"803aec4aba175e8ab1d666873c984c0308179099"); .fromString("803aec4aba175e8ab1d666873c984c0308179099");
assertEquals(cmtid1, actid1); assertEquals(cmtid1, actid1);
final CommitBuilder c2 = new CommitBuilder(); final CommitBuilder c2 = new CommitBuilder();
c2.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); c2.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
c2.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c2.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c2.setMessage("A Commit 2\n"); c2.setMessage("A Commit 2\n");
c2.setTreeId(t.getTreeId()); c2.setTreeId(treeId);
assertEquals(t.getTreeId(), c2.getTreeId()); assertEquals(treeId, c2.getTreeId());
c2.setParentIds(actid1); c2.setParentIds(actid1);
ObjectId actid2 = insertCommit(c2); ObjectId actid2 = insertCommit(c2);
final ObjectId cmtid2 = ObjectId.fromString( final ObjectId cmtid2 = ObjectId
"95d068687c91c5c044fb8c77c5154d5247901553"); .fromString("95d068687c91c5c044fb8c77c5154d5247901553");
assertEquals(cmtid2, actid2); assertEquals(cmtid2, actid2);
RevCommit rm2 = parseCommit(cmtid2); RevCommit rm2 = parseCommit(cmtid2);
assertNotSame(c2, rm2); // assert the parsed objects is not from the cache assertNotSame(c2, rm2); // assert the parsed objects is not from the
// cache
assertEquals(c2.getAuthor(), rm2.getAuthorIdent()); assertEquals(c2.getAuthor(), rm2.getAuthorIdent());
assertEquals(actid2, rm2.getId()); assertEquals(actid2, rm2.getId());
assertEquals(c2.getMessage(), rm2.getFullMessage()); assertEquals(c2.getMessage(), rm2.getFullMessage());
@ -567,16 +583,17 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
c3.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); c3.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
c3.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c3.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c3.setMessage("A Commit 3\n"); c3.setMessage("A Commit 3\n");
c3.setTreeId(t.getTreeId()); c3.setTreeId(treeId);
assertEquals(t.getTreeId(), c3.getTreeId()); assertEquals(treeId, c3.getTreeId());
c3.setParentIds(actid1, actid2); c3.setParentIds(actid1, actid2);
ObjectId actid3 = insertCommit(c3); ObjectId actid3 = insertCommit(c3);
final ObjectId cmtid3 = ObjectId.fromString( final ObjectId cmtid3 = ObjectId
"ce6e1ce48fbeeb15a83f628dc8dc2debefa066f4"); .fromString("ce6e1ce48fbeeb15a83f628dc8dc2debefa066f4");
assertEquals(cmtid3, actid3); assertEquals(cmtid3, actid3);
RevCommit rm3 = parseCommit(cmtid3); RevCommit rm3 = parseCommit(cmtid3);
assertNotSame(c3, rm3); // assert the parsed objects is not from the cache assertNotSame(c3, rm3); // assert the parsed objects is not from the
// cache
assertEquals(c3.getAuthor(), rm3.getAuthorIdent()); assertEquals(c3.getAuthor(), rm3.getAuthorIdent());
assertEquals(actid3, rm3.getId()); assertEquals(actid3, rm3.getId());
assertEquals(c3.getMessage(), rm3.getFullMessage()); assertEquals(c3.getMessage(), rm3.getFullMessage());
@ -589,16 +606,17 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
c4.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60)); c4.setAuthor(new PersonIdent(author, 1154236443000L, -4 * 60));
c4.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60)); c4.setCommitter(new PersonIdent(committer, 1154236443000L, -4 * 60));
c4.setMessage("A Commit 4\n"); c4.setMessage("A Commit 4\n");
c4.setTreeId(t.getTreeId()); c4.setTreeId(treeId);
assertEquals(t.getTreeId(), c3.getTreeId()); assertEquals(treeId, c3.getTreeId());
c4.setParentIds(actid1, actid2, actid3); c4.setParentIds(actid1, actid2, actid3);
ObjectId actid4 = insertCommit(c4); ObjectId actid4 = insertCommit(c4);
final ObjectId cmtid4 = ObjectId.fromString( final ObjectId cmtid4 = ObjectId
"d1fca9fe3fef54e5212eb67902c8ed3e79736e27"); .fromString("d1fca9fe3fef54e5212eb67902c8ed3e79736e27");
assertEquals(cmtid4, actid4); assertEquals(cmtid4, actid4);
RevCommit rm4 = parseCommit(cmtid4); RevCommit rm4 = parseCommit(cmtid4);
assertNotSame(c4, rm3); // assert the parsed objects is not from the cache assertNotSame(c4, rm3); // assert the parsed objects is not from the
// cache
assertEquals(c4.getAuthor(), rm4.getAuthorIdent()); assertEquals(c4.getAuthor(), rm4.getAuthorIdent());
assertEquals(actid4, rm4.getId()); assertEquals(actid4, rm4.getId());
assertEquals(c4.getMessage(), rm4.getFullMessage()); assertEquals(c4.getMessage(), rm4.getFullMessage());
@ -609,7 +627,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
assertEquals(actid3, rm4.getParent(2)); assertEquals(actid3, rm4.getParent(2));
} }
public void test027_UnpackedRefHigherPriorityThanPacked() throws IOException { public void test027_UnpackedRefHigherPriorityThanPacked()
throws IOException {
String unpackedId = "7f822839a2fe9760f386cbbbcb3f92c5fe81def7"; String unpackedId = "7f822839a2fe9760f386cbbbcb3f92c5fe81def7";
write(new File(db.getDirectory(), "refs/heads/a"), unpackedId + "\n"); write(new File(db.getDirectory(), "refs/heads/a"), unpackedId + "\n");
@ -618,7 +637,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
} }
public void test028_LockPackedRef() throws IOException { public void test028_LockPackedRef() throws IOException {
writeTrashFile(".git/packed-refs", "7f822839a2fe9760f386cbbbcb3f92c5fe81def7 refs/heads/foobar"); writeTrashFile(".git/packed-refs",
"7f822839a2fe9760f386cbbbcb3f92c5fe81def7 refs/heads/foobar");
writeTrashFile(".git/HEAD", "ref: refs/heads/foobar\n"); writeTrashFile(".git/HEAD", "ref: refs/heads/foobar\n");
BUG_WorkAroundRacyGitIssues("packed-refs"); BUG_WorkAroundRacyGitIssues("packed-refs");
BUG_WorkAroundRacyGitIssues("HEAD"); BUG_WorkAroundRacyGitIssues("HEAD");
@ -627,7 +647,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
assertEquals("7f822839a2fe9760f386cbbbcb3f92c5fe81def7", resolve.name()); assertEquals("7f822839a2fe9760f386cbbbcb3f92c5fe81def7", resolve.name());
RefUpdate lockRef = db.updateRef("HEAD"); RefUpdate lockRef = db.updateRef("HEAD");
ObjectId newId = ObjectId.fromString("07f822839a2fe9760f386cbbbcb3f92c5fe81def"); ObjectId newId = ObjectId
.fromString("07f822839a2fe9760f386cbbbcb3f92c5fe81def");
lockRef.setNewObjectId(newId); lockRef.setNewObjectId(newId);
assertEquals(RefUpdate.Result.FORCED, lockRef.forceUpdate()); assertEquals(RefUpdate.Result.FORCED, lockRef.forceUpdate());
@ -636,7 +657,8 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
// Again. The ref already exists // Again. The ref already exists
RefUpdate lockRef2 = db.updateRef("HEAD"); RefUpdate lockRef2 = db.updateRef("HEAD");
ObjectId newId2 = ObjectId.fromString("7f822839a2fe9760f386cbbbcb3f92c5fe81def7"); ObjectId newId2 = ObjectId
.fromString("7f822839a2fe9760f386cbbbcb3f92c5fe81def7");
lockRef2.setNewObjectId(newId2); lockRef2.setNewObjectId(newId2);
assertEquals(RefUpdate.Result.FORCED, lockRef2.forceUpdate()); assertEquals(RefUpdate.Result.FORCED, lockRef2.forceUpdate());
@ -653,20 +675,26 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
File relBaseFile = new File(new File(relBase, "other"), "module.c"); File relBaseFile = new File(new File(relBase, "other"), "module.c");
File absBaseFile = new File(new File(absBase, "other"), "module.c"); File absBaseFile = new File(new File(absBase, "other"), "module.c");
assertEquals("other/module.c", Repository.stripWorkDir(relBase, relBaseFile)); assertEquals("other/module.c", Repository.stripWorkDir(relBase,
assertEquals("other/module.c", Repository.stripWorkDir(relBase, absBaseFile)); relBaseFile));
assertEquals("other/module.c", Repository.stripWorkDir(absBase, relBaseFile)); assertEquals("other/module.c", Repository.stripWorkDir(relBase,
assertEquals("other/module.c", Repository.stripWorkDir(absBase, absBaseFile)); absBaseFile));
assertEquals("other/module.c", Repository.stripWorkDir(absBase,
relBaseFile));
assertEquals("other/module.c", Repository.stripWorkDir(absBase,
absBaseFile));
File relNonFile = new File(new File(relCwd, "not-repo"), ".gitignore"); File relNonFile = new File(new File(relCwd, "not-repo"), ".gitignore");
File absNonFile = new File(new File(absCwd, "not-repo"), ".gitignore"); File absNonFile = new File(new File(absCwd, "not-repo"), ".gitignore");
assertEquals("", Repository.stripWorkDir(relBase, relNonFile)); assertEquals("", Repository.stripWorkDir(relBase, relNonFile));
assertEquals("", Repository.stripWorkDir(absBase, absNonFile)); assertEquals("", Repository.stripWorkDir(absBase, absNonFile));
assertEquals("", Repository.stripWorkDir(db.getWorkTree(), db.getWorkTree())); assertEquals("", Repository.stripWorkDir(db.getWorkTree(), db
.getWorkTree()));
File file = new File(new File(db.getWorkTree(), "subdir"), "File.java"); File file = new File(new File(db.getWorkTree(), "subdir"), "File.java");
assertEquals("subdir/File.java", Repository.stripWorkDir(db.getWorkTree(), file)); assertEquals("subdir/File.java", Repository.stripWorkDir(db
.getWorkTree(), file));
} }
@ -693,8 +721,19 @@ public class T0003_Basic extends SampleDataRepositoryTestCase {
} }
} }
private ObjectId insertCommit(final CommitBuilder builder) throws IOException, private ObjectId insertTree(TreeFormatter tree) throws IOException {
UnsupportedEncodingException { ObjectInserter oi = db.newObjectInserter();
try {
ObjectId id = oi.insert(tree);
oi.flush();
return id;
} finally {
oi.release();
}
}
private ObjectId insertCommit(final CommitBuilder builder)
throws IOException, UnsupportedEncodingException {
ObjectInserter oi = db.newObjectInserter(); ObjectInserter oi = db.newObjectInserter();
try { try {
ObjectId id = oi.insert(builder); ObjectId id = oi.insert(builder);

Loading…
Cancel
Save