Browse Source

Merge branch 'stable-4.2'

* stable-4.2:
  RepoProject: Fix warnings about variable hiding
  RepoTest: Open Git in try-with-resources
  RepositoryResolveTest: Open Git in try-with-resource
  RepositoryTestCase: Open autocloseable types in try-with-resource
  ResetCommandTest: Use Git member in testHardResetAfterSquashMerge
  ResolveMergerTest: Open Git in try-with-resource
  RevCommitListTest: Open Git and RevWalk in try-with-resource
  RevCommitParseTest: Open ObjectInserter.Formatter in try-with-resource
  RevObjectTest: Open RevWalk in try-with-resource
  RevTagParseTest: Open ObjectInserter.Formatter in try-with-resource
  RevertCommandTest: Open Git in try-with-resource
  SquashMessageFormatterTest: Open git in try-with-resource
  StatusCommandTest: Open Git in try-with-resource
  SubmoduleAddTest: Open Git in try-with-resource
  SymlinksTest: Open git and TreeWalk in try-with-resource
  T0003_BasicTest: Open autocloseable types in try-with-resource
  TextHashFunctions: Fix warnings about variable hiding
  TreeFilterTest: Open TreeWalk in try-with-resource
  TreeWalkJava7Test: Open TreeWalk in try-with-resource
  Fix diff for added and removed submodule

Change-Id: If3ecc63f6dfac55474d3c1dd2f4105371f3d24fb
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.3
Matthias Sohn 9 years ago
parent
commit
28e2fed761
  1. 7
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java
  2. 12
      org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RepoTest.java
  3. 14
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java
  4. 14
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java
  5. 34
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java
  6. 10
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java
  7. 62
      org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java
  8. 12
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/T0003_BasicTest.java
  9. 6
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java
  10. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java
  11. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SquashMessageFormatterTest.java
  12. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitListTest.java
  13. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java
  14. 9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java
  15. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java
  16. 12
      org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java
  17. 31
      org.eclipse.jgit.test/tst/org/eclipse/jgit/symlinks/SymlinksTest.java
  18. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/TreeWalkJava7Test.java
  19. 9
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java
  20. 3
      org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java
  21. 12
      org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java

7
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/RepositoryTestCase.java

@ -401,8 +401,7 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
* @return the created commit
*/
protected RevCommit commitFile(String filename, String contents, String branch) {
try {
Git git = new Git(db);
try (Git git = new Git(db)) {
Repository repo = git.getRepository();
String originalBranch = repo.getFullBranch();
boolean empty = repo.resolve(Constants.HEAD) == null;
@ -443,8 +442,10 @@ public abstract class RepositoryTestCase extends LocalDiskRepositoryTestCase {
final int stage, final String content) {
final DirCacheEntry entry = new DirCacheEntry(path, stage);
entry.setFileMode(mode);
entry.setObjectId(new ObjectInserter.Formatter().idFor(
try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
entry.setObjectId(formatter.idFor(
Constants.OBJ_BLOB, Constants.encode(content)));
}
return entry;
}

12
org.eclipse.jgit.pgm.test/tst/org/eclipse/jgit/pgm/RepoTest.java

@ -74,28 +74,32 @@ public class RepoTest extends CLIRepositoryTestCase {
super.setUp();
defaultDb = createWorkRepository();
Git git = new Git(defaultDb);
try (Git git = new Git(defaultDb)) {
JGitTestUtil.writeTrashFile(defaultDb, "hello.txt", "world");
git.add().addFilepattern("hello.txt").call();
git.commit().setMessage("Initial commit").call();
}
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();
}
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();
}
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();
}
resolveRelativeUris();
}

14
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/TextHashFunctions.java

@ -286,25 +286,25 @@ class TextHashFunctions extends TextBuiltin {
else
rb.findGitDir(dir);
Repository db = rb.build();
Repository repo = rb.build();
try {
run(db);
run(repo);
} finally {
db.close();
repo.close();
}
}
}
private void run(Repository db) throws Exception {
private void run(Repository repo) throws Exception {
List<Function> all = init();
long fileCnt = 0;
long lineCnt = 0;
try (ObjectReader or = db.newObjectReader();
try (ObjectReader or = repo.newObjectReader();
RevWalk rw = new RevWalk(or);
TreeWalk tw = new TreeWalk(or)) {
final MutableObjectId id = new MutableObjectId();
tw.reset(rw.parseTree(db.resolve(Constants.HEAD)));
tw.reset(rw.parseTree(repo.resolve(Constants.HEAD)));
tw.setRecursive(true);
while (tw.next()) {
@ -341,7 +341,7 @@ class TextHashFunctions extends TextBuiltin {
}
}
File directory = db.getDirectory();
File directory = repo.getDirectory();
if (directory != null) {
String name = directory.getName();
File parent = directory.getParentFile();

14
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/ResetCommandTest.java

@ -463,24 +463,24 @@ public class ResetCommandTest extends RepositoryTestCase {
@Test
public void testHardResetAfterSquashMerge() throws Exception {
Git g = new Git(db);
git = new Git(db);
writeTrashFile("file1", "file1");
g.add().addFilepattern("file1").call();
RevCommit first = g.commit().setMessage("initial commit").call();
git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("initial commit").call();
assertTrue(new File(db.getWorkTree(), "file1").exists());
createBranch(first, "refs/heads/branch1");
checkoutBranch("refs/heads/branch1");
writeTrashFile("file2", "file2");
g.add().addFilepattern("file2").call();
g.commit().setMessage("second commit").call();
git.add().addFilepattern("file2").call();
git.commit().setMessage("second commit").call();
assertTrue(new File(db.getWorkTree(), "file2").exists());
checkoutBranch("refs/heads/master");
MergeResult result = g.merge()
MergeResult result = git.merge()
.include(db.exactRef("refs/heads/branch1"))
.setSquash(true)
.call();
@ -489,7 +489,7 @@ public class ResetCommandTest extends RepositoryTestCase {
result.getMergeStatus());
assertNotNull(db.readSquashCommitMsg());
assertSameAsHead(g.reset().setMode(ResetType.HARD)
assertSameAsHead(git.reset().setMode(ResetType.HARD)
.setRef(first.getName()).call());
assertNull(db.readSquashCommitMsg());

34
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/RevertCommandTest.java

@ -74,8 +74,7 @@ public class RevertCommandTest extends RepositoryTestCase {
@Test
public void testRevert() throws IOException, JGitInternalException,
GitAPIException {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "first line\nsec. line\nthird line\n");
git.add().addFilepattern("a").call();
git.commit().setMessage("create a").call();
@ -122,14 +121,14 @@ public class RevertCommandTest extends RepositoryTestCase {
reader = db.getReflogReader(db.getBranch());
assertTrue(reader.getLastEntry().getComment()
.startsWith("revert: Revert \""));
}
}
@Test
public void testRevertMultiple() throws IOException, JGitInternalException,
GitAPIException {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "first\n");
git.add().addFilepattern("a").call();
git.commit().setMessage("add first").call();
@ -169,14 +168,14 @@ public class RevertCommandTest extends RepositoryTestCase {
reader = db.getReflogReader(db.getBranch());
assertTrue(reader.getLastEntry().getComment()
.startsWith("revert: Revert \""));
}
}
@Test
public void testRevertMultipleWithFail() throws IOException,
JGitInternalException, GitAPIException {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "first\n");
git.add().addFilepattern("a").call();
git.commit().setMessage("add first").call();
@ -220,12 +219,13 @@ public class RevertCommandTest extends RepositoryTestCase {
reader = db.getReflogReader(db.getBranch());
assertTrue(reader.getLastEntry().getComment()
.startsWith("revert: Revert \""));
}
}
@Test
public void testRevertDirtyIndex() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit sideCommit = prepareRevert(git);
// modify and add file a
@ -235,11 +235,12 @@ public class RevertCommandTest extends RepositoryTestCase {
doRevertAndCheckResult(git, sideCommit,
MergeFailureReason.DIRTY_INDEX);
}
}
@Test
public void testRevertDirtyWorktree() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit sideCommit = prepareRevert(git);
// modify file a
@ -249,10 +250,11 @@ public class RevertCommandTest extends RepositoryTestCase {
doRevertAndCheckResult(git, sideCommit,
MergeFailureReason.DIRTY_WORKTREE);
}
}
@Test
public void testRevertConflictResolution() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit sideCommit = prepareRevert(git);
RevertCommand revert = git.revert();
@ -281,11 +283,11 @@ public class RevertCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
}
}
@Test
public void testRevertkConflictReset() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit sideCommit = prepareRevert(git);
RevertCommand revert = git.revert();
@ -304,11 +306,12 @@ public class RevertCommandTest extends RepositoryTestCase {
assertFalse(new File(db.getDirectory(), Constants.REVERT_HEAD)
.exists());
}
}
@Test
public void testRevertOverExecutableChangeOnNonExectuableFileSystem()
throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
File file = writeTrashFile("test.txt", "a");
assertNotNull(git.add().addFilepattern("test.txt").call());
assertNotNull(git.commit().setMessage("commit1").call());
@ -340,10 +343,11 @@ public class RevertCommandTest extends RepositoryTestCase {
RevCommit newHead = revert.include(commit2).call();
assertNotNull(newHead);
}
}
@Test
public void testRevertConflictMarkers() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit sideCommit = prepareRevert(git);
RevertCommand revert = git.revert();
@ -356,10 +360,11 @@ public class RevertCommandTest extends RepositoryTestCase {
String expected = "<<<<<<< master\na(latest)\n=======\na\n>>>>>>> ca96c31 second master\n";
checkFile(new File(db.getWorkTree(), "a"), expected);
}
}
@Test
public void testRevertOurCommitName() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit sideCommit = prepareRevert(git);
RevertCommand revert = git.revert();
@ -372,6 +377,7 @@ public class RevertCommandTest extends RepositoryTestCase {
String expected = "<<<<<<< custom name\na(latest)\n=======\na\n>>>>>>> ca96c31 second master\n";
checkFile(new File(db.getWorkTree(), "a"), expected);
}
}
private RevCommit prepareRevert(final Git git) throws Exception {
// create, add and commit file a

10
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/StatusCommandTest.java

@ -61,8 +61,7 @@ public class StatusCommandTest extends RepositoryTestCase {
@Test
public void testEmptyStatus() throws NoWorkTreeException,
GitAPIException {
Git git = new Git(db);
try (Git git = new Git(db)) {
Status stat = git.status().call();
assertEquals(0, stat.getAdded().size());
assertEquals(0, stat.getChanged().size());
@ -71,11 +70,12 @@ public class StatusCommandTest extends RepositoryTestCase {
assertEquals(0, stat.getRemoved().size());
assertEquals(0, stat.getUntracked().size());
}
}
@Test
public void testDifferentStates() throws IOException,
NoFilepatternException, GitAPIException {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "content of a");
writeTrashFile("b", "content of b");
writeTrashFile("c", "content of c");
@ -130,11 +130,12 @@ public class StatusCommandTest extends RepositoryTestCase {
assertEquals(1, stat.getUntrackedFolders().size());
assertTrue(stat.getUntrackedFolders().contains("sub"));
}
}
@Test
public void testDifferentStatesWithPaths() throws IOException,
NoFilepatternException, GitAPIException {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "content of a");
writeTrashFile("D/b", "content of b");
writeTrashFile("D/c", "content of c");
@ -166,4 +167,5 @@ public class StatusCommandTest extends RepositoryTestCase {
stat = git.status().call();
assertEquals(Sets.of("a", "D/b", "D/D/d"), stat.getModified());
}
}
}

62
org.eclipse.jgit.test/tst/org/eclipse/jgit/diff/DiffFormatterTest.java

@ -259,6 +259,68 @@ public class DiffFormatterTest extends RepositoryTestCase {
assertEquals(1, hh.toEditList().size());
}
@Test
public void testCreateFileHeader_AddGitLink() throws Exception {
ObjectId adId = blob("a\nd\n");
DiffEntry ent = DiffEntry.add("FOO", adId);
ent.newMode = FileMode.GITLINK;
FileHeader fh = df.toFileHeader(ent);
String diffHeader = "diff --git a/FOO b/FOO\n" //
+ "new file mode " + GITLINK + "\n"
+ "index "
+ ObjectId.zeroId().abbreviate(8).name()
+ ".."
+ adId.abbreviate(8).name() + "\n" //
+ "--- /dev/null\n"//
+ "+++ b/FOO\n";
assertEquals(diffHeader, RawParseUtils.decode(fh.getBuffer()));
assertEquals(1, fh.getHunks().size());
HunkHeader hh = fh.getHunks().get(0);
EditList el = hh.toEditList();
assertEquals(1, el.size());
Edit e = el.get(0);
assertEquals(0, e.getBeginA());
assertEquals(0, e.getEndA());
assertEquals(0, e.getBeginB());
assertEquals(1, e.getEndB());
assertEquals(Edit.Type.INSERT, e.getType());
}
@Test
public void testCreateFileHeader_DeleteGitLink() throws Exception {
ObjectId adId = blob("a\nd\n");
DiffEntry ent = DiffEntry.delete("FOO", adId);
ent.oldMode = FileMode.GITLINK;
FileHeader fh = df.toFileHeader(ent);
String diffHeader = "diff --git a/FOO b/FOO\n" //
+ "deleted file mode " + GITLINK + "\n"
+ "index "
+ adId.abbreviate(8).name()
+ ".."
+ ObjectId.zeroId().abbreviate(8).name() + "\n" //
+ "--- a/FOO\n"//
+ "+++ /dev/null\n";
assertEquals(diffHeader, RawParseUtils.decode(fh.getBuffer()));
assertEquals(1, fh.getHunks().size());
HunkHeader hh = fh.getHunks().get(0);
EditList el = hh.toEditList();
assertEquals(1, el.size());
Edit e = el.get(0);
assertEquals(0, e.getBeginA());
assertEquals(1, e.getEndA());
assertEquals(0, e.getBeginB());
assertEquals(0, e.getEndB());
assertEquals(Edit.Type.DELETE, e.getType());
}
@Test
public void testCreateFileHeaderWithoutIndexLine() throws Exception {
DiffEntry m = DiffEntry.modify(PATH_A);

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

@ -354,14 +354,14 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
@Test
public void test007_Open() throws IOException {
final FileRepository db2 = new FileRepository(db.getDirectory());
try (final FileRepository db2 = new FileRepository(db.getDirectory())) {
assertEquals(db.getDirectory(), db2.getDirectory());
assertEquals(db.getObjectDatabase().getDirectory(), db2
.getObjectDatabase().getDirectory());
assertNotSame(db.getConfig(), db2.getConfig());
}
}
@SuppressWarnings("unused")
@Test
public void test008_FailOnWrongVersion() throws IOException {
final File cfg = new File(db.getDirectory(), Constants.CONFIG);
@ -370,8 +370,7 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
+ badvers + "\n";
write(cfg, configStr);
try {
new FileRepository(db.getDirectory());
try (FileRepository unused = new FileRepository(db.getDirectory())) {
fail("incorrectly opened a bad repository");
} catch (IllegalArgumentException ioe) {
assertNotNull(ioe.getMessage());
@ -533,10 +532,11 @@ public class T0003_BasicTest extends SampleDataRepositoryTestCase {
public void test025_computeSha1NoStore() throws IOException {
byte[] data = "test025 some data, more than 16 bytes to get good coverage"
.getBytes("ISO-8859-1");
final ObjectId id = new ObjectInserter.Formatter().idFor(
Constants.OBJ_BLOB, data);
try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
final ObjectId id = formatter.idFor(Constants.OBJ_BLOB, data);
assertEquals("4f561df5ecf0dfbd53a0dc0f37262fef075d9dde", id.name());
}
}
@Test
public void test026_CreateCommitMultipleparents() throws IOException {

6
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/RepositoryResolveTest.java

@ -267,7 +267,7 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
@Test
public void resolveExprSimple() 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();
@ -275,10 +275,11 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
assertEquals("refs/heads/master", db.simplify("refs/heads/master"));
assertEquals("HEAD", db.simplify("HEAD"));
}
}
@Test
public void resolveUpstream() 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();
@ -297,6 +298,7 @@ public class RepositoryResolveTest extends SampleDataRepositoryTestCase {
git.commit().setMessage("create file").call();
assertEquals("refs/remotes/origin/main", db.simplify("@{upstream}"));
}
}
@Test
public void invalidNames() throws AmbiguousObjectException, IOException {

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/ResolveMergerTest.java

@ -88,7 +88,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
file = new File(folder1, "file2.txt");
write(file, "folder1--file2.txt");
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern(folder1.getName()).call();
RevCommit base = git.commit().setMessage("adding folder").call();
@ -118,6 +118,7 @@ public class ResolveMergerTest extends RepositoryTestCase {
assertTrue(ok);
assertTrue(file.exists());
}
}
/**
* Merging two conflicting subtrees when the index does not contain any file

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/SquashMessageFormatterTest.java

@ -73,7 +73,7 @@ public class SquashMessageFormatterTest extends SampleDataRepositoryTestCase {
@Test
public void testCommit() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
revCommit = git.commit().setMessage("squash_me").call();
Ref master = db.exactRef("refs/heads/master");
@ -86,4 +86,5 @@ public class SquashMessageFormatterTest extends SampleDataRepositoryTestCase {
+ ">\nDate: " + dateFormatter.formatDate(author)
+ "\n\n\tsquash_me\n", message);
}
}
}

8
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitListTest.java

@ -57,15 +57,16 @@ public class RevCommitListTest extends RepositoryTestCase {
private RevCommitList<RevCommit> list;
public void setup(int count) throws Exception {
Git git = new Git(db);
try (Git git = new Git(db);
RevWalk w = new RevWalk(db);) {
for (int i = 0; i < count; i++)
git.commit().setCommitter(committer).setAuthor(author)
.setMessage("commit " + i).call();
list = new RevCommitList<RevCommit>();
RevWalk w = new RevWalk(db);
w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
list.source(w);
}
}
@Test
public void testFillToHighMark2() throws Exception {
@ -107,7 +108,7 @@ public class RevCommitListTest extends RepositoryTestCase {
public void testFillToCommit() throws Exception {
setup(3);
RevWalk w = new RevWalk(db);
try (RevWalk w = new RevWalk(db)) {
w.markStart(w.lookupCommit(db.resolve(Constants.HEAD)));
w.next();
@ -119,6 +120,7 @@ public class RevCommitListTest extends RepositoryTestCase {
assertEquals("commit 1", list.get(1).getFullMessage());
assertNull(list.get(3));
}
}
@Test
public void testFillToUnknownCommit() throws Exception {

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevCommitParseTest.java

@ -452,9 +452,10 @@ public class RevCommitParseTest extends RepositoryTestCase {
@Test
public void testParse_PublicParseMethod()
throws UnsupportedEncodingException {
ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
CommitBuilder src = new CommitBuilder();
try (ObjectInserter.Formatter fmt = new ObjectInserter.Formatter()) {
src.setTreeId(fmt.idFor(Constants.OBJ_TREE, new byte[] {}));
}
src.setAuthor(author);
src.setCommitter(committer);
src.setMessage("Test commit\n\nThis is a test.\n");

9
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevObjectTest.java

@ -73,9 +73,12 @@ public class RevObjectTest extends RevWalkTestCase {
assertTrue(a1.equals((Object) a1));
assertFalse(a1.equals(""));
final RevWalk rw2 = new RevWalk(db);
final RevCommit a2 = rw2.parseCommit(a1);
final RevCommit b2 = rw2.parseCommit(b1);
final RevCommit a2;
final RevCommit b2;
try (final RevWalk rw2 = new RevWalk(db)) {
a2 = rw2.parseCommit(a1);
b2 = rw2.parseCommit(b1);
}
assertNotSame(a1, a2);
assertNotSame(b1, b2);

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/revwalk/RevTagParseTest.java

@ -463,10 +463,11 @@ public class RevTagParseTest extends RepositoryTestCase {
@Test
public void testParse_PublicParseMethod() throws CorruptObjectException {
ObjectInserter.Formatter fmt = new ObjectInserter.Formatter();
TagBuilder src = new TagBuilder();
try (ObjectInserter.Formatter fmt = new ObjectInserter.Formatter()) {
src.setObjectId(fmt.idFor(Constants.OBJ_TREE, new byte[] {}),
Constants.OBJ_TREE);
}
src.setTagger(committer);
src.setTag("a.test");
src.setMessage("Test tag\n\nThis is a test.\n");

12
org.eclipse.jgit.test/tst/org/eclipse/jgit/submodule/SubmoduleAddTest.java

@ -119,7 +119,7 @@ public class SubmoduleAddTest extends RepositoryTestCase {
@Test
public void addSubmodule() 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();
@ -150,6 +150,7 @@ public class SubmoduleAddTest extends RepositoryTestCase {
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
assertTrue(status.getAdded().contains(path));
}
}
@Test
public void addExistentSubmodule() throws Exception {
@ -182,7 +183,7 @@ public class SubmoduleAddTest extends RepositoryTestCase {
@Test
public void addSubmoduleWithRelativeUri() 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();
@ -203,8 +204,9 @@ public class SubmoduleAddTest extends RepositoryTestCase {
assertEquals(uri, generator.getModulesUrl());
assertEquals(path, generator.getModulesPath());
String fullUri = db.getDirectory().getAbsolutePath();
if (File.separatorChar == '\\')
if (File.separatorChar == '\\') {
fullUri = fullUri.replace('\\', '/');
}
assertEquals(fullUri, generator.getConfigUrl());
Repository subModRepo = generator.getRepository();
assertNotNull(subModRepo);
@ -222,6 +224,7 @@ public class SubmoduleAddTest extends RepositoryTestCase {
assertTrue(status.getAdded().contains(Constants.DOT_GIT_MODULES));
assertTrue(status.getAdded().contains(path));
}
}
@Test
public void addSubmoduleWithExistingSubmoduleDefined() throws Exception {
@ -237,7 +240,7 @@ public class SubmoduleAddTest extends RepositoryTestCase {
path1, ConfigConstants.CONFIG_KEY_URL, url1);
modulesConfig.save();
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
assertNotNull(git.commit().setMessage("create file").call());
@ -264,4 +267,5 @@ public class SubmoduleAddTest extends RepositoryTestCase {
ConfigConstants.CONFIG_SUBMODULE_SECTION, path2,
ConfigConstants.CONFIG_KEY_URL));
}
}
}

31
org.eclipse.jgit.test/tst/org/eclipse/jgit/symlinks/SymlinksTest.java

@ -75,7 +75,7 @@ public class SymlinksTest extends RepositoryTestCase {
*/
@Test
public void fileModeTestFileThenSymlink() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "Hello world a");
writeTrashFile("b", "Hello world b");
git.add().addFilepattern(".").call();
@ -96,6 +96,7 @@ public class SymlinksTest extends RepositoryTestCase {
db.getFS());
assertEquals(FileMode.REGULAR_FILE, entry.getMode());
}
}
/**
* Steps: 1.Add symlink 'a' 2.Commit 3.Create branch '1' 4.Replace symlink
@ -108,7 +109,7 @@ public class SymlinksTest extends RepositoryTestCase {
*/
@Test
public void fileModeTestSymlinkThenFile() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("b", "Hello world b");
FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "b");
git.add().addFilepattern(".").call();
@ -129,6 +130,7 @@ public class SymlinksTest extends RepositoryTestCase {
db.getFS());
assertEquals(FileMode.SYMLINK, entry.getMode());
}
}
/**
* Steps: 1.Add folder 'a' 2.Commit 3.Create branch '1' 4.Replace folder 'a'
@ -141,7 +143,7 @@ public class SymlinksTest extends RepositoryTestCase {
*/
@Test
public void fileModeTestFolderThenSymlink() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
FileUtils.mkdirs(new File(db.getWorkTree(), "a"));
writeTrashFile("a/b", "Hello world b");
writeTrashFile("c", "Hello world c");
@ -163,6 +165,7 @@ public class SymlinksTest extends RepositoryTestCase {
db.getFS());
assertEquals(FileMode.TREE, entry.getMode());
}
}
/**
* Steps: 1.Add symlink 'a' 2.Commit 3.Create branch '1' 4.Replace symlink
@ -175,7 +178,7 @@ public class SymlinksTest extends RepositoryTestCase {
*/
@Test
public void fileModeTestSymlinkThenFolder() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("c", "Hello world c");
FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "c");
git.add().addFilepattern(".").call();
@ -197,6 +200,7 @@ public class SymlinksTest extends RepositoryTestCase {
db.getFS());
assertEquals(FileMode.SYMLINK, entry.getMode());
}
}
/**
* Steps: 1.Add file 'b' 2.Commit 3.Create branch '1' 4.Add symlink 'a'
@ -209,7 +213,8 @@ public class SymlinksTest extends RepositoryTestCase {
*/
@Test
public void fileModeTestMissingThenSymlink() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk tw = new TreeWalk(db);) {
writeTrashFile("b", "Hello world b");
git.add().addFilepattern(".").call();
RevCommit commit1 = git.commit().setMessage("add file b").call();
@ -220,7 +225,6 @@ public class SymlinksTest extends RepositoryTestCase {
git.checkout().setName(branch_1.getName()).call();
TreeWalk tw = new TreeWalk(db);
tw.addTree(commit1.getTree());
tw.addTree(commit2.getTree());
List<DiffEntry> scan = DiffEntry.scan(tw);
@ -228,6 +232,7 @@ public class SymlinksTest extends RepositoryTestCase {
assertEquals(FileMode.SYMLINK, scan.get(0).getNewMode());
assertEquals(FileMode.MISSING, scan.get(0).getOldMode());
}
}
/**
* Steps: 1.Add symlink 'a' 2.Commit 3.Create branch '1' 4.Delete symlink
@ -240,7 +245,8 @@ public class SymlinksTest extends RepositoryTestCase {
*/
@Test
public void fileModeTestSymlinkThenMissing() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db);
TreeWalk tw = new TreeWalk(db);) {
writeTrashFile("b", "Hello world b");
FileUtils.createSymLink(new File(db.getWorkTree(), "a"), "b");
git.add().addFilepattern(".").call();
@ -252,7 +258,6 @@ public class SymlinksTest extends RepositoryTestCase {
git.checkout().setName(branch_1.getName()).call();
TreeWalk tw = new TreeWalk(db);
tw.addTree(commit1.getTree());
tw.addTree(commit2.getTree());
List<DiffEntry> scan = DiffEntry.scan(tw);
@ -260,10 +265,11 @@ public class SymlinksTest extends RepositoryTestCase {
assertEquals(FileMode.MISSING, scan.get(0).getNewMode());
assertEquals(FileMode.SYMLINK, scan.get(0).getOldMode());
}
}
@Test
public void createSymlinkAfterTarget() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "start");
git.add().addFilepattern("a").call();
RevCommit base = git.commit().setMessage("init").call();
@ -284,10 +290,11 @@ public class SymlinksTest extends RepositoryTestCase {
FileUtils.readSymLink(new File(db.getWorkTree(), "link")));
assertEquals("someData", data);
}
}
@Test
public void createFileSymlinkBeforeTarget() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "start");
git.add().addFilepattern("a").call();
RevCommit base = git.commit().setMessage("init").call();
@ -308,10 +315,11 @@ public class SymlinksTest extends RepositoryTestCase {
FileUtils.readSymLink(new File(db.getWorkTree(), "tlink")));
assertEquals("someData", data);
}
}
@Test
public void createDirSymlinkBeforeTarget() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "start");
git.add().addFilepattern("a").call();
RevCommit base = git.commit().setMessage("init").call();
@ -333,4 +341,5 @@ public class SymlinksTest extends RepositoryTestCase {
FileUtils.readSymLink(new File(db.getWorkTree(), "link")));
assertEquals("someData", data);
}
}
}

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/TreeWalkJava7Test.java

@ -60,7 +60,7 @@ public class TreeWalkJava7Test extends RepositoryTestCase {
assertTrue(fs.supportsSymlinks());
writeTrashFile("target/data", "targetdata");
fs.createSymLink(new File(trash, "link"), "target");
TreeWalk tw = new TreeWalk(db);
try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new FileTreeIterator(db));
assertTrue(tw.next());
@ -69,4 +69,5 @@ public class TreeWalkJava7Test extends RepositoryTestCase {
assertEquals("target/data", tw.getPathString());
assertFalse(tw.next());
}
}
}

9
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/TreeFilterTest.java

@ -55,10 +55,11 @@ import org.junit.Test;
public class TreeFilterTest extends RepositoryTestCase {
@Test
public void testALL_IncludesAnything() throws Exception {
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new EmptyTreeIterator());
assertTrue(TreeFilter.ALL.include(tw));
}
}
@Test
public void testALL_ShouldNotBeRecursive() throws Exception {
@ -72,17 +73,19 @@ public class TreeFilterTest extends RepositoryTestCase {
@Test
public void testNotALL_IncludesNothing() throws Exception {
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new EmptyTreeIterator());
assertFalse(TreeFilter.ALL.negate().include(tw));
}
}
@Test
public void testANY_DIFF_IncludesSingleTreeCase() throws Exception {
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new EmptyTreeIterator());
assertTrue(TreeFilter.ANY_DIFF.include(tw));
}
}
@Test
public void testANY_DIFF_ShouldNotBeRecursive() throws Exception {

3
org.eclipse.jgit/src/org/eclipse/jgit/diff/DiffFormatter.java

@ -666,6 +666,9 @@ public class DiffFormatter implements AutoCloseable {
}
private static byte[] writeGitLinkText(AbbreviatedObjectId id) {
if (id.toObjectId().equals(ObjectId.zeroId())) {
return EMPTY;
}
return encodeASCII("Subproject commit " + id.name() //$NON-NLS-1$
+ "\n"); //$NON-NLS-1$
}

12
org.eclipse.jgit/src/org/eclipse/jgit/gitrepo/RepoProject.java

@ -252,10 +252,10 @@ public class RepoProject implements Comparable<RepoProject> {
/**
* Add a bunch of copyfile configurations.
*
* @param copyfiles
* @param copyFiles
*/
public void addCopyFiles(Collection<CopyFile> copyfiles) {
this.copyfiles.addAll(copyfiles);
public void addCopyFiles(Collection<CopyFile> copyFiles) {
this.copyfiles.addAll(copyFiles);
}
/**
@ -288,13 +288,13 @@ public class RepoProject implements Comparable<RepoProject> {
/**
* Check if this sub repo is an ancestor of the given path.
*
* @param path
* @param thatPath
* path to be checked to see if it is within this repository
* @return true if this sub repo is an ancestor of the given path.
* @since 4.2
*/
public boolean isAncestorOf(String path) {
return path.startsWith(getPathWithSlash());
public boolean isAncestorOf(String thatPath) {
return thatPath.startsWith(getPathWithSlash());
}
@Override

Loading…
Cancel
Save