Browse Source

Merge branch 'stable-4.2'

* stable-4.2:
  Don't use deprecated LockFile constructor
  Fix warnings about unchecked conversion of MergeResult
  MockServletConfig: Fix warning about unchecked conversion of Enumeration
  HugeFileTest: Make Git a class member and open in try-with-resource
  Suppress "unchecked cast" warnings related to UploadPackFactory.DISABLED
  DiffAlgorithms: Fix warnings about variable hiding
  DirCacheBasicTest: Open ObjectInserter.Formatter in try-with-resource
  DirCacheBuilderIteratorTest: Open TreeWalk in try-with-resource
  DirCacheCGitCompatabilityTest: Open TreeWalk in try-with-resource
  DirCacheCheckoutMaliciousPathTest: Open Git and RevWalk in t-w-r
  DirCacheIteratorTest: Open TreeWalk instances in try-with-resource
  ForPathTest: Open TreeWalk in try-with-resource
  GitConstructionTest: Open Git instance in try-with-resource
  IndexDiffTest: Open Git instances in try-with-resources
  ManifestParserTest: Don't use deprecated StringBufferInputStream
  InMemoryRepository: Remove unused RevWalk from batch method signature
  IndexModificationTimesTest: Open Git instances in try-with-resource
  InterIndexDiffFilterTest: Open TreeWalk in try-with-resource
  LockFileTest: Open Git instance in try-with-resource
  JGit v4.1.2.201602141800-r
  MergeCommandTest: Use JUnit's assume to check preconditions
  MergeCommandTest: Open Git instances in try-with-resource

Change-Id: Ie5dba6b9132a29e86958a04fa2b76465bcd2c6b5
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
stable-4.3
Matthias Sohn 9 years ago
parent
commit
514b11ddcc
  1. 1
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java
  2. 1
      org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java
  3. 2
      org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/MockServletConfig.java
  4. 2
      org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java
  5. 23
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java
  6. 4
      org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java
  7. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/GitConstructionTest.java
  8. 17
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/HugeFileTest.java
  9. 165
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
  10. 4
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java
  11. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java
  12. 3
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
  13. 21
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java
  14. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java
  15. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java
  16. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java
  17. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/RefUpdateTest.java
  18. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java
  19. 46
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
  20. 7
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java
  21. 2
      org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java
  22. 5
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/ForPathTest.java
  23. 15
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java
  24. 6
      org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java
  25. 4
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/InMemoryRepository.java
  26. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java
  27. 4
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java
  28. 8
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java
  29. 2
      org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryUpdate.java
  30. 2
      org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeFormatter.java
  31. 5
      org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java
  32. 3
      org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java

1
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultReceivePackFactoryTest.java

@ -79,6 +79,7 @@ public class DefaultReceivePackFactoryTest extends LocalDiskRepositoryTestCase {
factory = new DefaultReceivePackFactory();
}
@SuppressWarnings("unchecked")
@Test
public void testDisabledSingleton() throws ServiceNotAuthorizedException {
factory = (ReceivePackFactory<HttpServletRequest>) ReceivePackFactory.DISABLED;

1
org.eclipse.jgit.http.test/tst/org/eclipse/jgit/http/test/DefaultUploadPackFactoryTest.java

@ -77,6 +77,7 @@ public class DefaultUploadPackFactoryTest extends LocalDiskRepositoryTestCase {
factory = new DefaultUploadPackFactory();
}
@SuppressWarnings("unchecked")
@Test
public void testDisabledSingleton() throws ServiceNotAuthorizedException {
factory = (UploadPackFactory<HttpServletRequest>) UploadPackFactory.DISABLED;

2
org.eclipse.jgit.junit.http/src/org/eclipse/jgit/junit/http/MockServletConfig.java

@ -62,7 +62,7 @@ public class MockServletConfig implements ServletConfig {
return parameters.get(name);
}
public Enumeration getInitParameterNames() {
public Enumeration<String> getInitParameterNames() {
final Iterator<String> i = parameters.keySet().iterator();
return new Enumeration<String>() {
public boolean hasMoreElements() {

2
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/TestRepository.java

@ -905,7 +905,7 @@ public class TestRepository<R extends Repository> {
private void writeFile(final File p, final byte[] bin) throws IOException,
ObjectWritingException {
final LockFile lck = new LockFile(p, db.getFS());
final LockFile lck = new LockFile(p);
if (!lck.lock())
throw new ObjectWritingException("Can't write " + p);
try {

23
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/DiffAlgorithms.java

@ -155,16 +155,16 @@ class DiffAlgorithms 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<Test> all = init();
long files = 0;
@ -173,14 +173,14 @@ class DiffAlgorithms extends TextBuiltin {
int maxN = 0;
AbbreviatedObjectId startId;
try (ObjectReader or = db.newObjectReader();
try (ObjectReader or = repo.newObjectReader();
RevWalk rw = new RevWalk(or)) {
final MutableObjectId id = new MutableObjectId();
TreeWalk tw = new TreeWalk(or);
tw.setFilter(TreeFilter.ANY_DIFF);
tw.setRecursive(true);
ObjectId start = db.resolve(Constants.HEAD);
ObjectId start = repo.resolve(Constants.HEAD);
startId = or.abbreviate(start);
rw.markStart(rw.parseCommit(start));
for (;;) {
@ -235,14 +235,15 @@ class DiffAlgorithms extends TextBuiltin {
Collections.sort(all, new Comparator<Test>() {
public int compare(Test a, Test b) {
int cmp = Long.signum(a.runningTimeNanos - b.runningTimeNanos);
if (cmp == 0)
cmp = a.algorithm.name.compareTo(b.algorithm.name);
return cmp;
int result = Long.signum(a.runningTimeNanos - b.runningTimeNanos);
if (result == 0) {
result = a.algorithm.name.compareTo(b.algorithm.name);
}
return result;
}
});
File directory = db.getDirectory();
File directory = repo.getDirectory();
if (directory != null) {
String name = directory.getName();
File parent = directory.getParentFile();

4
org.eclipse.jgit.pgm/src/org/eclipse/jgit/pgm/debug/RebuildCommitGraph.java

@ -235,7 +235,7 @@ class RebuildCommitGraph extends TextBuiltin {
final ObjectId id = db.resolve(Constants.HEAD);
if (!ObjectId.isId(head) && id != null) {
final LockFile lf;
lf = new LockFile(new File(db.getDirectory(), Constants.HEAD), db.getFS());
lf = new LockFile(new File(db.getDirectory(), Constants.HEAD));
if (!lf.lock())
throw new IOException(MessageFormat.format(CLIText.get().cannotLock, Constants.HEAD));
lf.write(id);
@ -263,7 +263,7 @@ class RebuildCommitGraph extends TextBuiltin {
protected void writeFile(final String name, final byte[] content)
throws IOException {
final File file = new File(db.getDirectory(), name);
final LockFile lck = new LockFile(file, db.getFS());
final LockFile lck = new LockFile(file);
if (!lck.lock())
throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file));
try {

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

@ -66,11 +66,12 @@ public class GitConstructionTest extends RepositoryTestCase {
@Before
public void setUp() throws Exception {
super.setUp();
Git git = new Git(db);
try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call();
writeTrashFile("Test.txt", "Hello world");
git.add().addFilepattern("Test.txt").call();
git.commit().setMessage("Initial commit").call();
}
bareRepo = Git.cloneRepository().setBare(true)
.setURI(db.getDirectory().toURI().toString())

17
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/HugeFileTest.java

@ -51,6 +51,8 @@ import java.util.Collection;
import org.eclipse.jgit.api.ResetCommand.ResetType;
import org.eclipse.jgit.junit.RepositoryTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
@ -60,12 +62,26 @@ public class HugeFileTest extends RepositoryTestCase {
private long lastt = t;
private Git git;
private void measure(String name) {
long c = System.currentTimeMillis();
System.out.println(name + ", dt=" + (c - lastt) / 1000.0 + "s");
lastt = c;
}
@Before
public void before() {
git = new Git(db);
}
@After
public void after() {
if (git != null) {
git.close();
}
}
@Ignore("Test takes way too long (~10 minutes) to be part of the standard suite")
@Test
public void testAddHugeFile() throws Exception {
@ -75,7 +91,6 @@ public class HugeFileTest extends RepositoryTestCase {
rf.setLength(4429185024L);
rf.close();
measure("Created file");
Git git = new Git(db);
git.add().addFilepattern("a.txt").call();
measure("Added file");

165
org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java

@ -50,6 +50,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import java.io.File;
import java.util.Iterator;
@ -96,11 +97,12 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
public void testMergeInItself() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call();
MergeResult result = git.merge().include(db.exactRef(Constants.HEAD)).call();
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus());
}
// no reflog entry written by merge
assertEquals("commit (initial): initial commit",
db
@ -112,7 +114,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
public void testAlreadyUpToDate() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("initial commit").call();
createBranch(first, "refs/heads/branch1");
@ -120,6 +122,7 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git.merge().include(db.exactRef("refs/heads/branch1")).call();
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus());
assertEquals(second, result.getNewHead());
}
// no reflog entry written by merge
assertEquals("commit: second commit", db
.getReflogReader(Constants.HEAD).getLastEntry().getComment());
@ -129,7 +132,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
public void testFastForward() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("initial commit").call();
createBranch(first, "refs/heads/branch1");
@ -141,6 +144,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead());
}
assertEquals("merge refs/heads/master: Fast-forward",
db.getReflogReader(Constants.HEAD).getLastEntry().getComment());
assertEquals("merge refs/heads/master: Fast-forward",
@ -149,7 +153,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
public void testFastForwardNoCommit() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("initial commit").call();
createBranch(first, "refs/heads/branch1");
@ -163,6 +167,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeResult.MergeStatus.FAST_FORWARD,
result.getMergeStatus());
assertEquals(second, result.getNewHead());
}
assertEquals("merge refs/heads/master: Fast-forward", db
.getReflogReader(Constants.HEAD).getLastEntry().getComment());
assertEquals("merge refs/heads/master: Fast-forward", db
@ -171,8 +176,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
public void testFastForwardWithFiles() 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();
@ -194,6 +198,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertTrue(new File(db.getWorkTree(), "file2").exists());
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead());
}
assertEquals("merge refs/heads/master: Fast-forward",
db.getReflogReader(Constants.HEAD).getLastEntry().getComment());
assertEquals("merge refs/heads/master: Fast-forward",
@ -202,8 +207,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
public void testMultipleHeads() 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();
@ -231,12 +235,12 @@ public class MergeCommandTest extends RepositoryTestCase {
// expected this exception
}
}
}
@Theory
public void testMergeSuccessAllStrategies(MergeStrategy mergeStrategy)
throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("first").call();
createBranch(first, "refs/heads/side");
@ -252,6 +256,7 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git.merge().setStrategy(mergeStrategy)
.include(db.exactRef(R_HEADS + MASTER)).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
}
assertEquals(
"merge refs/heads/master: Merge made by "
+ mergeStrategy.getName() + ".",
@ -265,8 +270,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Theory
public void testMergeSuccessAllStrategiesNoCommit(
MergeStrategy mergeStrategy) throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("first").call();
createBranch(first, "refs/heads/side");
@ -286,11 +290,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(),
thirdCommit.getId());
}
}
@Test
public void testContentMerge() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("c/c/c", "1\nc\n3\n");
@ -331,11 +335,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.MERGING, db.getRepositoryState());
}
}
@Test
public void testMergeTag() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "a");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -358,11 +362,11 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git.merge().include(tag).setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
}
}
@Test
public void testMergeMessage() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -387,13 +391,13 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals("Merge branch 'side'\n\nConflicts:\n\ta\n",
db.readMergeCommitMsg());
}
}
@Test
public void testMergeNonVersionedPaths() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("c/c/c", "1\nc\n3\n");
@ -440,11 +444,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.MERGING, db.getRepositoryState());
}
}
@Test
public void testMultipleCreations() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -466,11 +470,11 @@ public class MergeCommandTest extends RepositoryTestCase {
.setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
}
@Test
public void testMultipleCreationsSameContent() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -501,11 +505,11 @@ public class MergeCommandTest extends RepositoryTestCase {
.getReflogReader(db.getBranch())
.getLastEntry().getComment());
}
}
@Test
public void testSuccessfulContentMerge() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("c/c/c", "1\nc\n3\n");
@ -559,11 +563,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
// test index state
}
}
@Test
public void testSuccessfulContentMergeNoCommit() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("c/c/c", "1\nc\n3\n");
@ -609,12 +613,12 @@ public class MergeCommandTest extends RepositoryTestCase {
assertNull(result.getNewHead());
assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState());
}
}
@Test
public void testSuccessfulContentMergeAndDirtyworkingTree()
throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("d", "1\nd\n3\n");
@ -670,11 +674,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
}
}
@Test
public void testSingleDeletion() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("d", "1\nd\n3\n");
@ -725,11 +729,11 @@ public class MergeCommandTest extends RepositoryTestCase {
read(new File(db.getWorkTree(), "c/c/c")));
assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d")));
}
}
@Test
public void testMultipleDeletions() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -754,11 +758,11 @@ public class MergeCommandTest extends RepositoryTestCase {
.setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
}
}
@Test
public void testDeletionAndConflict() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("d", "1\nd\n3\n");
@ -798,11 +802,11 @@ public class MergeCommandTest extends RepositoryTestCase {
read(new File(db.getWorkTree(), "c/c/c")));
assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d")));
}
}
@Test
public void testDeletionOnMasterConflict() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call();
@ -830,11 +834,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals("1\na(side)\n3\n", read(new File(db.getWorkTree(), "a")));
assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b")));
}
}
@Test
public void testDeletionOnSideConflict() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call();
@ -864,14 +868,14 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(1, result.getConflicts().size());
assertEquals(3, result.getConflicts().get("a")[0].length);
}
}
@Test
public void testModifiedAndRenamed() throws Exception {
// this test is essentially the same as testDeletionOnSideConflict,
// however if once rename support is added this test should result in a
// successful merge instead of a conflict
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("x", "add x");
git.add().addFilepattern("x").call();
RevCommit initial = git.commit().setMessage("add x").call();
@ -903,11 +907,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(1, d2Merge.getConflicts().size());
assertEquals(3, d2Merge.getConflicts().get("x")[0].length);
}
}
@Test
public void testMergeFailingWithDirtyWorkingTree() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call();
@ -942,11 +946,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState());
}
}
@Test
public void testMergeConflictFileFolder() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call();
@ -981,11 +985,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.MERGING, db.getRepositoryState());
}
}
@Test
public void testSuccessfulMergeFailsDueToDirtyIndex() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "a");
RevCommit initialCommit = addAllAndCommit(git);
@ -1017,11 +1021,11 @@ public class MergeCommandTest extends RepositoryTestCase {
checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX,
indexState, fileA);
}
}
@Test
public void testConflictingMergeFailsDueToDirtyIndex() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "a");
RevCommit initialCommit = addAllAndCommit(git);
@ -1055,11 +1059,11 @@ public class MergeCommandTest extends RepositoryTestCase {
checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX,
indexState, fileA);
}
}
@Test
public void testSuccessfulMergeFailsDueToDirtyWorktree() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "a");
RevCommit initialCommit = addAllAndCommit(git);
@ -1090,11 +1094,11 @@ public class MergeCommandTest extends RepositoryTestCase {
checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE,
indexState, fileA);
}
}
@Test
public void testConflictingMergeFailsDueToDirtyWorktree() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "a");
RevCommit initialCommit = addAllAndCommit(git);
@ -1127,6 +1131,7 @@ public class MergeCommandTest extends RepositoryTestCase {
checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE,
indexState, fileA);
}
}
@Test
public void testMergeRemovingFolders() throws Exception {
@ -1143,7 +1148,7 @@ public class MergeCommandTest extends RepositoryTestCase {
file = new File(folder2, "file2.txt");
write(file, "folder2--file2.txt");
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern(folder1.getName())
.addFilepattern(folder2.getName()).call();
RevCommit commit1 = git.commit().setMessage("adding folders").call();
@ -1167,6 +1172,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertFalse(folder1.exists());
assertFalse(folder2.exists());
}
}
@Test
public void testMergeRemovingFoldersWithoutFastForward() throws Exception {
@ -1183,7 +1189,7 @@ public class MergeCommandTest extends RepositoryTestCase {
file = new File(folder2, "file2.txt");
write(file, "folder2--file2.txt");
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern(folder1.getName())
.addFilepattern(folder2.getName()).call();
RevCommit base = git.commit().setMessage("adding folders").call();
@ -1212,14 +1218,13 @@ public class MergeCommandTest extends RepositoryTestCase {
result.getMergeStatus());
assertFalse(folder1.exists());
}
}
@Test
public void testFileModeMerge() throws Exception {
if (!FS.DETECTED.supportsExecute())
return;
// Only Java6
Git git = new Git(db);
assumeTrue(FS.DETECTED.supportsExecute());
try (Git git = new Git(db)) {
writeTrashFile("mergeableMode", "a");
setExecutable(git, "mergeableMode", false);
writeTrashFile("conflictingModeWithBase", "a");
@ -1251,15 +1256,14 @@ public class MergeCommandTest extends RepositoryTestCase {
assertTrue(canExecute(git, "mergeableMode"));
assertFalse(canExecute(git, "conflictingModeNoBase"));
}
}
@Test
public void testFileModeMergeWithDirtyWorkTree() throws Exception {
if (!FS.DETECTED.supportsExecute())
return;
// Only Java6 (or set x bit in index)
assumeTrue(FS.DETECTED.supportsExecute());
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("mergeableButDirty", "a");
setExecutable(git, "mergeableButDirty", false);
RevCommit initialCommit = addAllAndCommit(git);
@ -1284,11 +1288,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeStatus.FAILED, result.getMergeStatus());
assertFalse(canExecute(git, "mergeableButDirty"));
}
}
@Test
public void testSquashFastForward() 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();
@ -1350,11 +1354,11 @@ public class MergeCommandTest extends RepositoryTestCase {
Status stat = git.status().call();
assertEquals(Sets.of("file2", "file3"), stat.getAdded());
}
}
@Test
public void testSquashMerge() 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();
@ -1408,11 +1412,11 @@ public class MergeCommandTest extends RepositoryTestCase {
Status stat = git.status().call();
assertEquals(Sets.of("file3"), stat.getAdded());
}
}
@Test
public void testSquashMergeConflict() 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();
@ -1464,10 +1468,11 @@ public class MergeCommandTest extends RepositoryTestCase {
Status stat = git.status().call();
assertEquals(Sets.of("file2"), stat.getConflicting());
}
}
@Test
public void testFastForwardOnly() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit initialCommit = git.commit().setMessage("initial commit")
.call();
createBranch(initialCommit, "refs/heads/branch1");
@ -1481,10 +1486,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
}
}
@Test
public void testNoFastForward() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit initialCommit = git.commit().setMessage("initial commit")
.call();
createBranch(initialCommit, "refs/heads/branch1");
@ -1498,11 +1504,12 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeStatus.MERGED, result.getMergeStatus());
}
}
@Test
public void testNoFastForwardNoCommit() throws Exception {
// given
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit initialCommit = git.commit().setMessage("initial commit")
.call();
createBranch(initialCommit, "refs/heads/branch1");
@ -1525,10 +1532,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertNull(result.getNewHead());
assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState());
}
}
@Test
public void testFastForwardOnlyNotPossible() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
RevCommit initialCommit = git.commit().setMessage("initial commit")
.call();
createBranch(initialCommit, "refs/heads/branch1");
@ -1544,6 +1552,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeStatus.ABORTED, result.getMergeStatus());
}
}
@Test
public void testRecursiveMergeWithConflict() throws Exception {
@ -1577,8 +1586,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test
public void testMergeWithMessageOption() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -1607,11 +1615,11 @@ public class MergeCommandTest extends RepositoryTestCase {
RevCommit newHead = it.next();
assertEquals("user message", newHead.getFullMessage());
}
}
@Test
public void testMergeConflictWithMessageOption() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -1637,6 +1645,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals("user message\n\nConflicts:\n\ta\n",
db.readMergeCommitMsg());
}
}
private static void setExecutable(Git git, String path, boolean executable) {
FS.DETECTED.setExecute(

4
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java vendored

@ -255,9 +255,11 @@ public class DirCacheBasicTest extends RepositoryTestCase {
DirCacheBuilder b = dc.builder();
DirCacheEntry e = new DirCacheEntry(path);
e.setFileMode(FileMode.REGULAR_FILE);
e.setObjectId(new ObjectInserter.Formatter().idFor(
try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
e.setObjectId(formatter.idFor(
Constants.OBJ_BLOB,
Constants.encode(path)));
}
b.add(e);
b.commit();
db.readDirCache();

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java vendored

@ -78,7 +78,7 @@ public class DirCacheBuilderIteratorTest extends RepositoryTestCase {
final int expIdx = 2;
final DirCacheBuilder b = dc.builder();
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheBuildIterator(b));
tw.setRecursive(true);
tw.setFilter(PathFilterGroup.createFromStrings(Collections
@ -95,6 +95,7 @@ public class DirCacheBuilderIteratorTest extends RepositoryTestCase {
b.add(c.getDirCacheEntry());
assertFalse("no more entries", tw.next());
}
b.finish();
assertEquals(ents.length, dc.getEntryCount());

3
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java vendored

@ -98,7 +98,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
assertEquals(ls.size(), dc.getEntryCount());
{
final Iterator<CGitIndexRecord> rItr = ls.values().iterator();
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc));
while (rItr.hasNext()) {
@ -112,6 +112,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
}
}
}
}
@Test
public void testUnsupportedOptionalExtension() throws Exception {

21
org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheIteratorTest.java vendored

@ -76,10 +76,11 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
final DirCache dc = DirCache.newInCore();
assertEquals(0, dc.getEntryCount());
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheIterator(dc));
assertFalse(tw.next());
}
}
@Test
public void testNoSubtree_NoTreeWalk() throws Exception {
@ -125,7 +126,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.finish();
final DirCacheIterator i = new DirCacheIterator(dc);
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(i);
int pathIdx = 0;
while (tw.next()) {
@ -139,6 +140,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
assertEquals(paths.length, pathIdx);
}
}
@Test
public void testSingleSubtree_NoRecursion() throws Exception {
@ -162,7 +164,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
final int expPos[] = { 0, -1, 4 };
final DirCacheIterator i = new DirCacheIterator(dc);
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(i);
tw.setRecursive(false);
int pathIdx = 0;
@ -183,6 +185,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
assertEquals(expPaths.length, pathIdx);
}
}
@Test
public void testSingleSubtree_Recursive() throws Exception {
@ -202,7 +205,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.finish();
final DirCacheIterator i = new DirCacheIterator(dc);
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(i);
tw.setRecursive(true);
int pathIdx = 0;
@ -218,6 +221,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
assertEquals(paths.length, pathIdx);
}
}
@Test
public void testTwoLevelSubtree_Recursive() throws Exception {
@ -236,7 +240,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.add(ents[i]);
b.finish();
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheIterator(dc));
tw.setRecursive(true);
int pathIdx = 0;
@ -252,6 +256,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
}
assertEquals(paths.length, pathIdx);
}
}
@Test
public void testReset() throws Exception {
@ -397,7 +402,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.add(ents[i]);
b.finish();
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
for (int victimIdx = 0; victimIdx < paths.length; victimIdx++) {
tw.reset();
tw.addTree(new DirCacheIterator(dc));
@ -415,6 +420,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
assertFalse(tw.next());
}
}
}
@Test
public void testRemovedSubtree() throws Exception {
@ -424,7 +430,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
final DirCache dc = DirCache.read(path, FS.DETECTED);
assertEquals(2, dc.getEntryCount());
final TreeWalk tw = new TreeWalk(db);
try (final TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc));
@ -439,3 +445,4 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
assertFalse(tw.next());
}
}
}

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/gitrepo/ManifestParserTest.java

@ -43,8 +43,9 @@
package org.eclipse.jgit.gitrepo;
import static org.junit.Assert.assertTrue;
import static java.nio.charset.StandardCharsets.UTF_8;
import java.io.StringBufferInputStream;
import java.io.ByteArrayInputStream;
import java.util.HashSet;
import java.util.Set;
@ -77,7 +78,7 @@ public class ManifestParserTest {
ManifestParser parser = new ManifestParser(
null, null, "master", baseUrl, null, null);
parser.read(new StringBufferInputStream(xmlContent.toString()));
parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)));
// Unfiltered projects should have them all.
results.clear();
results.add("foo");

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/GcPackRefsTest.java

@ -118,7 +118,7 @@ public class GcPackRefsTest extends GcTestCase {
tr.lightweightTag("t1", a);
tr.lightweightTag("t2", a);
LockFile refLock = new LockFile(new File(repo.getDirectory(),
"refs/tags/t1"), repo.getFS());
"refs/tags/t1"));
try {
refLock.lock();
gc.packRefs();

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/internal/storage/file/LockFileTest.java

@ -61,7 +61,7 @@ public class LockFileTest extends RepositoryTestCase {
@Test
public void lockFailedExceptionRecovery() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call();
RevCommit commit1 = git.commit().setMessage("create file").call();
@ -71,7 +71,7 @@ public class LockFileTest extends RepositoryTestCase {
git.add().addFilepattern("file.txt").call();
assertNotNull(git.commit().setMessage("edit file").call());
LockFile lf = new LockFile(db.getIndexFile(), db.getFS());
LockFile lf = new LockFile(db.getIndexFile());
assertTrue(lf.lock());
try {
git.checkout().setName(commit1.name()).call();
@ -83,3 +83,4 @@ public class LockFileTest extends RepositoryTestCase {
}
}
}
}

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

@ -597,14 +597,13 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
RefUpdate updateRef = db.updateRef("refs/heads/master");
updateRef.setNewObjectId(pid);
LockFile lockFile1 = new LockFile(new File(db.getDirectory(),
"refs/heads/master"), db.getFS());
"refs/heads/master"));
try {
assertTrue(lockFile1.lock()); // precondition to test
Result update = updateRef.update();
assertEquals(Result.LOCK_FAILURE, update);
assertEquals(opid, db.resolve("refs/heads/master"));
LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"),
db.getFS());
LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"));
assertFalse(lockFile2.lock()); // was locked, still is
} finally {
lockFile1.unlock();
@ -747,8 +746,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
"logs/" + fromName).exists());
// "someone" has branch X locked
LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock),
db.getFS());
LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock));
try {
assertTrue(lockFile.lock());

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java

@ -338,7 +338,8 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
*/
private void testMaliciousPath(boolean good, boolean secondCheckout,
String... path) throws GitAPIException, IOException {
Git git = new Git(db);
try (Git git = new Git(db);
RevWalk revWalk = new RevWalk(git.getRepository())) {
ObjectInserter newObjectInserter;
newObjectInserter = git.getRepository().newObjectInserter();
ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB,
@ -379,7 +380,6 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
commitBuilder.setParentId(firstCommitId);
ObjectId commitId = newObjectInserter.insert(commitBuilder);
RevWalk revWalk = new RevWalk(git.getRepository());
if (!secondCheckout)
git.checkout().setStartPoint(revWalk.parseCommit(firstCommitId))
.setName("refs/heads/master").setCreateBranch(true).call();
@ -402,5 +402,6 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
assertTrue(e.getMessage().startsWith("Invalid path"));
}
}
}
}

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

@ -148,8 +148,9 @@ public class IndexDiffTest extends RepositoryTestCase {
writeTrashFile("file2", "file2");
writeTrashFile("dir/file3", "dir/file3");
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern("file2").addFilepattern("dir/file3").call();
}
writeTrashFile("dir/file3", "changed");
@ -177,8 +178,7 @@ public class IndexDiffTest extends RepositoryTestCase {
@Test
public void testConflicting() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call();
@ -202,6 +202,7 @@ public class IndexDiffTest extends RepositoryTestCase {
MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -221,8 +222,7 @@ public class IndexDiffTest extends RepositoryTestCase {
@Test
public void testConflictingDeletedAndModified() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call();
@ -244,6 +244,7 @@ public class IndexDiffTest extends RepositoryTestCase {
MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -262,8 +263,7 @@ public class IndexDiffTest extends RepositoryTestCase {
@Test
public void testConflictingFromMultipleCreations() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -284,6 +284,7 @@ public class IndexDiffTest extends RepositoryTestCase {
MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -304,11 +305,12 @@ public class IndexDiffTest extends RepositoryTestCase {
writeTrashFile("a.c", "a.c");
writeTrashFile("a=c", "a=c");
writeTrashFile("a=d", "a=d");
Git git = new Git(db);
try (Git git = new Git(db)) {
git.add().addFilepattern("a.b").call();
git.add().addFilepattern("a.c").call();
git.add().addFilepattern("a=c").call();
git.add().addFilepattern("a=d").call();
}
TreeFormatter tree = new TreeFormatter();
// got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
@ -338,7 +340,6 @@ public class IndexDiffTest extends RepositoryTestCase {
*/
@Test
public void testUnchangedComplex() throws IOException, GitAPIException {
Git git = new Git(db);
writeTrashFile("a.b", "a.b");
writeTrashFile("a.c", "a.c");
writeTrashFile("a/b.b/b", "a/b.b/b");
@ -346,10 +347,12 @@ public class IndexDiffTest extends RepositoryTestCase {
writeTrashFile("a/c", "a/c");
writeTrashFile("a=c", "a=c");
writeTrashFile("a=d", "a=d");
try (Git git = new Git(db)) {
git.add().addFilepattern("a.b").addFilepattern("a.c")
.addFilepattern("a/b.b/b").addFilepattern("a/b")
.addFilepattern("a/c").addFilepattern("a=c")
.addFilepattern("a=d").call();
}
// got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
@ -397,11 +400,12 @@ public class IndexDiffTest extends RepositoryTestCase {
*/
@Test
public void testRemovedUntracked() throws Exception{
Git git = new Git(db);
String path = "file";
try (Git git = new Git(db)) {
writeTrashFile(path, "content");
git.add().addFilepattern(path).call();
git.commit().setMessage("commit").call();
}
removeFromIndex(path);
FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -417,8 +421,7 @@ public class IndexDiffTest extends RepositoryTestCase {
*/
@Test
public void testUntrackedFolders() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
IndexDiff diff = new IndexDiff(db, Constants.HEAD,
new FileTreeIterator(db));
diff.diff();
@ -463,6 +466,7 @@ public class IndexDiffTest extends RepositoryTestCase {
"target")),
diff.getUntrackedFolders());
}
}
/**
* Test that ignored folders aren't listed as untracked
@ -471,8 +475,7 @@ public class IndexDiffTest extends RepositoryTestCase {
*/
@Test
public void testUntrackedNotIgnoredFolders() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
IndexDiff diff = new IndexDiff(db, Constants.HEAD,
new FileTreeIterator(db));
diff.diff();
@ -510,10 +513,11 @@ public class IndexDiffTest extends RepositoryTestCase {
"target")),
diff.getUntrackedFolders());
}
}
@Test
public void testAssumeUnchanged() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
String path = "file";
writeTrashFile(path, "content");
git.add().addFilepattern(path).call();
@ -551,6 +555,7 @@ public class IndexDiffTest extends RepositoryTestCase {
assertTrue(diff.getChanged().contains("file"));
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
}
}
@Test
public void testStageState() throws IOException {
@ -575,8 +580,7 @@ public class IndexDiffTest extends RepositoryTestCase {
@Test
public void testStageState_mergeAndReset_bug() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "content");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial commit")
@ -635,11 +639,11 @@ public class IndexDiffTest extends RepositoryTestCase {
.get("b"));
assertTrue(diff.getUntrackedFolders().isEmpty());
}
}
@Test
public void testStageState_simulated_bug() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
writeTrashFile("a", "content");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial commit")
@ -688,10 +692,11 @@ public class IndexDiffTest extends RepositoryTestCase {
.get("b"));
assertTrue(diff.getUntrackedFolders().isEmpty());
}
}
@Test
public void testAutoCRLFInput() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
FileBasedConfig config = db.getConfig();
// Make sure core.autocrlf is false before adding
@ -717,6 +722,7 @@ public class IndexDiffTest extends RepositoryTestCase {
"Expected no modified files, but there were: "
+ diff.getModified(), diff.getModified().isEmpty());
}
}
private void verifyStageState(StageState expected, int... stages)
throws IOException {

7
org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexModificationTimesTest.java

@ -49,7 +49,7 @@ public class IndexModificationTimesTest extends RepositoryTestCase {
@Test
public void testLastModifiedTimes() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
String path = "file";
writeTrashFile(path, "content");
String path2 = "file2";
@ -83,10 +83,11 @@ public class IndexModificationTimesTest extends RepositoryTestCase {
assertTrue("last modified shall not be zero!",
entry2.getLastModified() != 0);
}
}
@Test
public void testModify() throws Exception {
Git git = new Git(db);
try (Git git = new Git(db)) {
String path = "file";
writeTrashFile(path, "content");
@ -122,7 +123,7 @@ public class IndexModificationTimesTest extends RepositoryTestCase {
assertTrue("shall have equal mod time!", masterLastMod == sideLastMode);
assertTrue("shall not equal master timestamp!",
entry.getLastModified() == masterLastMod);
}
}
}

2
org.eclipse.jgit.test/tst/org/eclipse/jgit/merge/MergeAlgorithmTest.java

@ -259,7 +259,7 @@ public class MergeAlgorithmTest {
}
private String merge(String commonBase, String ours, String theirs) throws IOException {
MergeResult r = new MergeAlgorithm().merge(RawTextComparator.DEFAULT,
MergeResult<RawText> r = new MergeAlgorithm().merge(RawTextComparator.DEFAULT,
T(commonBase), T(ours), T(theirs));
ByteArrayOutputStream bo=new ByteArrayOutputStream(50);
fmt.formatMerge(bo, r, "B", "O", "T", Constants.CHARACTER_ENCODING);

5
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/ForPathTest.java

@ -84,10 +84,10 @@ public class ForPathTest extends RepositoryTestCase {
ObjectId tree = tree0.writeTree(oi);
// Find the directories that were implicitly created above.
TreeWalk tw = new TreeWalk(or);
tw.addTree(tree);
ObjectId a = null;
ObjectId aSlashC = null;
try (TreeWalk tw = new TreeWalk(or)) {
tw.addTree(tree);
while (tw.next()) {
if (tw.getPathString().equals("a")) {
a = tw.getObjectId(0);
@ -101,6 +101,7 @@ public class ForPathTest extends RepositoryTestCase {
break;
}
}
}
assertEquals(a, TreeWalk.forPath(or, "a", tree).getObjectId(0));
assertEquals(a, TreeWalk.forPath(or, "a/", tree).getObjectId(0));

15
org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/filter/InterIndexDiffFilterTest.java

@ -76,11 +76,12 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
public void testEmpty() throws IOException {
DirCache dc1 = DirCache.newInCore();
DirCache dc2 = DirCache.newInCore();
TreeWalk tw = new TreeWalk(db);
try (TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2));
assertFalse(tw.next());
}
}
static final class AddEdit extends PathEdit {
@ -124,7 +125,7 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
editor.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false));
editor.finish();
TreeWalk tw = new TreeWalk(db);
try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2));
@ -133,6 +134,7 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
assertEquals("a/a", tw.getPathString());
assertFalse(tw.next());
}
}
@Test
public void testTwoSame() throws IOException {
@ -145,7 +147,7 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false));
ed2.finish();
TreeWalk tw = new TreeWalk(db);
try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2));
@ -153,6 +155,7 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
assertFalse(tw.next());
}
}
@Test
public void testTwoSameDifferByAssumeValid() throws IOException {
@ -165,7 +168,7 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, true));
ed2.finish();
TreeWalk tw = new TreeWalk(db);
try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2));
@ -175,6 +178,7 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
assertEquals("a/a", tw.getPathString());
assertFalse(tw.next());
}
}
@Test
public void testTwoSameSameAssumeValidDifferentContent()
@ -188,7 +192,7 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("b"), 1, true));
ed2.finish();
TreeWalk tw = new TreeWalk(db);
try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2));
@ -197,3 +201,4 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
assertFalse(tw.next());
}
}
}

6
org.eclipse.jgit/src/org/eclipse/jgit/dircache/DirCache.java vendored

@ -344,9 +344,6 @@ public class DirCache {
/** Our active lock (if we hold it); null if we don't have it locked. */
private LockFile myLock;
/** file system abstraction **/
private final FS fs;
/** Keep track of whether the index has changed or not */
private FileSnapshot snapshot;
@ -376,7 +373,6 @@ public class DirCache {
*/
public DirCache(final File indexLocation, final FS fs) {
liveFile = indexLocation;
this.fs = fs;
clear();
}
@ -611,7 +607,7 @@ public class DirCache {
public boolean lock() throws IOException {
if (liveFile == null)
throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile);
final LockFile tmp = new LockFile(liveFile, fs);
final LockFile tmp = new LockFile(liveFile);
if (tmp.lock()) {
tmp.setNeedStatInformation(true);
myLock = tmp;

4
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/dfs/InMemoryRepository.java

@ -274,7 +274,7 @@ public class InMemoryRepository extends DfsRepository {
if (performsAtomicTransactions()) {
try {
lock.writeLock().lock();
batch(walk, getCommands());
batch(getCommands());
} finally {
lock.writeLock().unlock();
}
@ -304,7 +304,7 @@ public class InMemoryRepository extends DfsRepository {
return new RefCache(ids.toRefList(), sym.toRefList());
}
private void batch(RevWalk walk, List<ReceiveCommand> cmds) {
private void batch(List<ReceiveCommand> cmds) {
// Validate that the target exists in a new RevWalk, as the RevWalk
// from the RefUpdate might be reading back unflushed objects.
Map<ObjectId, ObjectId> peeled = new HashMap<>();

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/FileRepository.java

@ -354,7 +354,7 @@ public class FileRepository extends Repository {
ConfigConstants.CONFIG_KEY_WORKTREE, getWorkTree()
.getAbsolutePath());
LockFile dotGitLockFile = new LockFile(new File(workTree,
Constants.DOT_GIT), getFS());
Constants.DOT_GIT));
try {
if (dotGitLockFile.lock()) {
dotGitLockFile.write(Constants.encode(Constants.GITDIR

4
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/PackLock.java

@ -53,7 +53,6 @@ import org.eclipse.jgit.util.FileUtils;
/** Keeps track of a {@link PackFile}'s associated <code>.keep</code> file. */
public class PackLock {
private final File keepFile;
private final FS fs;
/**
* Create a new lock for a pack file.
@ -67,7 +66,6 @@ public class PackLock {
final File p = packFile.getParentFile();
final String n = packFile.getName();
keepFile = new File(p, n.substring(0, n.length() - 5) + ".keep"); //$NON-NLS-1$
this.fs = fs;
}
/**
@ -84,7 +82,7 @@ public class PackLock {
return false;
if (!msg.endsWith("\n")) //$NON-NLS-1$
msg += "\n"; //$NON-NLS-1$
final LockFile lf = new LockFile(keepFile, fs);
final LockFile lf = new LockFile(keepFile);
if (!lf.lock())
return false;
lf.write(Constants.encode(msg));

8
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectory.java

@ -588,8 +588,7 @@ public class RefDirectory extends RefDatabase {
// we don't miss an edit made externally.
final PackedRefList packed = getPackedRefs();
if (packed.contains(name)) {
LockFile lck = new LockFile(packedRefsFile,
update.getRepository().getFS());
LockFile lck = new LockFile(packedRefsFile);
if (!lck.lock())
throw new LockFailedException(packedRefsFile);
try {
@ -639,7 +638,7 @@ public class RefDirectory extends RefDatabase {
FS fs = parent.getFS();
// Lock the packed refs file and read the content
LockFile lck = new LockFile(packedRefsFile, fs);
LockFile lck = new LockFile(packedRefsFile);
if (!lck.lock())
throw new IOException(MessageFormat.format(
JGitText.get().cannotLock, packedRefsFile));
@ -670,8 +669,7 @@ public class RefDirectory extends RefDatabase {
File refFile = fileFor(refName);
if (!fs.exists(refFile))
continue;
LockFile rLck = new LockFile(refFile,
parent.getFS());
LockFile rLck = new LockFile(refFile);
if (!rLck.lock())
continue;
try {

2
org.eclipse.jgit/src/org/eclipse/jgit/internal/storage/file/RefDirectoryUpdate.java

@ -79,7 +79,7 @@ class RefDirectoryUpdate extends RefUpdate {
if (deref)
dst = dst.getLeaf();
String name = dst.getName();
lock = new LockFile(database.fileFor(name), getRepository().getFS());
lock = new LockFile(database.fileFor(name));
if (lock.lock()) {
dst = database.getRef(name);
setOldObjectId(dst != null ? dst.getObjectId() : null);

2
org.eclipse.jgit/src/org/eclipse/jgit/merge/MergeFormatter.java

@ -102,7 +102,7 @@ public class MergeFormatter {
* metadata
* @throws IOException
*/
public void formatMerge(OutputStream out, MergeResult res, String baseName,
public void formatMerge(OutputStream out, MergeResult<RawText> res, String baseName,
String oursName, String theirsName, String charsetName) throws IOException {
List<String> names = new ArrayList<String>(3);
names.add(baseName);

5
org.eclipse.jgit/src/org/eclipse/jgit/storage/file/FileBasedConfig.java

@ -74,8 +74,6 @@ import org.eclipse.jgit.util.RawParseUtils;
public class FileBasedConfig extends StoredConfig {
private final File configFile;
private final FS fs;
private boolean utf8Bom;
private volatile FileSnapshot snapshot;
@ -109,7 +107,6 @@ public class FileBasedConfig extends StoredConfig {
public FileBasedConfig(Config base, File cfgLocation, FS fs) {
super(base);
configFile = cfgLocation;
this.fs = fs;
this.snapshot = FileSnapshot.DIRTY;
this.hash = ObjectId.zeroId();
}
@ -203,7 +200,7 @@ public class FileBasedConfig extends StoredConfig {
out = Constants.encode(text);
}
final LockFile lf = new LockFile(getFile(), fs);
final LockFile lf = new LockFile(getFile());
if (!lf.lock())
throw new LockFailedException(getFile());
try {

3
org.eclipse.jgit/src/org/eclipse/jgit/transport/FetchProcess.java

@ -314,8 +314,7 @@ class FetchProcess {
File meta = transport.local.getDirectory();
if (meta == null)
return;
final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD"), //$NON-NLS-1$
transport.local.getFS());
final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD")); //$NON-NLS-1$
try {
if (lock.lock()) {
final Writer w = new OutputStreamWriter(lock.getOutputStream());

Loading…
Cancel
Save