Browse Source

Merge branch 'stable-4.2'

* stable-4.2:
  FileTreeIteratorTest: Open Git and RevWalk in try-with-resource
  RebaseCommandTest: Open RevWalk in try-with-resource
  PullCommandTest: Open RevWalk in try-with-resource
  BlameGeneratorTest: Create Git instances in try-with-resource
  Remove unnecessary suppression of deprecation warnings in tests
  DiffEntryTest: Open Git and TreeWalk in try-with-resource
  DiffCommandTest: Open Git and RevWalk in try-with-resource
  CommitCommandTest: Open Git and TreeWalk in try-with-resource

Change-Id: Ic886ec9b1a4b3b46f9fa14188b4df832ce36cfa6
Signed-off-by: David Pursehouse <david.pursehouse@sonymobile.com>
stable-4.3
David Pursehouse 9 years ago
parent
commit
27a6a52654
  1. 38
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java
  2. 29
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DiffCommandTest.java
  3. 15
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java
  4. 64
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java
  5. 11
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/blame/BlameGeneratorTest.java
  6. 55
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java
  7. 1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
  8. 1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
  9. 1
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectWalkTest.java
  10. 39
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java

38
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/CommitCommandTest.java

@ -186,7 +186,7 @@ public class CommitCommandTest extends RepositoryTestCase {
@Test
public void commitNewSubmodule() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
RevCommit commit = git.commit().setMessage("create file").call();
@ -215,7 +215,7 @@ public class CommitCommandTest extends RepositoryTestCase {
RevCommit submoduleCommit = git.commit().setMessage("submodule add")
.setOnly(path).call();
assertNotNull(submoduleCommit);
TreeWalk walk = new TreeWalk(db);
try (TreeWalk walk = new TreeWalk(db)) {
walk.addTree(commit.getTree());
walk.addTree(submoduleCommit.getTree());
walk.setFilter(TreeFilter.ANY_DIFF);
@ -228,10 +228,12 @@ public class CommitCommandTest extends RepositoryTestCase {
assertEquals(commit, subDiff.getNewId().toObjectId());
assertEquals(path, subDiff.getNewPath());
}
}
}
@Test
public void commitSubmoduleUpdate() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
RevCommit commit = git.commit().setMessage("create file").call();
@ -271,7 +273,7 @@ public class CommitCommandTest extends RepositoryTestCase {
RevCommit submoduleEditCommit = git.commit()
.setMessage("submodule add").setOnly(path).call();
assertNotNull(submoduleEditCommit);
TreeWalk walk = new TreeWalk(db);
try (TreeWalk walk = new TreeWalk(db)) {
walk.addTree(submoduleAddCommit.getTree());
walk.addTree(submoduleEditCommit.getTree());
walk.setFilter(TreeFilter.ANY_DIFF);
@ -285,11 +287,12 @@ public class CommitCommandTest extends RepositoryTestCase {
assertEquals(path, subDiff.getNewPath());
assertEquals(path, subDiff.getOldPath());
}
}
}
@Test
public void commitUpdatesSmudgedEntries() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
File file1 = writeTrashFile("file1.txt", "content1");
assertTrue(file1.setLastModified(file1.lastModified() - 5000));
File file2 = writeTrashFile("file2.txt", "content2");
@ -341,11 +344,11 @@ public class CommitCommandTest extends RepositoryTestCase {
assertEquals(file2Id, cache.getEntry("file2.txt").getObjectId());
assertEquals(file3Id, cache.getEntry("file3.txt").getObjectId());
}
}
@Test
public void commitIgnoresSmudgedEntryWithDifferentId() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
File file1 = writeTrashFile("file1.txt", "content1");
assertTrue(file1.setLastModified(file1.lastModified() - 5000));
File file2 = writeTrashFile("file2.txt", "content2");
@ -391,11 +394,11 @@ public class CommitCommandTest extends RepositoryTestCase {
assertEquals(file1Size, cache.getEntry("file1.txt").getLength());
assertEquals(0, cache.getEntry("file2.txt").getLength());
}
}
@Test
public void commitAfterSquashMerge() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("initial commit").call();
@ -431,18 +434,19 @@ public class CommitCommandTest extends RepositoryTestCase {
assertEquals("commit: Squashed commit of the following:", db
.getReflogReader(db.getBranch()).getLastEntry().getComment());
}
}
@Test(expected = WrongRepositoryStateException.class)
public void commitAmendOnInitialShouldFail() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
git.commit().setAmend(true).setMessage("initial commit").call();
}
}
@Test
public void commitAmendWithoutAuthorShouldSetOriginalAuthorAndAuthorTime()
throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call();
@ -461,11 +465,11 @@ public class CommitCommandTest extends RepositoryTestCase {
assertEquals(authorEmail, amendedAuthor.getEmailAddress());
assertEquals(authorDate.getTime(), amendedAuthor.getWhen().getTime());
}
}
@Test
public void commitAmendWithAuthorShouldUseIt() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call();
git.commit().setMessage("initial commit").call();
@ -478,6 +482,7 @@ public class CommitCommandTest extends RepositoryTestCase {
assertEquals("New Author", amendedAuthor.getName());
assertEquals("newauthor@example.org", amendedAuthor.getEmailAddress());
}
}
@Test
public void commitEmptyCommits() throws Exception {
@ -532,7 +537,7 @@ public class CommitCommandTest extends RepositoryTestCase {
+ "[unmerged2, mode:100644, stage:3]",
indexState(0));
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit commit = git.commit().setOnly("unmerged1")
.setMessage("Only one file").call();
@ -546,6 +551,7 @@ public class CommitCommandTest extends RepositoryTestCase {
assertEquals(FileMode.REGULAR_FILE, walk.getFileMode(0));
}
}
}
@Test
public void commitOnlyShouldHandleIgnored() throws Exception {

29
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/DiffCommandTest.java

@ -70,7 +70,7 @@ public class DiffCommandTest extends RepositoryTestCase {
File folder = new File(db.getWorkTree(), "folder");
folder.mkdir();
write(new File(folder, "folder.txt"), "folder");
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"), "folder change");
@ -97,13 +97,14 @@ public class DiffCommandTest extends RepositoryTestCase {
+ "\\ No newline at end of file\n";
assertEquals(expected.toString(), actual);
}
}
@Test
public void testDiffCached() throws Exception {
write(new File(db.getWorkTree(), "test.txt"), "test");
File folder = new File(db.getWorkTree(), "folder");
folder.mkdir();
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"), "folder");
@ -131,6 +132,7 @@ public class DiffCommandTest extends RepositoryTestCase {
+ "\\ No newline at end of file\n";
assertEquals(expected.toString(), actual);
}
}
@Test
public void testDiffTwoCommits() throws Exception {
@ -138,7 +140,7 @@ public class DiffCommandTest extends RepositoryTestCase {
File folder = new File(db.getWorkTree(), "folder");
folder.mkdir();
write(new File(folder, "folder.txt"), "folder");
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"), "folder change");
@ -179,19 +181,19 @@ public class DiffCommandTest extends RepositoryTestCase {
+ "\\ No newline at end of file\n";
assertEquals(expected.toString(), actual);
}
}
@Test
public void testDiffWithPrefixes() throws Exception {
write(new File(db.getWorkTree(), "test.txt"), "test");
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit").call();
write(new File(db.getWorkTree(), "test.txt"), "test change");
OutputStream out = new ByteArrayOutputStream();
git.diff().setOutputStream(out).setSourcePrefix("old/")
.setDestinationPrefix("new/")
.call();
.setDestinationPrefix("new/").call();
String actual = out.toString();
String expected = "diff --git old/test.txt new/test.txt\n"
@ -201,20 +203,20 @@ public class DiffCommandTest extends RepositoryTestCase {
+ "\\ No newline at end of file\n";
assertEquals(expected.toString(), actual);
}
}
@Test
public void testDiffWithNegativeLineCount() throws Exception {
write(new File(db.getWorkTree(), "test.txt"),
"0\n1\n2\n3\n4\n5\n6\n7\n8\n9");
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern(".").call();
git.commit().setMessage("Initial commit").call();
write(new File(db.getWorkTree(), "test.txt"),
"0\n1\n2\n3\n4a\n5\n6\n7\n8\n9");
OutputStream out = new ByteArrayOutputStream();
git.diff().setOutputStream(out).setContextLines(1)
.call();
git.diff().setOutputStream(out).setContextLines(1).call();
String actual = out.toString();
String expected = "diff --git a/test.txt b/test.txt\n"
@ -223,12 +225,13 @@ public class DiffCommandTest extends RepositoryTestCase {
+ "+4a\n" + " 5\n";
assertEquals(expected.toString(), actual);
}
}
@Test
public void testNoOutputStreamSet() throws Exception {
File file = writeTrashFile("test.txt", "a");
assertTrue(file.setLastModified(file.lastModified() - 5000));
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern(".").call();
write(file, "b");
@ -240,6 +243,7 @@ public class DiffCommandTest extends RepositoryTestCase {
assertEquals("test.txt", diff.getOldPath());
assertEquals("test.txt", diff.getNewPath());
}
}
private AbstractTreeIterator getTreeIterator(String name)
throws IOException {
@ -247,8 +251,9 @@ public class DiffCommandTest extends RepositoryTestCase {
if (id == null)
throw new IllegalArgumentException(name);
final CanonicalTreeParser p = new CanonicalTreeParser();
try (ObjectReader or = db.newObjectReader()) {
p.reset(or, new RevWalk(db).parseTree(id));
try (ObjectReader or = db.newObjectReader();
RevWalk rw = new RevWalk(db)) {
p.reset(or, rw.parseTree(id));
return p;
}
}

15
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/PullCommandTest.java

@ -140,12 +140,13 @@ public class PullCommandTest extends RepositoryTestCase {
ObjectId[] mergedCommits = mergeResult.getMergedCommits();
assertEquals(targetCommit.getId(), mergedCommits[0]);
assertEquals(sourceCommit.getId(), mergedCommits[1]);
RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult
.getNewHead());
try (RevWalk rw = new RevWalk(dbTarget)) {
RevCommit mergeCommit = rw.parseCommit(mergeResult.getNewHead());
String message = "Merge branch 'master' of "
+ db.getWorkTree().getAbsolutePath();
assertEquals(message, mergeCommit.getShortMessage());
}
}
@Test
public void testPullConflict() throws Exception {
@ -259,12 +260,13 @@ public class PullCommandTest extends RepositoryTestCase {
ObjectId[] mergedCommits = mergeResult.getMergedCommits();
assertEquals(targetCommit.getId(), mergedCommits[0]);
assertEquals(sourceCommit.getId(), mergedCommits[1]);
RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult
.getNewHead());
try (RevWalk rw = new RevWalk(dbTarget)) {
RevCommit mergeCommit = rw.parseCommit(mergeResult.getNewHead());
String message = "Merge branch 'other' of "
+ db.getWorkTree().getAbsolutePath();
assertEquals(message, mergeCommit.getShortMessage());
}
}
@Test
public void testPullMergeProgrammaticConfigurationImpliedTargetBranch()
@ -293,12 +295,13 @@ public class PullCommandTest extends RepositoryTestCase {
ObjectId[] mergedCommits = mergeResult.getMergedCommits();
assertEquals(targetCommit.getId(), mergedCommits[0]);
assertEquals(sourceCommit.getId(), mergedCommits[1]);
RevCommit mergeCommit = new RevWalk(dbTarget).parseCommit(mergeResult
.getNewHead());
try (RevWalk rw = new RevWalk(dbTarget)) {
RevCommit mergeCommit = rw.parseCommit(mergeResult.getNewHead());
String message = "Merge branch 'other' of "
+ db.getWorkTree().getAbsolutePath() + " into other";
assertEquals(message, mergeCommit.getShortMessage());
}
}
private enum TestPullMode {
MERGE, REBASE, REBASE_PREASERVE

64
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RebaseCommandTest.java

@ -288,13 +288,14 @@ public class RebaseCommandTest extends RepositoryTestCase {
RebaseResult res = git.rebase().setUpstream("refs/heads/master").call();
assertEquals(Status.OK, res.getStatus());
RevWalk rw = new RevWalk(db);
try (RevWalk rw = new RevWalk(db)) {
rw.markStart(rw.parseCommit(db.resolve("refs/heads/topic")));
assertDerivedFrom(rw.next(), e);
assertDerivedFrom(rw.next(), d);
assertDerivedFrom(rw.next(), c);
assertEquals(b, rw.next());
assertEquals(a, rw.next());
}
List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
.getReverseEntries();
@ -354,8 +355,6 @@ public class RebaseCommandTest extends RepositoryTestCase {
*/
private void doTestRebasePreservingMerges(boolean testConflict)
throws Exception {
RevWalk rw = new RevWalk(db);
// create file1 on master
writeTrashFile(FILE1, FILE1);
git.add().addFilepattern(FILE1).call();
@ -409,8 +408,10 @@ public class RebaseCommandTest extends RepositoryTestCase {
f = git.commit().setMessage("commit f").call();
} else {
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
try (RevWalk rw = new RevWalk(db)) {
f = rw.parseCommit(result.getNewHead());
}
}
RebaseResult res = git.rebase().setUpstream("refs/heads/master")
.setPreserveMerges(true).call();
@ -453,6 +454,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals("file2", read("file2"));
assertEquals("more change", read("file3"));
try (RevWalk rw = new RevWalk(db)) {
rw.markStart(rw.parseCommit(db.resolve("refs/heads/topic")));
RevCommit newF = rw.next();
assertDerivedFrom(newF, f);
@ -471,6 +473,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(b, rw.next());
assertEquals(a, rw.next());
}
}
private String readFile(String path, RevCommit commit) throws IOException {
try (TreeWalk walk = TreeWalk.forPath(db, path, commit.getTree())) {
@ -517,7 +520,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
*/
private void doTestRebasePreservingMergesWithUnrelatedSide(
boolean testConflict) throws Exception {
RevWalk rw = new RevWalk(db);
try (RevWalk rw = new RevWalk(db)) {
rw.sort(RevSort.TOPO);
writeTrashFile(FILE1, FILE1);
@ -600,6 +603,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(b, rw.next());
assertEquals(a, rw.next());
}
}
@Test
public void testRebaseParentOntoHeadShouldBeUptoDate() throws Exception {
@ -687,8 +691,10 @@ public class RebaseCommandTest extends RepositoryTestCase {
checkFile(theFile, "1master\n2\n3\ntopic\n");
// our old branch should be checked out again
assertEquals("refs/heads/topic", db.getFullBranch());
assertEquals(lastMasterChange, new RevWalk(db).parseCommit(
try (RevWalk rw = new RevWalk(db)) {
assertEquals(lastMasterChange, rw.parseCommit(
db.resolve(Constants.HEAD)).getParent(0));
}
assertEquals(origHead, db.readOrigHead());
List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
.getReverseEntries();
@ -737,8 +743,10 @@ public class RebaseCommandTest extends RepositoryTestCase {
RebaseResult res = git.rebase().setUpstream("refs/heads/master").call();
assertEquals(Status.OK, res.getStatus());
checkFile(theFile, "1master\n2\n3\ntopic\n");
assertEquals(lastMasterChange, new RevWalk(db).parseCommit(
try (RevWalk rw = new RevWalk(db)) {
assertEquals(lastMasterChange, rw.parseCommit(
db.resolve(Constants.HEAD)).getParent(0));
}
List<ReflogEntry> headLog = db.getReflogReader(Constants.HEAD)
.getReverseEntries();
@ -785,8 +793,10 @@ public class RebaseCommandTest extends RepositoryTestCase {
// our old branch should be checked out again
assertEquals("refs/heads/file3", db.getFullBranch());
assertEquals(addFile2, new RevWalk(db).parseCommit(
try (RevWalk rw = new RevWalk(db)) {
assertEquals(addFile2, rw.parseCommit(
db.resolve(Constants.HEAD)).getParent(0));
}
checkoutBranch("refs/heads/file2");
assertTrue(new File(db.getWorkTree(), FILE1).exists());
@ -846,9 +856,10 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(res.getStatus(), Status.ABORTED);
assertEquals("refs/heads/topic", db.getFullBranch());
checkFile(FILE1, "1topic", "2", "3", "topic4");
RevWalk rw = new RevWalk(db);
assertEquals(lastTopicCommit, rw
.parseCommit(db.resolve(Constants.HEAD)));
try (RevWalk rw = new RevWalk(db)) {
assertEquals(lastTopicCommit,
rw.parseCommit(db.resolve(Constants.HEAD)));
}
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
// rebase- dir in .git must be deleted
@ -909,9 +920,10 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(res.getStatus(), Status.ABORTED);
assertEquals(lastTopicCommit.getName(), db.getFullBranch());
checkFile(FILE1, "1topic", "2", "3", "topic4");
RevWalk rw = new RevWalk(db);
try (RevWalk rw = new RevWalk(db)) {
assertEquals(lastTopicCommit,
rw.parseCommit(db.resolve(Constants.HEAD)));
}
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
// rebase- dir in .git must be deleted
@ -966,12 +978,13 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
ObjectId headId = db.resolve(Constants.HEAD);
RevWalk rw = new RevWalk(db);
try (RevWalk rw = new RevWalk(db)) {
RevCommit rc = rw.parseCommit(headId);
RevCommit parent = rw.parseCommit(rc.getParent(0));
assertEquals("change file1 in topic\n\nThis is conflicting", parent
.getFullMessage());
}
}
@Test
public void testStopOnConflictAndContinueWithNoDeltaToMaster()
@ -1017,10 +1030,11 @@ public class RebaseCommandTest extends RepositoryTestCase {
git.rebase().setOperation(Operation.SKIP).call();
ObjectId headId = db.resolve(Constants.HEAD);
RevWalk rw = new RevWalk(db);
try (RevWalk rw = new RevWalk(db)) {
RevCommit rc = rw.parseCommit(headId);
assertEquals("change file1 in master", rc.getFullMessage());
}
}
@Test
public void testStopOnConflictAndFailContinueIfFileIsDirty()
@ -1308,11 +1322,12 @@ public class RebaseCommandTest extends RepositoryTestCase {
git.rebase().setOperation(Operation.SKIP).call();
ObjectId headId = db.resolve(Constants.HEAD);
RevWalk rw = new RevWalk(db);
try (RevWalk rw = new RevWalk(db)) {
RevCommit rc = rw.parseCommit(headId);
RevCommit parent = rw.parseCommit(rc.getParent(0));
assertEquals("A different commit message", parent.getFullMessage());
}
}
private RevCommit writeFileAndCommit(String fileName, String commitMessage,
String... lines) throws Exception {
@ -1420,9 +1435,10 @@ public class RebaseCommandTest extends RepositoryTestCase {
res = git.rebase().setOperation(Operation.ABORT).call();
assertEquals(res.getStatus(), Status.ABORTED);
assertEquals("refs/heads/topic", db.getFullBranch());
RevWalk rw = new RevWalk(db);
try (RevWalk rw = new RevWalk(db)) {
assertEquals(conflicting, rw.parseCommit(db.resolve(Constants.HEAD)));
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
}
// rebase- dir in .git must be deleted
assertFalse(new File(db.getDirectory(), "rebase-merge").exists());
@ -2286,7 +2302,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(RebaseResult.Status.OK, res2.getStatus());
ObjectId headId = db.resolve(Constants.HEAD);
RevWalk rw = new RevWalk(db);
try (RevWalk rw = new RevWalk(db)) {
RevCommit rc = rw.parseCommit(headId);
ObjectId head1Id = db.resolve(Constants.HEAD + "~1");
@ -2295,6 +2311,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals(rc.getFullMessage(), c4.getFullMessage());
assertEquals(rc1.getFullMessage(), c2.getFullMessage());
}
}
@Test
public void testParseRewordCommand() throws Exception {
@ -2643,7 +2660,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
}
}).call();
RevWalk walk = new RevWalk(db);
try (RevWalk walk = new RevWalk(db)) {
ObjectId headId = db.resolve(Constants.HEAD);
RevCommit headCommit = walk.parseCommit(headId);
assertEquals(headCommit.getFullMessage(),
@ -2653,6 +2670,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
RevCommit head1Commit = walk.parseCommit(head2Id);
assertEquals("changed", head1Commit.getFullMessage());
}
}
@Test
public void testRebaseInteractiveMultipleSquash() throws Exception {
@ -2722,7 +2740,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
}
}).call();
RevWalk walk = new RevWalk(db);
try (RevWalk walk = new RevWalk(db)) {
ObjectId headId = db.resolve(Constants.HEAD);
RevCommit headCommit = walk.parseCommit(headId);
assertEquals(headCommit.getFullMessage(),
@ -2734,6 +2752,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
"Add file1\nnew line\nAdd file2\nnew line\nupdated file1 on master\nnew line",
head1Commit.getFullMessage());
}
}
@Test
public void testRebaseInteractiveMixedSquashAndFixup() throws Exception {
@ -2804,7 +2823,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
}
}).call();
RevWalk walk = new RevWalk(db);
try (RevWalk walk = new RevWalk(db)) {
ObjectId headId = db.resolve(Constants.HEAD);
RevCommit headCommit = walk.parseCommit(headId);
assertEquals(headCommit.getFullMessage(),
@ -2814,6 +2833,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
RevCommit head1Commit = walk.parseCommit(head2Id);
assertEquals("changed", head1Commit.getFullMessage());
}
}
@Test
public void testRebaseInteractiveSingleFixup() throws Exception {
@ -2855,7 +2875,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
}
}).call();
RevWalk walk = new RevWalk(db);
try (RevWalk walk = new RevWalk(db)) {
ObjectId headId = db.resolve(Constants.HEAD);
RevCommit headCommit = walk.parseCommit(headId);
assertEquals("update file2 on master\nnew line",
@ -2866,6 +2886,7 @@ public class RebaseCommandTest extends RepositoryTestCase {
assertEquals("Add file2\nnew line",
head1Commit.getFullMessage());
}
}
@Test
public void testRebaseInteractiveFixupWithBlankLines() throws Exception {
@ -2903,12 +2924,13 @@ public class RebaseCommandTest extends RepositoryTestCase {
}
}).call();
RevWalk walk = new RevWalk(db);
try (RevWalk walk = new RevWalk(db)) {
ObjectId headId = db.resolve(Constants.HEAD);
RevCommit headCommit = walk.parseCommit(headId);
assertEquals("Add file2",
headCommit.getFullMessage());
}
}
@Test(expected = InvalidRebaseStepException.class)
public void testRebaseInteractiveFixupFirstCommitShouldFail()

11
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/blame/BlameGeneratorTest.java

@ -58,8 +58,7 @@ import org.junit.Test;
public class BlameGeneratorTest extends RepositoryTestCase {
@Test
public void testBoundLineDelete() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
String[] content1 = new String[] { "first", "second" };
writeTrashFile("file.txt", join(content1));
git.add().addFilepattern("file.txt").call();
@ -95,10 +94,11 @@ public class BlameGeneratorTest extends RepositoryTestCase {
assertFalse(generator.next());
}
}
}
@Test
public void testRenamedBoundLineDelete() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
final String FILENAME_1 = "subdir/file1.txt";
final String FILENAME_2 = "subdir/file2.txt";
@ -162,11 +162,11 @@ public class BlameGeneratorTest extends RepositoryTestCase {
assertEquals(FILENAME_1, result.getSourcePath(2));
}
}
}
@Test
public void testLinesAllDeletedShortenedWalk() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
String[] content1 = new String[] { "first", "second", "third" };
writeTrashFile("file.txt", join(content1));
@ -195,6 +195,7 @@ public class BlameGeneratorTest extends RepositoryTestCase {
assertFalse(generator.next());
}
}
}
private static String join(String... lines) {
StringBuilder joined = new StringBuilder();

55
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffEntryTest.java

@ -77,12 +77,12 @@ public class DiffEntryTest extends RepositoryTestCase {
public void shouldListAddedFileInInitialCommit() throws Exception {
// given
writeTrashFile("a.txt", "content");
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
git.add().addFilepattern("a.txt").call();
RevCommit c = git.commit().setMessage("initial commit").call();
// when
TreeWalk walk = new TreeWalk(db);
walk.addTree(new EmptyTreeIterator());
walk.addTree(c.getTree());
List<DiffEntry> result = DiffEntry.scan(walk);
@ -96,18 +96,19 @@ public class DiffEntryTest extends RepositoryTestCase {
assertThat(entry.getNewPath(), is("a.txt"));
assertThat(entry.getOldPath(), is(DEV_NULL));
}
}
@Test
public void shouldListAddedFileBetweenTwoCommits() throws Exception {
// given
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
RevCommit c1 = git.commit().setMessage("initial commit").call();
writeTrashFile("a.txt", "content");
git.add().addFilepattern("a.txt").call();
RevCommit c2 = git.commit().setMessage("second commit").call();
// when
TreeWalk walk = new TreeWalk(db);
walk.addTree(c1.getTree());
walk.addTree(c2.getTree());
List<DiffEntry> result = DiffEntry.scan(walk);
@ -121,11 +122,13 @@ public class DiffEntryTest extends RepositoryTestCase {
assertThat(entry.getNewPath(), is("a.txt"));
assertThat(entry.getOldPath(), is(DEV_NULL));
}
}
@Test
public void shouldListModificationBetweenTwoCommits() throws Exception {
// given
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
File file = writeTrashFile("a.txt", "content");
git.add().addFilepattern("a.txt").call();
RevCommit c1 = git.commit().setMessage("initial commit").call();
@ -134,7 +137,6 @@ public class DiffEntryTest extends RepositoryTestCase {
.call();
// when
TreeWalk walk = new TreeWalk(db);
walk.addTree(c1.getTree());
walk.addTree(c2.getTree());
List<DiffEntry> result = DiffEntry.scan(walk);
@ -147,11 +149,13 @@ public class DiffEntryTest extends RepositoryTestCase {
assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
assertThat(entry.getNewPath(), is("a.txt"));
}
}
@Test
public void shouldListDeletionBetweenTwoCommits() throws Exception {
// given
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
File file = writeTrashFile("a.txt", "content");
git.add().addFilepattern("a.txt").call();
RevCommit c1 = git.commit().setMessage("initial commit").call();
@ -160,7 +164,6 @@ public class DiffEntryTest extends RepositoryTestCase {
.call();
// when
TreeWalk walk = new TreeWalk(db);
walk.addTree(c1.getTree());
walk.addTree(c2.getTree());
List<DiffEntry> result = DiffEntry.scan(walk);
@ -174,12 +177,14 @@ public class DiffEntryTest extends RepositoryTestCase {
assertThat(entry.getNewPath(), is(DEV_NULL));
assertThat(entry.getChangeType(), is(ChangeType.DELETE));
}
}
@Test
public void shouldListModificationInDirWithoutModifiedTrees()
throws Exception {
// given
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
File tree = new File(new File(db.getWorkTree(), "a"), "b");
FileUtils.mkdirs(tree);
File file = new File(tree, "c.txt");
@ -192,7 +197,6 @@ public class DiffEntryTest extends RepositoryTestCase {
.call();
// when
TreeWalk walk = new TreeWalk(db);
walk.addTree(c1.getTree());
walk.addTree(c2.getTree());
walk.setRecursive(true);
@ -206,11 +210,13 @@ public class DiffEntryTest extends RepositoryTestCase {
assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
assertThat(entry.getNewPath(), is("a/b/c.txt"));
}
}
@Test
public void shouldListModificationInDirWithModifiedTrees() throws Exception {
// given
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
File tree = new File(new File(db.getWorkTree(), "a"), "b");
FileUtils.mkdirs(tree);
File file = new File(tree, "c.txt");
@ -223,7 +229,6 @@ public class DiffEntryTest extends RepositoryTestCase {
.call();
// when
TreeWalk walk = new TreeWalk(db);
walk.addTree(c1.getTree());
walk.addTree(c2.getTree());
List<DiffEntry> result = DiffEntry.scan(walk, true);
@ -244,18 +249,19 @@ public class DiffEntryTest extends RepositoryTestCase {
assertThat(entry.getChangeType(), is(ChangeType.MODIFY));
assertThat(entry.getNewPath(), is("a/b/c.txt"));
}
}
@Test
public void shouldListChangesInWorkingTree() throws Exception {
// given
writeTrashFile("a.txt", "content");
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
git.add().addFilepattern("a.txt").call();
RevCommit c = git.commit().setMessage("initial commit").call();
writeTrashFile("b.txt", "new line");
// when
TreeWalk walk = new TreeWalk(db);
walk.addTree(c.getTree());
walk.addTree(new FileTreeIterator(db));
List<DiffEntry> result = DiffEntry.scan(walk, true);
@ -267,11 +273,13 @@ public class DiffEntryTest extends RepositoryTestCase {
assertThat(entry.getChangeType(), is(ChangeType.ADD));
assertThat(entry.getNewPath(), is("b.txt"));
}
}
@Test
public void shouldMarkEntriesWhenGivenMarkTreeFilter() throws Exception {
// given
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
RevCommit c1 = git.commit().setMessage("initial commit").call();
FileUtils.mkdir(new File(db.getWorkTree(), "b"));
writeTrashFile("a.txt", "a");
@ -286,7 +294,6 @@ public class DiffEntryTest extends RepositoryTestCase {
TreeFilter filterB2 = PathFilterGroup.createFromStrings("b/2.txt");
// when
TreeWalk walk = new TreeWalk(db);
walk.addTree(c1.getTree());
walk.addTree(c2.getTree());
List<DiffEntry> result = DiffEntry.scan(walk, true, new TreeFilter[] {
@ -332,6 +339,7 @@ public class DiffEntryTest extends RepositoryTestCase {
assertFalse(entryC.isMarked(2));
assertEquals(0, entryC.getTreeFilterMarks());
}
}
@Test(expected = IllegalArgumentException.class)
public void shouldThrowIAEWhenTreeWalkHasLessThanTwoTrees()
@ -339,10 +347,11 @@ public class DiffEntryTest extends RepositoryTestCase {
// given - we don't need anything here
// when
TreeWalk walk = new TreeWalk(db);
try (TreeWalk walk = new TreeWalk(db)) {
walk.addTree(new EmptyTreeIterator());
DiffEntry.scan(walk);
}
}
@Test(expected = IllegalArgumentException.class)
public void shouldThrowIAEWhenTreeWalkHasMoreThanTwoTrees()
@ -350,12 +359,13 @@ public class DiffEntryTest extends RepositoryTestCase {
// given - we don't need anything here
// when
TreeWalk walk = new TreeWalk(db);
try (TreeWalk walk = new TreeWalk(db)) {
walk.addTree(new EmptyTreeIterator());
walk.addTree(new EmptyTreeIterator());
walk.addTree(new EmptyTreeIterator());
DiffEntry.scan(walk);
}
}
@Test(expected = IllegalArgumentException.class)
public void shouldThrowIAEWhenScanShouldIncludeTreesAndWalkIsRecursive()
@ -363,28 +373,28 @@ public class DiffEntryTest extends RepositoryTestCase {
// given - we don't need anything here
// when
TreeWalk walk = new TreeWalk(db);
try (TreeWalk walk = new TreeWalk(db)) {
walk.addTree(new EmptyTreeIterator());
walk.addTree(new EmptyTreeIterator());
walk.setRecursive(true);
DiffEntry.scan(walk, true);
}
}
@Test
public void shouldReportFileModeChange() throws Exception {
writeTrashFile("a.txt", "content");
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
git.add().addFilepattern("a.txt").call();
RevCommit c1 = git.commit().setMessage("initial commit").call();
DirCache cache = db.lockDirCache();
DirCacheEditor editor = cache.editor();
final TreeWalk walk = new TreeWalk(db);
walk.addTree(c1.getTree());
walk.setRecursive(true);
assertTrue(walk.next());
editor.add(new PathEdit("a.txt") {
public void apply(DirCacheEntry ent) {
ent.setFileMode(FileMode.EXECUTABLE_FILE);
ent.setObjectId(walk.getObjectId(0));
@ -406,3 +416,4 @@ public class DiffEntryTest extends RepositoryTestCase {
assertEquals(FileMode.REGULAR_FILE, diff.getOldMode());
}
}
}

1
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java

@ -84,7 +84,6 @@ import org.eclipse.jgit.test.resources.SampleDataRepositoryTestCase;
import org.eclipse.jgit.util.FileUtils;
import org.junit.Test;
@SuppressWarnings("deprecation")
public class T0003_BasicTest extends SampleDataRepositoryTestCase {
@Test

1
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java

@ -77,7 +77,6 @@ import org.eclipse.jgit.treewalk.FileTreeIterator;
import org.eclipse.jgit.util.IO;
import org.junit.Test;
@SuppressWarnings("deprecation")
public class IndexDiffTest extends RepositoryTestCase {
static PathEdit add(final Repository db, final File workdir,

1
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/ObjectWalkTest.java

@ -53,7 +53,6 @@ import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.TreeFormatter;
import org.junit.Test;
@SuppressWarnings("deprecation")
public class ObjectWalkTest extends RevWalkTestCase {
protected ObjectWalk objw;

39
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/FileTreeIteratorTest.java

@ -255,10 +255,11 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
@Test
public void testDirCacheMatchingId() throws Exception {
File f = writeTrashFile("file", "content");
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file", "content");
fsTick(f);
git.add().addFilepattern("file").call();
}
DirCacheEntry dce = db.readDirCache().getEntry("file");
TreeWalk tw = new TreeWalk(db);
FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
@ -282,11 +283,12 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
@Test
public void testIsModifiedSymlinkAsFile() throws Exception {
writeTrashFile("symlink", "content");
Git git = new Git(db);
try (Git git = new Git(db)) {
db.getConfig().setString(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_SYMLINKS, "false");
git.add().addFilepattern("symlink").call();
git.commit().setMessage("commit").call();
}
// Modify previously committed DirCacheEntry and write it back to disk
DirCacheEntry dce = db.readDirCache().getEntry("symlink");
@ -305,7 +307,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
@Test
public void testIsModifiedFileSmudged() throws Exception {
File f = writeTrashFile("file", "content");
Git git = new Git(db);
try (Git git = new Git(db)) {
// The idea of this test is to check the smudged handling
// Hopefully fsTick will make sure our entry gets smudged
fsTick(f);
@ -319,6 +321,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
// resolution, so we force the index to have the
// same timestamp as the file we look at.
db.getIndexFile().setLastModified(lastModified);
}
DirCacheEntry dce = db.readDirCache().getEntry("file");
FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
.getConfig().get(WorkingTreeOptions.KEY));
@ -334,7 +337,8 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
@Test
public void submoduleHeadMatchesIndex() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
final RevCommit id = git.commit().setMessage("create file").call();
@ -354,7 +358,6 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
.setDirectory(new File(db.getWorkTree(), path)).call()
.getRepository().close();
TreeWalk walk = new TreeWalk(db);
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
FileTreeIterator workTreeIter = new FileTreeIterator(db);
walk.addTree(indexIter);
@ -364,10 +367,12 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
assertTrue(walk.next());
assertTrue(indexIter.idEqual(workTreeIter));
}
}
@Test
public void submoduleWithNoGitDirectory() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
final RevCommit id = git.commit().setMessage("create file").call();
@ -387,7 +392,6 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
assertTrue(submoduleRoot.mkdir());
assertTrue(new File(submoduleRoot, Constants.DOT_GIT).mkdir());
TreeWalk walk = new TreeWalk(db);
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
FileTreeIterator workTreeIter = new FileTreeIterator(db);
walk.addTree(indexIter);
@ -398,10 +402,12 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
assertFalse(indexIter.idEqual(workTreeIter));
assertEquals(ObjectId.zeroId(), workTreeIter.getEntryObjectId());
}
}
@Test
public void submoduleWithNoHead() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
final RevCommit id = git.commit().setMessage("create file").call();
@ -420,7 +426,6 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
assertNotNull(Git.init().setDirectory(new File(db.getWorkTree(), path))
.call().getRepository());
TreeWalk walk = new TreeWalk(db);
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
FileTreeIterator workTreeIter = new FileTreeIterator(db);
walk.addTree(indexIter);
@ -431,10 +436,12 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
assertFalse(indexIter.idEqual(workTreeIter));
assertEquals(ObjectId.zeroId(), workTreeIter.getEntryObjectId());
}
}
@Test
public void submoduleDirectoryIterator() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
final RevCommit id = git.commit().setMessage("create file").call();
@ -454,7 +461,6 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
.setDirectory(new File(db.getWorkTree(), path)).call()
.getRepository().close();
TreeWalk walk = new TreeWalk(db);
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
FileTreeIterator workTreeIter = new FileTreeIterator(db.getWorkTree(),
db.getFS(), db.getConfig().get(WorkingTreeOptions.KEY));
@ -465,10 +471,12 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
assertTrue(walk.next());
assertTrue(indexIter.idEqual(workTreeIter));
}
}
@Test
public void submoduleNestedWithHeadMatchingIndex() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk walk = new TreeWalk(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
final RevCommit id = git.commit().setMessage("create file").call();
@ -488,7 +496,6 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
.setDirectory(new File(db.getWorkTree(), path)).call()
.getRepository().close();
TreeWalk walk = new TreeWalk(db);
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
FileTreeIterator workTreeIter = new FileTreeIterator(db);
walk.addTree(indexIter);
@ -498,16 +505,17 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
assertTrue(walk.next());
assertTrue(indexIter.idEqual(workTreeIter));
}
}
@Test
public void idOffset() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk tw = new TreeWalk(db)) {
writeTrashFile("fileAinfsonly", "A");
File fileBinindex = writeTrashFile("fileBinindex", "B");
fsTick(fileBinindex);
git.add().addFilepattern("fileBinindex").call();
writeTrashFile("fileCinfsonly", "C");
TreeWalk tw = new TreeWalk(db);
DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
FileTreeIterator workTreeIter = new FileTreeIterator(db);
tw.addTree(indexIter);
@ -527,6 +535,7 @@ public class FileTreeIteratorTest extends RepositoryTestCase {
"fileCinfsonly", tw);
assertFalse(tw.next());
}
}
private static void assertEntry(String sha1string, String path, TreeWalk tw)
throws MissingObjectException, IncorrectObjectTypeException,

Loading…
Cancel
Save