Browse Source

Merge branch 'stable-4.2'

* stable-4.2:
  NoteMapTest: Open TreeWalk instances in try-with-resource
  ObjectDirectoryTest: Fix warnings about variable hiding
  PackWriterTest: Open RevWalk in try-with-resource
  PatchIdDiffFormatterTest: Open Git and PatchIdDiffFormatter in try-with-resource
  PathSuffixFilterTest: Open TreeWalk in try-with-resource
  PostOrderTreeWalkTest: Open TreeWalk in try-with-resource
  PullCommandWithRebaseTest: Open RevWalk in try-with-resource
  PushCommandTest: Open Git instances in try-with-resource
  RacyGitTests: Open NameConflictTreeWalk in try-with-resource
  RecursiveMergerTest: Open TreeWalk and BufferedReader in try-with-resource
  ReflogConfigTest: refactor commit method to avoid variable hiding
  Update .mailmap
  RefDirectoryTest: Fix warning about member variable hiding
  ReflogResolveTest: Open Git instances in try-with-resource
  ReflogTest: Open Git instances in try-with-resource
  RepoCommandTest: Open Git instances in try-with-resource

Change-Id: I7964b699396629e31a9cc5600aedcf4be4e659a8
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.3
Matthias Sohn 9 years ago
parent
commit
4dcf34eddf
  1. 5
      .mailmap
  2. 7
      org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ReflogTest.java
  3. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java
  4. 39
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java
  5. 18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/PatchIdDiffFormatterTest.java
  6. 12
      org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java
  7. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java
  8. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java
  9. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java
  10. 14
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java
  11. 17
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogConfigTest.java
  12. 18
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogResolveTest.java
  13. 21
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java
  14. 12
      org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java
  15. 24
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java
  16. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java

5
.mailmap

@ -1,5 +1,6 @@
Roberto Tyley <roberto.tyley@guardian.co.uk> roberto <roberto.tyley@guardian.co.uk>
Saša Živkov <sasa.zivkov@sap.com> Sasa Zivkov <sasa.zivkov@sap.com>
Saša Živkov <sasa.zivkov@sap.com> Saša Živkov <zivkov@gmail.com>
Shawn Pearce <spearce@spearce.org> Shawn O. Pearce <sop@google.com>
Shawn Pearce <spearce@spearce.org> Shawn Pearce <sop@google.com>
Shawn Pearce <spearce@spearce.org> Shawn O. Pearce <spearce@spearce.org>
Saša Živkov <sasa.zivkov@sap.com> Sasa Zivkov <sasa.zivkov@sap.com>
Saša Živkov <sasa.zivkov@sap.com> Saša Živkov <zivkov@gmail.com>

7
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/ReflogTest.java

@ -57,15 +57,17 @@ public class ReflogTest extends CLIRepositoryTestCase {
@Test
public void testSingleCommit() throws Exception {
new Git(db).commit().setMessage("initial commit").call();
try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call();
assertEquals("6fd41be HEAD@{0}: commit (initial): initial commit",
execute("git reflog")[0]);
}
}
@Test
public void testBranch() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
git.commit().setMessage("first commit").call();
git.checkout().setCreateBranch(true).setName("side").call();
writeTrashFile("file", "side content");
@ -77,4 +79,5 @@ public class ReflogTest extends CLIRepositoryTestCase {
"d216986 side@{1}: branch: Created from commit first commit",
"" }, execute("git reflog refs/heads/side"));
}
}
}

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandWithRebaseTest.java

@ -273,7 +273,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
// Get the HEAD and HEAD~1 commits
Repository targetRepo = target.getRepository();
RevWalk revWalk = new RevWalk(targetRepo);
try (RevWalk revWalk = new RevWalk(targetRepo)) {
ObjectId headId = targetRepo.resolve(Constants.HEAD);
RevCommit root = revWalk.parseCommit(headId);
revWalk.markStart(root);
@ -294,6 +294,7 @@ public class PullCommandWithRebaseTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, target
.getRepository().getRepositoryState());
}
}
@Override
@Before

39
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PushCommandTest.java

@ -90,7 +90,7 @@ public class PushCommandTest extends RepositoryTestCase {
remoteConfig.update(config);
config.save();
Git git1 = new Git(db);
try (Git git1 = new Git(db)) {
// create some refs via commits and tag
RevCommit commit = git1.commit().setMessage("initial commit").call();
Ref tagRef = git1.tag().setName("tag").call();
@ -111,6 +111,7 @@ public class PushCommandTest extends RepositoryTestCase {
assertEquals(tagRef.getObjectId(),
db2.resolve(tagRef.getObjectId().getName()));
}
}
@Test
public void testPrePushHook() throws JGitInternalException, IOException,
@ -132,7 +133,7 @@ public class PushCommandTest extends RepositoryTestCase {
+ hookOutput.toPath() + "\"\ncat - >>\"" + hookOutput.toPath()
+ "\"\nexit 0");
Git git1 = new Git(db);
try (Git git1 = new Git(db)) {
// create some refs via commits and tag
RevCommit commit = git1.commit().setMessage("initial commit").call();
@ -142,6 +143,7 @@ public class PushCommandTest extends RepositoryTestCase {
+ commit.getName() + " refs/heads/x "
+ ObjectId.zeroId().name(), read(hookOutput));
}
}
private File writeHookFile(final String name, final String data)
throws IOException {
@ -160,8 +162,7 @@ public class PushCommandTest extends RepositoryTestCase {
String branch = "refs/heads/master";
String trackingBranch = "refs/remotes/" + remote + "/master";
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit commit1 = git.commit().setMessage("Initial commit")
.call();
@ -200,6 +201,7 @@ public class PushCommandTest extends RepositoryTestCase {
assertEquals(commit2.getId(), db.resolve(trackingBranch));
assertEquals(commit2.getId(), db2.resolve(branch));
}
}
/**
* Check that pushes over file protocol lead to appropriate ref-updates.
@ -208,9 +210,8 @@ public class PushCommandTest extends RepositoryTestCase {
*/
@Test
public void testPushRefUpdate() throws Exception {
Git git = new Git(db);
Git git2 = new Git(createBareRepository());
try (Git git = new Git(db);
Git git2 = new Git(createBareRepository())) {
final StoredConfig config = git.getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
URIish uri = new URIish(git2.getRepository().getDirectory().toURI()
@ -232,7 +233,6 @@ public class PushCommandTest extends RepositoryTestCase {
git.branchCreate().setName("refs/heads/test").call();
git.checkout().setName("refs/heads/test").call();
for (int i = 0; i < 6; i++) {
writeTrashFile("f" + i, "content of f" + i);
git.add().addFilepattern("f" + i).call();
@ -241,7 +241,7 @@ public class PushCommandTest extends RepositoryTestCase {
git2.getRepository().getAllRefs();
assertEquals("failed to update on attempt " + i, commit.getId(),
git2.getRepository().resolve("refs/heads/test"));
}
}
}
@ -252,9 +252,8 @@ public class PushCommandTest extends RepositoryTestCase {
*/
@Test
public void testPushWithRefSpecFromConfig() throws Exception {
Git git = new Git(db);
Git git2 = new Git(createBareRepository());
try (Git git = new Git(db);
Git git2 = new Git(createBareRepository())) {
final StoredConfig config = git.getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
URIish uri = new URIish(git2.getRepository().getDirectory().toURI()
@ -272,8 +271,7 @@ public class PushCommandTest extends RepositoryTestCase {
git.push().setRemote("test").call();
assertEquals(commit.getId(),
git2.getRepository().resolve("refs/heads/newbranch"));
}
}
/**
@ -283,9 +281,8 @@ public class PushCommandTest extends RepositoryTestCase {
*/
@Test
public void testPushWithoutPushRefSpec() throws Exception {
Git git = new Git(db);
Git git2 = new Git(createBareRepository());
try (Git git = new Git(db);
Git git2 = new Git(createBareRepository())) {
final StoredConfig config = git.getRepository().getConfig();
RemoteConfig remoteConfig = new RemoteConfig(config, "test");
URIish uri = new URIish(git2.getRepository().getDirectory().toURI()
@ -314,7 +311,7 @@ public class PushCommandTest extends RepositoryTestCase {
assertEquals(null, git2.getRepository()
.resolve("refs/heads/not-pushed"));
assertEquals(null, git2.getRepository().resolve("refs/heads/master"));
}
}
/**
@ -335,9 +332,8 @@ public class PushCommandTest extends RepositoryTestCase {
remoteConfig.update(config);
config.save();
Git git1 = new Git(db);
Git git2 = new Git(db2);
try (Git git1 = new Git(db);
Git git2 = new Git(db2)) {
// push master (with a new commit) to the remote
git1.commit().setMessage("initial commit").call();
@ -382,4 +378,5 @@ public class PushCommandTest extends RepositoryTestCase {
assertEquals(commit3.getId(),
db2.resolve(commit3.getId().getName() + "^{commit}"));
}
}
}

18
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/PatchIdDiffFormatterTest.java

@ -61,12 +61,12 @@ public class PatchIdDiffFormatterTest extends RepositoryTestCase {
File folder = new File(db.getDirectory().getParent(), "folder");
folder.mkdir();
write(new File(folder, "folder.txt"), "folder");
Git git = new Git(db);
try (Git git = new Git(db);
PatchIdDiffFormatter df = new PatchIdDiffFormatter()) {
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit").call();
write(new File(folder, "folder.txt"), "folder change");
PatchIdDiffFormatter df = new PatchIdDiffFormatter();
df.setRepository(db);
df.setPathFilter(PathFilter.create("folder"));
DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
@ -77,6 +77,7 @@ public class PatchIdDiffFormatterTest extends RepositoryTestCase {
assertEquals("1ff64e0f9333e9b81967c3e8d7a81362b14d5441", df
.getCalulatedPatchId().name());
}
}
@Test
public void testSameDiff() throws Exception {
@ -84,12 +85,12 @@ public class PatchIdDiffFormatterTest extends RepositoryTestCase {
File folder = new File(db.getDirectory().getParent(), "folder");
folder.mkdir();
write(new File(folder, "folder.txt"), "\n\n\n\nfolder");
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit").call();
write(new File(folder, "folder.txt"), "\n\n\n\nfolder change");
PatchIdDiffFormatter df = new PatchIdDiffFormatter();
try (PatchIdDiffFormatter df = new PatchIdDiffFormatter()) {
df.setRepository(db);
df.setPathFilter(PathFilter.create("folder"));
DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
@ -99,22 +100,25 @@ public class PatchIdDiffFormatterTest extends RepositoryTestCase {
assertEquals("08fca5ac531383eb1da8bf6b6f7cf44411281407", df
.getCalulatedPatchId().name());
}
write(new File(folder, "folder.txt"), "a\n\n\n\nfolder");
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit").call();
write(new File(folder, "folder.txt"), "a\n\n\n\nfolder change");
df = new PatchIdDiffFormatter();
try (PatchIdDiffFormatter df = new PatchIdDiffFormatter()) {
df.setRepository(db);
df.setPathFilter(PathFilter.create("folder"));
oldTree = new DirCacheIterator(db.readDirCache());
newTree = new FileTreeIterator(db);
DirCacheIterator oldTree = new DirCacheIterator(db.readDirCache());
FileTreeIterator newTree = new FileTreeIterator(db);
df.format(oldTree, newTree);
df.flush();
assertEquals("08fca5ac531383eb1da8bf6b6f7cf44411281407", df
.getCalulatedPatchId().name());
}
}
}
}

12
org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/RepoCommandTest.java

@ -82,7 +82,7 @@ public class RepoCommandTest extends RepositoryTestCase {
super.setUp();
defaultDb = createWorkRepository();
Git git = new Git(defaultDb);
try (Git git = new Git(defaultDb)) {
JGitTestUtil.writeTrashFile(defaultDb, "hello.txt", "branch world");
git.add().addFilepattern("hello.txt").call();
oldCommitId = git.commit().setMessage("Initial commit").call().getId();
@ -93,27 +93,31 @@ public class RepoCommandTest extends RepositoryTestCase {
git.add().addFilepattern("hello.txt").call();
git.commit().setMessage("Second commit").call();
addRepoToClose(defaultDb);
}
notDefaultDb = createWorkRepository();
git = new Git(notDefaultDb);
try (Git git = new Git(notDefaultDb)) {
JGitTestUtil.writeTrashFile(notDefaultDb, "world.txt", "hello");
git.add().addFilepattern("world.txt").call();
git.commit().setMessage("Initial commit").call();
addRepoToClose(notDefaultDb);
}
groupADb = createWorkRepository();
git = new Git(groupADb);
try (Git git = new Git(groupADb)) {
JGitTestUtil.writeTrashFile(groupADb, "a.txt", "world");
git.add().addFilepattern("a.txt").call();
git.commit().setMessage("Initial commit").call();
addRepoToClose(groupADb);
}
groupBDb = createWorkRepository();
git = new Git(groupBDb);
try (Git git = new Git(groupBDb)) {
JGitTestUtil.writeTrashFile(groupBDb, "b.txt", "world");
git.add().addFilepattern("b.txt").call();
git.commit().setMessage("Initial commit").call();
addRepoToClose(groupBDb);
}
resolveRelativeUris();
}

8
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/ObjectDirectoryTest.java

@ -62,18 +62,18 @@ public class ObjectDirectoryTest extends RepositoryTestCase {
throws Exception {
ExecutorService e = Executors.newCachedThreadPool();
for (int i=0; i < 100; ++i) {
ObjectDirectory db = createBareRepository().getObjectDatabase();
for (Future f : e.invokeAll(blobInsertersForTheSameFanOutDir(db))) {
ObjectDirectory dir = createBareRepository().getObjectDatabase();
for (Future f : e.invokeAll(blobInsertersForTheSameFanOutDir(dir))) {
f.get();
}
}
}
private Collection<Callable<ObjectId>> blobInsertersForTheSameFanOutDir(
final ObjectDirectory db) {
final ObjectDirectory dir) {
Callable<ObjectId> callable = new Callable<ObjectId>() {
public ObjectId call() throws Exception {
return db.newInserter().insert(Constants.OBJ_BLOB, new byte[0]);
return dir.newInserter().insert(Constants.OBJ_BLOB, new byte[0]);
}
};
return Collections.nCopies(4, callable);

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/PackWriterTest.java

@ -342,12 +342,13 @@ public class PackWriterTest extends SampleDataRepositoryTestCase {
ObjectId.fromString("902d5476fa249b7abc9d84c611577a81381f0327"),
ObjectId.fromString("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259"),
ObjectId.fromString("6ff87c4664981e4397625791c8ea3bbb5f2279a3") };
final RevWalk parser = new RevWalk(db);
try (final RevWalk parser = new RevWalk(db)) {
final RevObject forcedOrderRevs[] = new RevObject[forcedOrder.length];
for (int i = 0; i < forcedOrder.length; i++)
forcedOrderRevs[i] = parser.parseAny(forcedOrder[i]);
createVerifyOpenPack(Arrays.asList(forcedOrderRevs));
}
assertEquals(forcedOrder.length, writer.getObjectCount());
verifyObjectsOrder(forcedOrder);

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefDirectoryTest.java

@ -1444,8 +1444,8 @@ public class RefDirectoryTest extends LocalDiskRepositoryTestCase {
// empty
}
public void beginTask(String title, int totalWork) {
this.totalWork = totalWork;
public void beginTask(String title, int total) {
this.totalWork = total;
lastWork = 0;
}

14
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RacyGitTests.java

@ -82,7 +82,7 @@ public class RacyGitTests extends RepositoryTestCase {
}
FileTreeIteratorWithTimeControl fileIt = new FileTreeIteratorWithTimeControl(
db, modTimes);
NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
try (NameConflictTreeWalk tw = new NameConflictTreeWalk(db)) {
tw.addTree(fileIt);
tw.setRecursive(true);
FileTreeIterator t;
@ -90,11 +90,12 @@ public class RacyGitTests extends RepositoryTestCase {
for (int i = 0; i < 10; i++) {
assertTrue(tw.next());
t = tw.getTree(0, FileTreeIterator.class);
if (i == 0)
if (i == 0) {
t0 = t.getEntryLastModified();
else
} else {
assertEquals(t0, t.getEntryLastModified());
}
}
long t1 = 0;
for (int i = 0; i < 10; i++) {
assertTrue(tw.next());
@ -102,9 +103,10 @@ public class RacyGitTests extends RepositoryTestCase {
if (i == 0) {
t1 = t.getEntryLastModified();
assertTrue(t1 > t0);
} else
} else {
assertEquals(t1, t.getEntryLastModified());
}
}
long t2 = 0;
for (int i = 0; i < 10; i++) {
assertTrue(tw.next());
@ -112,10 +114,12 @@ public class RacyGitTests extends RepositoryTestCase {
if (i == 0) {
t2 = t.getEntryLastModified();
assertTrue(t2 > t1);
} else
} else {
assertEquals(t2, t.getEntryLastModified());
}
}
}
}
public void testRacyGitDetection() throws IOException,
IllegalStateException, InterruptedException {

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

@ -70,8 +70,7 @@ public class ReflogConfigTest extends RepositoryTestCase {
// do one commit and check that reflog size is 0: no reflogs should be
// written
commit("A Commit\n", new PersonIdent(author, commitTime, tz),
new PersonIdent(committer, commitTime, tz));
commit("A Commit\n", commitTime, tz);
commitTime += 60 * 1000;
assertTrue(
"Reflog for HEAD still contain no entry",
@ -83,8 +82,7 @@ public class ReflogConfigTest extends RepositoryTestCase {
assertTrue(cfg.get(CoreConfig.KEY).isLogAllRefUpdates());
// do one commit and check that reflog size is increased to 1
commit("A Commit\n", new PersonIdent(author, commitTime, tz),
new PersonIdent(committer, commitTime, tz));
commit("A Commit\n", commitTime, tz);
commitTime += 60 * 1000;
assertTrue(
"Reflog for HEAD should contain one entry",
@ -96,18 +94,17 @@ public class ReflogConfigTest extends RepositoryTestCase {
assertFalse(cfg.get(CoreConfig.KEY).isLogAllRefUpdates());
// do one commit and check that reflog size is 2
commit("A Commit\n", new PersonIdent(author, commitTime, tz),
new PersonIdent(committer, commitTime, tz));
commit("A Commit\n", commitTime, tz);
assertTrue(
"Reflog for HEAD should contain two entries",
db.getReflogReader(Constants.HEAD).getReverseEntries().size() == 2);
}
private void commit(String commitMsg, PersonIdent author,
PersonIdent committer) throws IOException {
private void commit(String commitMsg, long commitTime, int tz)
throws IOException {
final CommitBuilder commit = new CommitBuilder();
commit.setAuthor(author);
commit.setCommitter(committer);
commit.setAuthor(new PersonIdent(author, commitTime, tz));
commit.setCommitter(new PersonIdent(committer, commitTime, tz));
commit.setMessage(commitMsg);
ObjectId id;
try (ObjectInserter inserter = db.newObjectInserter()) {

18
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/ReflogResolveTest.java

@ -60,7 +60,7 @@ public class ReflogResolveTest extends RepositoryTestCase {
@Test
public void resolveMasterCommits() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
RevCommit c1 = git.commit().setMessage("create file").call();
@ -71,10 +71,11 @@ public class ReflogResolveTest extends RepositoryTestCase {
assertEquals(c2, db.resolve("master@{0}"));
assertEquals(c1, db.resolve("master@{1}"));
}
}
@Test
public void resolveUnnamedCurrentBranchCommits() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
RevCommit c1 = git.commit().setMessage("create file").call();
@ -103,10 +104,11 @@ public class ReflogResolveTest extends RepositoryTestCase {
assertEquals(c1, db.resolve("@{1}"));
assertEquals(c2, db.resolve("@{2}"));
}
}
@Test
public void resolveReflogParent() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
RevCommit c1 = git.commit().setMessage("create file").call();
@ -116,19 +118,21 @@ public class ReflogResolveTest extends RepositoryTestCase {
assertEquals(c1, db.resolve("master@{0}~1"));
}
}
@Test
public void resolveNonExistingBranch() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
git.commit().setMessage("create file").call();
assertNull(db.resolve("notabranch@{7}"));
}
}
@Test
public void resolvePreviousBranch() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
RevCommit c1 = git.commit().setMessage("create file").call();
@ -159,10 +163,11 @@ public class ReflogResolveTest extends RepositoryTestCase {
assertEquals(c2.getName(), db.resolve("@{-3}@{0}").getName());
}
}
@Test
public void resolveDate() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
git.commit().setMessage("create file").call();
@ -173,4 +178,5 @@ public class ReflogResolveTest extends RepositoryTestCase {
assertNotNull(e);
}
}
}
}

21
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/RecursiveMergerTest.java

@ -872,32 +872,31 @@ public class RecursiveMergerTest extends RepositoryTestCase {
private String contentAsString(Repository r, ObjectId treeId, String path)
throws MissingObjectException, IOException {
TreeWalk tw = new TreeWalk(r);
AnyObjectId blobId;
try (TreeWalk tw = new TreeWalk(r)) {
tw.addTree(treeId);
tw.setFilter(PathFilter.create(path));
tw.setRecursive(true);
if (!tw.next())
if (!tw.next()) {
return null;
AnyObjectId blobId = tw.getObjectId(0);
}
blobId = tw.getObjectId(0);
}
StringBuilder result = new StringBuilder();
BufferedReader br = null;
ObjectReader or = r.newObjectReader();
try {
br = new BufferedReader(new InputStreamReader(or.open(blobId)
.openStream()));
try (BufferedReader br = new BufferedReader(
new InputStreamReader(or.open(blobId).openStream()))) {
String line;
boolean first = true;
while ((line = br.readLine()) != null) {
if (!first)
if (!first) {
result.append('\n');
}
result.append(line);
first = false;
}
return result.toString();
} finally {
if (br != null)
br.close();
}
}
}

12
org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java

@ -403,10 +403,12 @@ public class NoteMapTest extends RepositoryTestCase {
}
RevCommit n = commitNoteMap(map);
TreeWalk tw = new TreeWalk(reader);
try (TreeWalk tw = new TreeWalk(reader)) {
tw.reset(n.getTree());
while (tw.next())
while (tw.next()) {
assertFalse("no fan-out subtree", tw.isSubtree());
}
}
for (int i = 254; i < 256; i++) {
idBuf.setByte(Constants.OBJECT_ID_LENGTH - 1, i);
@ -418,14 +420,16 @@ public class NoteMapTest extends RepositoryTestCase {
// The 00 bucket is fully split.
String path = fanout(38, idBuf.name());
tw = TreeWalk.forPath(reader, path, n.getTree());
try (TreeWalk tw = TreeWalk.forPath(reader, path, n.getTree())) {
assertNotNull("has " + path, tw);
}
// The other bucket is not.
path = fanout(2, data1.name());
tw = TreeWalk.forPath(reader, path, n.getTree());
try (TreeWalk tw = TreeWalk.forPath(reader, path, n.getTree())) {
assertNotNull("has " + path, tw);
}
}
@Test
public void testRemoveDeletesTreeFanout2_38() throws Exception {

24
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/PostOrderTreeWalkTest.java

@ -60,23 +60,25 @@ import org.junit.Test;
public class PostOrderTreeWalkTest extends RepositoryTestCase {
@Test
public void testInitialize_NoPostOrder() throws Exception {
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
assertFalse(tw.isPostOrderTraversal());
}
}
@Test
public void testInitialize_TogglePostOrder() throws Exception {
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
assertFalse(tw.isPostOrderTraversal());
tw.setPostOrderTraversal(true);
assertTrue(tw.isPostOrderTraversal());
tw.setPostOrderTraversal(false);
assertFalse(tw.isPostOrderTraversal());
}
}
@Test
public void testResetDoesNotAffectPostOrder() throws Exception {
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setPostOrderTraversal(true);
assertTrue(tw.isPostOrderTraversal());
tw.reset();
@ -87,11 +89,11 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
tw.reset();
assertFalse(tw.isPostOrderTraversal());
}
}
@Test
public void testNoPostOrder() throws Exception {
final DirCache tree = db.readDirCache();
{
final DirCacheBuilder b = tree.builder();
b.add(makeFile("a"));
@ -101,9 +103,8 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
b.finish();
assertEquals(4, tree.getEntryCount());
}
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setPostOrderTraversal(false);
tw.addTree(new DirCacheIterator(tree));
@ -116,11 +117,11 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
assertModes("b/d", REGULAR_FILE, tw);
assertModes("q", REGULAR_FILE, tw);
}
}
@Test
public void testWithPostOrder_EnterSubtree() throws Exception {
final DirCache tree = db.readDirCache();
{
final DirCacheBuilder b = tree.builder();
b.add(makeFile("a"));
@ -130,9 +131,8 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
b.finish();
assertEquals(4, tree.getEntryCount());
}
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setPostOrderTraversal(true);
tw.addTree(new DirCacheIterator(tree));
@ -151,11 +151,11 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
assertModes("q", REGULAR_FILE, tw);
}
}
@Test
public void testWithPostOrder_NoEnterSubtree() throws Exception {
final DirCache tree = db.readDirCache();
{
final DirCacheBuilder b = tree.builder();
b.add(makeFile("a"));
@ -165,9 +165,8 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
b.finish();
assertEquals(4, tree.getEntryCount());
}
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setPostOrderTraversal(true);
tw.addTree(new DirCacheIterator(tree));
@ -179,6 +178,7 @@ public class PostOrderTreeWalkTest extends RepositoryTestCase {
assertModes("q", REGULAR_FILE, tw);
}
}
private DirCacheEntry makeFile(final String path) throws Exception {
return createEntry(path, REGULAR_FILE);

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/PathSuffixFilterTest.java

@ -113,7 +113,7 @@ public class PathSuffixFilterTest extends RepositoryTestCase {
private List<String> getMatchingPaths(String suffixFilter,
final ObjectId treeId, boolean recursiveWalk) throws IOException {
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setFilter(PathSuffixFilter.create(suffixFilter));
tw.setRecursive(recursiveWalk);
tw.addTree(treeId);
@ -123,5 +123,6 @@ public class PathSuffixFilterTest extends RepositoryTestCase {
paths.add(tw.getPathString());
return paths;
}
}
}

Loading…
Cancel
Save