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(); factory = new DefaultReceivePackFactory();
} }
@SuppressWarnings("unchecked")
@Test @Test
public void testDisabledSingleton() throws ServiceNotAuthorizedException { public void testDisabledSingleton() throws ServiceNotAuthorizedException {
factory = (ReceivePackFactory<HttpServletRequest>) ReceivePackFactory.DISABLED; 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(); factory = new DefaultUploadPackFactory();
} }
@SuppressWarnings("unchecked")
@Test @Test
public void testDisabledSingleton() throws ServiceNotAuthorizedException { public void testDisabledSingleton() throws ServiceNotAuthorizedException {
factory = (UploadPackFactory<HttpServletRequest>) UploadPackFactory.DISABLED; 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); return parameters.get(name);
} }
public Enumeration getInitParameterNames() { public Enumeration<String> getInitParameterNames() {
final Iterator<String> i = parameters.keySet().iterator(); final Iterator<String> i = parameters.keySet().iterator();
return new Enumeration<String>() { return new Enumeration<String>() {
public boolean hasMoreElements() { 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, private void writeFile(final File p, final byte[] bin) throws IOException,
ObjectWritingException { ObjectWritingException {
final LockFile lck = new LockFile(p, db.getFS()); final LockFile lck = new LockFile(p);
if (!lck.lock()) if (!lck.lock())
throw new ObjectWritingException("Can't write " + p); throw new ObjectWritingException("Can't write " + p);
try { try {

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

@ -155,16 +155,16 @@ class DiffAlgorithms extends TextBuiltin {
else else
rb.findGitDir(dir); rb.findGitDir(dir);
Repository db = rb.build(); Repository repo = rb.build();
try { try {
run(db); run(repo);
} finally { } finally {
db.close(); repo.close();
} }
} }
} }
private void run(Repository db) throws Exception { private void run(Repository repo) throws Exception {
List<Test> all = init(); List<Test> all = init();
long files = 0; long files = 0;
@ -173,14 +173,14 @@ class DiffAlgorithms extends TextBuiltin {
int maxN = 0; int maxN = 0;
AbbreviatedObjectId startId; AbbreviatedObjectId startId;
try (ObjectReader or = db.newObjectReader(); try (ObjectReader or = repo.newObjectReader();
RevWalk rw = new RevWalk(or)) { RevWalk rw = new RevWalk(or)) {
final MutableObjectId id = new MutableObjectId(); final MutableObjectId id = new MutableObjectId();
TreeWalk tw = new TreeWalk(or); TreeWalk tw = new TreeWalk(or);
tw.setFilter(TreeFilter.ANY_DIFF); tw.setFilter(TreeFilter.ANY_DIFF);
tw.setRecursive(true); tw.setRecursive(true);
ObjectId start = db.resolve(Constants.HEAD); ObjectId start = repo.resolve(Constants.HEAD);
startId = or.abbreviate(start); startId = or.abbreviate(start);
rw.markStart(rw.parseCommit(start)); rw.markStart(rw.parseCommit(start));
for (;;) { for (;;) {
@ -235,14 +235,15 @@ class DiffAlgorithms extends TextBuiltin {
Collections.sort(all, new Comparator<Test>() { Collections.sort(all, new Comparator<Test>() {
public int compare(Test a, Test b) { public int compare(Test a, Test b) {
int cmp = Long.signum(a.runningTimeNanos - b.runningTimeNanos); int result = Long.signum(a.runningTimeNanos - b.runningTimeNanos);
if (cmp == 0) if (result == 0) {
cmp = a.algorithm.name.compareTo(b.algorithm.name); result = a.algorithm.name.compareTo(b.algorithm.name);
return cmp; }
return result;
} }
}); });
File directory = db.getDirectory(); File directory = repo.getDirectory();
if (directory != null) { if (directory != null) {
String name = directory.getName(); String name = directory.getName();
File parent = directory.getParentFile(); 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); final ObjectId id = db.resolve(Constants.HEAD);
if (!ObjectId.isId(head) && id != null) { if (!ObjectId.isId(head) && id != null) {
final LockFile lf; 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()) if (!lf.lock())
throw new IOException(MessageFormat.format(CLIText.get().cannotLock, Constants.HEAD)); throw new IOException(MessageFormat.format(CLIText.get().cannotLock, Constants.HEAD));
lf.write(id); lf.write(id);
@ -263,7 +263,7 @@ class RebuildCommitGraph extends TextBuiltin {
protected void writeFile(final String name, final byte[] content) protected void writeFile(final String name, final byte[] content)
throws IOException { throws IOException {
final File file = new File(db.getDirectory(), name); 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()) if (!lck.lock())
throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file)); throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file));
try { try {

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

@ -66,11 +66,12 @@ public class GitConstructionTest extends RepositoryTestCase {
@Before @Before
public void setUp() throws Exception { public void setUp() throws Exception {
super.setUp(); super.setUp();
Git git = new Git(db); try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
writeTrashFile("Test.txt", "Hello world"); writeTrashFile("Test.txt", "Hello world");
git.add().addFilepattern("Test.txt").call(); git.add().addFilepattern("Test.txt").call();
git.commit().setMessage("Initial commit").call(); git.commit().setMessage("Initial commit").call();
}
bareRepo = Git.cloneRepository().setBare(true) bareRepo = Git.cloneRepository().setBare(true)
.setURI(db.getDirectory().toURI().toString()) .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.api.ResetCommand.ResetType;
import org.eclipse.jgit.junit.RepositoryTestCase; import org.eclipse.jgit.junit.RepositoryTestCase;
import org.junit.After;
import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
@ -60,12 +62,26 @@ public class HugeFileTest extends RepositoryTestCase {
private long lastt = t; private long lastt = t;
private Git git;
private void measure(String name) { private void measure(String name) {
long c = System.currentTimeMillis(); long c = System.currentTimeMillis();
System.out.println(name + ", dt=" + (c - lastt) / 1000.0 + "s"); System.out.println(name + ", dt=" + (c - lastt) / 1000.0 + "s");
lastt = c; 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") @Ignore("Test takes way too long (~10 minutes) to be part of the standard suite")
@Test @Test
public void testAddHugeFile() throws Exception { public void testAddHugeFile() throws Exception {
@ -75,7 +91,6 @@ public class HugeFileTest extends RepositoryTestCase {
rf.setLength(4429185024L); rf.setLength(4429185024L);
rf.close(); rf.close();
measure("Created file"); measure("Created file");
Git git = new Git(db);
git.add().addFilepattern("a.txt").call(); git.add().addFilepattern("a.txt").call();
measure("Added file"); 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.assertNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import java.io.File; import java.io.File;
import java.util.Iterator; import java.util.Iterator;
@ -96,11 +97,12 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test @Test
public void testMergeInItself() throws Exception { public void testMergeInItself() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
git.commit().setMessage("initial commit").call(); git.commit().setMessage("initial commit").call();
MergeResult result = git.merge().include(db.exactRef(Constants.HEAD)).call(); MergeResult result = git.merge().include(db.exactRef(Constants.HEAD)).call();
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus());
}
// no reflog entry written by merge // no reflog entry written by merge
assertEquals("commit (initial): initial commit", assertEquals("commit (initial): initial commit",
db db
@ -112,7 +114,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test @Test
public void testAlreadyUpToDate() throws Exception { public void testAlreadyUpToDate() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("initial commit").call(); RevCommit first = git.commit().setMessage("initial commit").call();
createBranch(first, "refs/heads/branch1"); 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(); MergeResult result = git.merge().include(db.exactRef("refs/heads/branch1")).call();
assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus()); assertEquals(MergeResult.MergeStatus.ALREADY_UP_TO_DATE, result.getMergeStatus());
assertEquals(second, result.getNewHead()); assertEquals(second, result.getNewHead());
}
// no reflog entry written by merge // no reflog entry written by merge
assertEquals("commit: second commit", db assertEquals("commit: second commit", db
.getReflogReader(Constants.HEAD).getLastEntry().getComment()); .getReflogReader(Constants.HEAD).getLastEntry().getComment());
@ -129,7 +132,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test @Test
public void testFastForward() throws Exception { public void testFastForward() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("initial commit").call(); RevCommit first = git.commit().setMessage("initial commit").call();
createBranch(first, "refs/heads/branch1"); createBranch(first, "refs/heads/branch1");
@ -141,6 +144,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead()); assertEquals(second, result.getNewHead());
}
assertEquals("merge refs/heads/master: Fast-forward", assertEquals("merge refs/heads/master: Fast-forward",
db.getReflogReader(Constants.HEAD).getLastEntry().getComment()); db.getReflogReader(Constants.HEAD).getLastEntry().getComment());
assertEquals("merge refs/heads/master: Fast-forward", assertEquals("merge refs/heads/master: Fast-forward",
@ -149,7 +153,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test @Test
public void testFastForwardNoCommit() throws Exception { public void testFastForwardNoCommit() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("initial commit").call(); RevCommit first = git.commit().setMessage("initial commit").call();
createBranch(first, "refs/heads/branch1"); createBranch(first, "refs/heads/branch1");
@ -163,6 +167,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, assertEquals(MergeResult.MergeStatus.FAST_FORWARD,
result.getMergeStatus()); result.getMergeStatus());
assertEquals(second, result.getNewHead()); assertEquals(second, result.getNewHead());
}
assertEquals("merge refs/heads/master: Fast-forward", db assertEquals("merge refs/heads/master: Fast-forward", db
.getReflogReader(Constants.HEAD).getLastEntry().getComment()); .getReflogReader(Constants.HEAD).getLastEntry().getComment());
assertEquals("merge refs/heads/master: Fast-forward", db assertEquals("merge refs/heads/master: Fast-forward", db
@ -171,8 +176,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test @Test
public void testFastForwardWithFiles() throws Exception { public void testFastForwardWithFiles() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("file1", "file1"); writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call(); git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("initial commit").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()); assertTrue(new File(db.getWorkTree(), "file2").exists());
assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals(MergeResult.MergeStatus.FAST_FORWARD, result.getMergeStatus());
assertEquals(second, result.getNewHead()); assertEquals(second, result.getNewHead());
}
assertEquals("merge refs/heads/master: Fast-forward", assertEquals("merge refs/heads/master: Fast-forward",
db.getReflogReader(Constants.HEAD).getLastEntry().getComment()); db.getReflogReader(Constants.HEAD).getLastEntry().getComment());
assertEquals("merge refs/heads/master: Fast-forward", assertEquals("merge refs/heads/master: Fast-forward",
@ -202,8 +207,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test @Test
public void testMultipleHeads() throws Exception { public void testMultipleHeads() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("file1", "file1"); writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call(); git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("initial commit").call(); RevCommit first = git.commit().setMessage("initial commit").call();
@ -231,12 +235,12 @@ public class MergeCommandTest extends RepositoryTestCase {
// expected this exception // expected this exception
} }
} }
}
@Theory @Theory
public void testMergeSuccessAllStrategies(MergeStrategy mergeStrategy) public void testMergeSuccessAllStrategies(MergeStrategy mergeStrategy)
throws Exception { throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("first").call(); RevCommit first = git.commit().setMessage("first").call();
createBranch(first, "refs/heads/side"); createBranch(first, "refs/heads/side");
@ -252,6 +256,7 @@ public class MergeCommandTest extends RepositoryTestCase {
MergeResult result = git.merge().setStrategy(mergeStrategy) MergeResult result = git.merge().setStrategy(mergeStrategy)
.include(db.exactRef(R_HEADS + MASTER)).call(); .include(db.exactRef(R_HEADS + MASTER)).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); assertEquals(MergeStatus.MERGED, result.getMergeStatus());
}
assertEquals( assertEquals(
"merge refs/heads/master: Merge made by " "merge refs/heads/master: Merge made by "
+ mergeStrategy.getName() + ".", + mergeStrategy.getName() + ".",
@ -265,8 +270,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Theory @Theory
public void testMergeSuccessAllStrategiesNoCommit( public void testMergeSuccessAllStrategiesNoCommit(
MergeStrategy mergeStrategy) throws Exception { MergeStrategy mergeStrategy) throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
RevCommit first = git.commit().setMessage("first").call(); RevCommit first = git.commit().setMessage("first").call();
createBranch(first, "refs/heads/side"); createBranch(first, "refs/heads/side");
@ -286,11 +290,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(), assertEquals(db.exactRef(Constants.HEAD).getTarget().getObjectId(),
thirdCommit.getId()); thirdCommit.getId());
} }
}
@Test @Test
public void testContentMerge() throws Exception { public void testContentMerge() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("c/c/c", "1\nc\n3\n"); writeTrashFile("c/c/c", "1\nc\n3\n");
@ -331,11 +335,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.MERGING, db.getRepositoryState()); assertEquals(RepositoryState.MERGING, db.getRepositoryState());
} }
}
@Test @Test
public void testMergeTag() throws Exception { public void testMergeTag() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "a"); writeTrashFile("a", "a");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").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(); MergeResult result = git.merge().include(tag).setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); assertEquals(MergeStatus.MERGED, result.getMergeStatus());
} }
}
@Test @Test
public void testMergeMessage() throws Exception { public void testMergeMessage() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").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", assertEquals("Merge branch 'side'\n\nConflicts:\n\ta\n",
db.readMergeCommitMsg()); db.readMergeCommitMsg());
}
} }
@Test @Test
public void testMergeNonVersionedPaths() throws Exception { public void testMergeNonVersionedPaths() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("c/c/c", "1\nc\n3\n"); writeTrashFile("c/c/c", "1\nc\n3\n");
@ -440,11 +444,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.MERGING, db.getRepositoryState()); assertEquals(RepositoryState.MERGING, db.getRepositoryState());
} }
}
@Test @Test
public void testMultipleCreations() throws Exception { public void testMultipleCreations() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call(); RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -466,11 +470,11 @@ public class MergeCommandTest extends RepositoryTestCase {
.setStrategy(MergeStrategy.RESOLVE).call(); .setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
} }
}
@Test @Test
public void testMultipleCreationsSameContent() throws Exception { public void testMultipleCreationsSameContent() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call(); RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -501,11 +505,11 @@ public class MergeCommandTest extends RepositoryTestCase {
.getReflogReader(db.getBranch()) .getReflogReader(db.getBranch())
.getLastEntry().getComment()); .getLastEntry().getComment());
} }
}
@Test @Test
public void testSuccessfulContentMerge() throws Exception { public void testSuccessfulContentMerge() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("c/c/c", "1\nc\n3\n"); writeTrashFile("c/c/c", "1\nc\n3\n");
@ -559,11 +563,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); assertEquals(RepositoryState.SAFE, db.getRepositoryState());
// test index state // test index state
} }
}
@Test @Test
public void testSuccessfulContentMergeNoCommit() throws Exception { public void testSuccessfulContentMergeNoCommit() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("c/c/c", "1\nc\n3\n"); writeTrashFile("c/c/c", "1\nc\n3\n");
@ -609,12 +613,12 @@ public class MergeCommandTest extends RepositoryTestCase {
assertNull(result.getNewHead()); assertNull(result.getNewHead());
assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState()); assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState());
} }
}
@Test @Test
public void testSuccessfulContentMergeAndDirtyworkingTree() public void testSuccessfulContentMergeAndDirtyworkingTree()
throws Exception { throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("d", "1\nd\n3\n"); writeTrashFile("d", "1\nd\n3\n");
@ -670,11 +674,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); assertEquals(RepositoryState.SAFE, db.getRepositoryState());
} }
}
@Test @Test
public void testSingleDeletion() throws Exception { public void testSingleDeletion() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("d", "1\nd\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"))); read(new File(db.getWorkTree(), "c/c/c")));
assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d"))); assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d")));
} }
}
@Test @Test
public void testMultipleDeletions() throws Exception { public void testMultipleDeletions() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call(); RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -754,11 +758,11 @@ public class MergeCommandTest extends RepositoryTestCase {
.setStrategy(MergeStrategy.RESOLVE).call(); .setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); assertEquals(MergeStatus.MERGED, result.getMergeStatus());
} }
}
@Test @Test
public void testDeletionAndConflict() throws Exception { public void testDeletionAndConflict() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
writeTrashFile("d", "1\nd\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"))); read(new File(db.getWorkTree(), "c/c/c")));
assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d"))); assertEquals("1\nd\n3\n", read(new File(db.getWorkTree(), "d")));
} }
}
@Test @Test
public void testDeletionOnMasterConflict() throws Exception { public void testDeletionOnMasterConflict() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call(); 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\na(side)\n3\n", read(new File(db.getWorkTree(), "a")));
assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b"))); assertEquals("1\nb\n3\n", read(new File(db.getWorkTree(), "b")));
} }
}
@Test @Test
public void testDeletionOnSideConflict() throws Exception { public void testDeletionOnSideConflict() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call(); git.add().addFilepattern("a").addFilepattern("b").call();
@ -864,14 +868,14 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(1, result.getConflicts().size()); assertEquals(1, result.getConflicts().size());
assertEquals(3, result.getConflicts().get("a")[0].length); assertEquals(3, result.getConflicts().get("a")[0].length);
} }
}
@Test @Test
public void testModifiedAndRenamed() throws Exception { public void testModifiedAndRenamed() throws Exception {
// this test is essentially the same as testDeletionOnSideConflict, // this test is essentially the same as testDeletionOnSideConflict,
// however if once rename support is added this test should result in a // however if once rename support is added this test should result in a
// successful merge instead of a conflict // successful merge instead of a conflict
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("x", "add x"); writeTrashFile("x", "add x");
git.add().addFilepattern("x").call(); git.add().addFilepattern("x").call();
RevCommit initial = git.commit().setMessage("add 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(1, d2Merge.getConflicts().size());
assertEquals(3, d2Merge.getConflicts().get("x")[0].length); assertEquals(3, d2Merge.getConflicts().get("x")[0].length);
} }
}
@Test @Test
public void testMergeFailingWithDirtyWorkingTree() throws Exception { public void testMergeFailingWithDirtyWorkingTree() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call(); git.add().addFilepattern("a").addFilepattern("b").call();
@ -942,11 +946,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.SAFE, db.getRepositoryState()); assertEquals(RepositoryState.SAFE, db.getRepositoryState());
} }
}
@Test @Test
public void testMergeConflictFileFolder() throws Exception { public void testMergeConflictFileFolder() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call(); git.add().addFilepattern("a").addFilepattern("b").call();
@ -981,11 +985,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(RepositoryState.MERGING, db.getRepositoryState()); assertEquals(RepositoryState.MERGING, db.getRepositoryState());
} }
}
@Test @Test
public void testSuccessfulMergeFailsDueToDirtyIndex() throws Exception { public void testSuccessfulMergeFailsDueToDirtyIndex() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "a"); File fileA = writeTrashFile("a", "a");
RevCommit initialCommit = addAllAndCommit(git); RevCommit initialCommit = addAllAndCommit(git);
@ -1017,11 +1021,11 @@ public class MergeCommandTest extends RepositoryTestCase {
checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX, checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX,
indexState, fileA); indexState, fileA);
} }
}
@Test @Test
public void testConflictingMergeFailsDueToDirtyIndex() throws Exception { public void testConflictingMergeFailsDueToDirtyIndex() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "a"); File fileA = writeTrashFile("a", "a");
RevCommit initialCommit = addAllAndCommit(git); RevCommit initialCommit = addAllAndCommit(git);
@ -1055,11 +1059,11 @@ public class MergeCommandTest extends RepositoryTestCase {
checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX, checkMergeFailedResult(result, MergeFailureReason.DIRTY_INDEX,
indexState, fileA); indexState, fileA);
} }
}
@Test @Test
public void testSuccessfulMergeFailsDueToDirtyWorktree() throws Exception { public void testSuccessfulMergeFailsDueToDirtyWorktree() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "a"); File fileA = writeTrashFile("a", "a");
RevCommit initialCommit = addAllAndCommit(git); RevCommit initialCommit = addAllAndCommit(git);
@ -1090,11 +1094,11 @@ public class MergeCommandTest extends RepositoryTestCase {
checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE, checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE,
indexState, fileA); indexState, fileA);
} }
}
@Test @Test
public void testConflictingMergeFailsDueToDirtyWorktree() throws Exception { public void testConflictingMergeFailsDueToDirtyWorktree() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
File fileA = writeTrashFile("a", "a"); File fileA = writeTrashFile("a", "a");
RevCommit initialCommit = addAllAndCommit(git); RevCommit initialCommit = addAllAndCommit(git);
@ -1127,6 +1131,7 @@ public class MergeCommandTest extends RepositoryTestCase {
checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE, checkMergeFailedResult(result, MergeFailureReason.DIRTY_WORKTREE,
indexState, fileA); indexState, fileA);
} }
}
@Test @Test
public void testMergeRemovingFolders() throws Exception { public void testMergeRemovingFolders() throws Exception {
@ -1143,7 +1148,7 @@ public class MergeCommandTest extends RepositoryTestCase {
file = new File(folder2, "file2.txt"); file = new File(folder2, "file2.txt");
write(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()) git.add().addFilepattern(folder1.getName())
.addFilepattern(folder2.getName()).call(); .addFilepattern(folder2.getName()).call();
RevCommit commit1 = git.commit().setMessage("adding folders").call(); RevCommit commit1 = git.commit().setMessage("adding folders").call();
@ -1167,6 +1172,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertFalse(folder1.exists()); assertFalse(folder1.exists());
assertFalse(folder2.exists()); assertFalse(folder2.exists());
} }
}
@Test @Test
public void testMergeRemovingFoldersWithoutFastForward() throws Exception { public void testMergeRemovingFoldersWithoutFastForward() throws Exception {
@ -1183,7 +1189,7 @@ public class MergeCommandTest extends RepositoryTestCase {
file = new File(folder2, "file2.txt"); file = new File(folder2, "file2.txt");
write(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()) git.add().addFilepattern(folder1.getName())
.addFilepattern(folder2.getName()).call(); .addFilepattern(folder2.getName()).call();
RevCommit base = git.commit().setMessage("adding folders").call(); RevCommit base = git.commit().setMessage("adding folders").call();
@ -1212,14 +1218,13 @@ public class MergeCommandTest extends RepositoryTestCase {
result.getMergeStatus()); result.getMergeStatus());
assertFalse(folder1.exists()); assertFalse(folder1.exists());
} }
}
@Test @Test
public void testFileModeMerge() throws Exception { public void testFileModeMerge() throws Exception {
if (!FS.DETECTED.supportsExecute())
return;
// Only Java6 // Only Java6
Git git = new Git(db); assumeTrue(FS.DETECTED.supportsExecute());
try (Git git = new Git(db)) {
writeTrashFile("mergeableMode", "a"); writeTrashFile("mergeableMode", "a");
setExecutable(git, "mergeableMode", false); setExecutable(git, "mergeableMode", false);
writeTrashFile("conflictingModeWithBase", "a"); writeTrashFile("conflictingModeWithBase", "a");
@ -1251,15 +1256,14 @@ public class MergeCommandTest extends RepositoryTestCase {
assertTrue(canExecute(git, "mergeableMode")); assertTrue(canExecute(git, "mergeableMode"));
assertFalse(canExecute(git, "conflictingModeNoBase")); assertFalse(canExecute(git, "conflictingModeNoBase"));
} }
}
@Test @Test
public void testFileModeMergeWithDirtyWorkTree() throws Exception { public void testFileModeMergeWithDirtyWorkTree() throws Exception {
if (!FS.DETECTED.supportsExecute())
return;
// Only Java6 (or set x bit in index) // 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"); writeTrashFile("mergeableButDirty", "a");
setExecutable(git, "mergeableButDirty", false); setExecutable(git, "mergeableButDirty", false);
RevCommit initialCommit = addAllAndCommit(git); RevCommit initialCommit = addAllAndCommit(git);
@ -1284,11 +1288,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeStatus.FAILED, result.getMergeStatus()); assertEquals(MergeStatus.FAILED, result.getMergeStatus());
assertFalse(canExecute(git, "mergeableButDirty")); assertFalse(canExecute(git, "mergeableButDirty"));
} }
}
@Test @Test
public void testSquashFastForward() throws Exception { public void testSquashFastForward() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("file1", "file1"); writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call(); git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("initial commit").call(); RevCommit first = git.commit().setMessage("initial commit").call();
@ -1350,11 +1354,11 @@ public class MergeCommandTest extends RepositoryTestCase {
Status stat = git.status().call(); Status stat = git.status().call();
assertEquals(Sets.of("file2", "file3"), stat.getAdded()); assertEquals(Sets.of("file2", "file3"), stat.getAdded());
} }
}
@Test @Test
public void testSquashMerge() throws Exception { public void testSquashMerge() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("file1", "file1"); writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call(); git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("initial commit").call(); RevCommit first = git.commit().setMessage("initial commit").call();
@ -1408,11 +1412,11 @@ public class MergeCommandTest extends RepositoryTestCase {
Status stat = git.status().call(); Status stat = git.status().call();
assertEquals(Sets.of("file3"), stat.getAdded()); assertEquals(Sets.of("file3"), stat.getAdded());
} }
}
@Test @Test
public void testSquashMergeConflict() throws Exception { public void testSquashMergeConflict() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("file1", "file1"); writeTrashFile("file1", "file1");
git.add().addFilepattern("file1").call(); git.add().addFilepattern("file1").call();
RevCommit first = git.commit().setMessage("initial commit").call(); RevCommit first = git.commit().setMessage("initial commit").call();
@ -1464,10 +1468,11 @@ public class MergeCommandTest extends RepositoryTestCase {
Status stat = git.status().call(); Status stat = git.status().call();
assertEquals(Sets.of("file2"), stat.getConflicting()); assertEquals(Sets.of("file2"), stat.getConflicting());
} }
}
@Test @Test
public void testFastForwardOnly() throws Exception { public void testFastForwardOnly() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
RevCommit initialCommit = git.commit().setMessage("initial commit") RevCommit initialCommit = git.commit().setMessage("initial commit")
.call(); .call();
createBranch(initialCommit, "refs/heads/branch1"); createBranch(initialCommit, "refs/heads/branch1");
@ -1481,10 +1486,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus()); assertEquals(MergeStatus.FAST_FORWARD, result.getMergeStatus());
} }
}
@Test @Test
public void testNoFastForward() throws Exception { public void testNoFastForward() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
RevCommit initialCommit = git.commit().setMessage("initial commit") RevCommit initialCommit = git.commit().setMessage("initial commit")
.call(); .call();
createBranch(initialCommit, "refs/heads/branch1"); createBranch(initialCommit, "refs/heads/branch1");
@ -1498,11 +1504,12 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeStatus.MERGED, result.getMergeStatus()); assertEquals(MergeStatus.MERGED, result.getMergeStatus());
} }
}
@Test @Test
public void testNoFastForwardNoCommit() throws Exception { public void testNoFastForwardNoCommit() throws Exception {
// given // given
Git git = new Git(db); try (Git git = new Git(db)) {
RevCommit initialCommit = git.commit().setMessage("initial commit") RevCommit initialCommit = git.commit().setMessage("initial commit")
.call(); .call();
createBranch(initialCommit, "refs/heads/branch1"); createBranch(initialCommit, "refs/heads/branch1");
@ -1525,10 +1532,11 @@ public class MergeCommandTest extends RepositoryTestCase {
assertNull(result.getNewHead()); assertNull(result.getNewHead());
assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState()); assertEquals(RepositoryState.MERGING_RESOLVED, db.getRepositoryState());
} }
}
@Test @Test
public void testFastForwardOnlyNotPossible() throws Exception { public void testFastForwardOnlyNotPossible() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
RevCommit initialCommit = git.commit().setMessage("initial commit") RevCommit initialCommit = git.commit().setMessage("initial commit")
.call(); .call();
createBranch(initialCommit, "refs/heads/branch1"); createBranch(initialCommit, "refs/heads/branch1");
@ -1544,6 +1552,7 @@ public class MergeCommandTest extends RepositoryTestCase {
assertEquals(MergeStatus.ABORTED, result.getMergeStatus()); assertEquals(MergeStatus.ABORTED, result.getMergeStatus());
} }
}
@Test @Test
public void testRecursiveMergeWithConflict() throws Exception { public void testRecursiveMergeWithConflict() throws Exception {
@ -1577,8 +1586,7 @@ public class MergeCommandTest extends RepositoryTestCase {
@Test @Test
public void testMergeWithMessageOption() throws Exception { public void testMergeWithMessageOption() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call(); RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -1607,11 +1615,11 @@ public class MergeCommandTest extends RepositoryTestCase {
RevCommit newHead = it.next(); RevCommit newHead = it.next();
assertEquals("user message", newHead.getFullMessage()); assertEquals("user message", newHead.getFullMessage());
} }
}
@Test @Test
public void testMergeConflictWithMessageOption() throws Exception { public void testMergeConflictWithMessageOption() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").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", assertEquals("user message\n\nConflicts:\n\ta\n",
db.readMergeCommitMsg()); db.readMergeCommitMsg());
} }
}
private static void setExecutable(Git git, String path, boolean executable) { private static void setExecutable(Git git, String path, boolean executable) {
FS.DETECTED.setExecute( 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(); DirCacheBuilder b = dc.builder();
DirCacheEntry e = new DirCacheEntry(path); DirCacheEntry e = new DirCacheEntry(path);
e.setFileMode(FileMode.REGULAR_FILE); 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.OBJ_BLOB,
Constants.encode(path))); Constants.encode(path)));
}
b.add(e); b.add(e);
b.commit(); b.commit();
db.readDirCache(); 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 int expIdx = 2;
final DirCacheBuilder b = dc.builder(); final DirCacheBuilder b = dc.builder();
final TreeWalk tw = new TreeWalk(db); try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheBuildIterator(b)); tw.addTree(new DirCacheBuildIterator(b));
tw.setRecursive(true); tw.setRecursive(true);
tw.setFilter(PathFilterGroup.createFromStrings(Collections tw.setFilter(PathFilterGroup.createFromStrings(Collections
@ -95,6 +95,7 @@ public class DirCacheBuilderIteratorTest extends RepositoryTestCase {
b.add(c.getDirCacheEntry()); b.add(c.getDirCacheEntry());
assertFalse("no more entries", tw.next()); assertFalse("no more entries", tw.next());
}
b.finish(); b.finish();
assertEquals(ents.length, dc.getEntryCount()); 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()); assertEquals(ls.size(), dc.getEntryCount());
{ {
final Iterator<CGitIndexRecord> rItr = ls.values().iterator(); final Iterator<CGitIndexRecord> rItr = ls.values().iterator();
final TreeWalk tw = new TreeWalk(db); try (final TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true); tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc)); tw.addTree(new DirCacheIterator(dc));
while (rItr.hasNext()) { while (rItr.hasNext()) {
@ -112,6 +112,7 @@ public class DirCacheCGitCompatabilityTest extends LocalDiskRepositoryTestCase {
} }
} }
} }
}
@Test @Test
public void testUnsupportedOptionalExtension() throws Exception { 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(); final DirCache dc = DirCache.newInCore();
assertEquals(0, dc.getEntryCount()); assertEquals(0, dc.getEntryCount());
final TreeWalk tw = new TreeWalk(db); try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheIterator(dc)); tw.addTree(new DirCacheIterator(dc));
assertFalse(tw.next()); assertFalse(tw.next());
} }
}
@Test @Test
public void testNoSubtree_NoTreeWalk() throws Exception { public void testNoSubtree_NoTreeWalk() throws Exception {
@ -125,7 +126,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.finish(); b.finish();
final DirCacheIterator i = new DirCacheIterator(dc); final DirCacheIterator i = new DirCacheIterator(dc);
final TreeWalk tw = new TreeWalk(db); try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(i); tw.addTree(i);
int pathIdx = 0; int pathIdx = 0;
while (tw.next()) { while (tw.next()) {
@ -139,6 +140,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
} }
assertEquals(paths.length, pathIdx); assertEquals(paths.length, pathIdx);
} }
}
@Test @Test
public void testSingleSubtree_NoRecursion() throws Exception { public void testSingleSubtree_NoRecursion() throws Exception {
@ -162,7 +164,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
final int expPos[] = { 0, -1, 4 }; final int expPos[] = { 0, -1, 4 };
final DirCacheIterator i = new DirCacheIterator(dc); final DirCacheIterator i = new DirCacheIterator(dc);
final TreeWalk tw = new TreeWalk(db); try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(i); tw.addTree(i);
tw.setRecursive(false); tw.setRecursive(false);
int pathIdx = 0; int pathIdx = 0;
@ -183,6 +185,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
} }
assertEquals(expPaths.length, pathIdx); assertEquals(expPaths.length, pathIdx);
} }
}
@Test @Test
public void testSingleSubtree_Recursive() throws Exception { public void testSingleSubtree_Recursive() throws Exception {
@ -202,7 +205,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.finish(); b.finish();
final DirCacheIterator i = new DirCacheIterator(dc); final DirCacheIterator i = new DirCacheIterator(dc);
final TreeWalk tw = new TreeWalk(db); try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(i); tw.addTree(i);
tw.setRecursive(true); tw.setRecursive(true);
int pathIdx = 0; int pathIdx = 0;
@ -218,6 +221,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
} }
assertEquals(paths.length, pathIdx); assertEquals(paths.length, pathIdx);
} }
}
@Test @Test
public void testTwoLevelSubtree_Recursive() throws Exception { public void testTwoLevelSubtree_Recursive() throws Exception {
@ -236,7 +240,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.add(ents[i]); b.add(ents[i]);
b.finish(); b.finish();
final TreeWalk tw = new TreeWalk(db); try (final TreeWalk tw = new TreeWalk(db)) {
tw.addTree(new DirCacheIterator(dc)); tw.addTree(new DirCacheIterator(dc));
tw.setRecursive(true); tw.setRecursive(true);
int pathIdx = 0; int pathIdx = 0;
@ -252,6 +256,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
} }
assertEquals(paths.length, pathIdx); assertEquals(paths.length, pathIdx);
} }
}
@Test @Test
public void testReset() throws Exception { public void testReset() throws Exception {
@ -397,7 +402,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
b.add(ents[i]); b.add(ents[i]);
b.finish(); b.finish();
final TreeWalk tw = new TreeWalk(db); try (final TreeWalk tw = new TreeWalk(db)) {
for (int victimIdx = 0; victimIdx < paths.length; victimIdx++) { for (int victimIdx = 0; victimIdx < paths.length; victimIdx++) {
tw.reset(); tw.reset();
tw.addTree(new DirCacheIterator(dc)); tw.addTree(new DirCacheIterator(dc));
@ -415,6 +420,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
assertFalse(tw.next()); assertFalse(tw.next());
} }
} }
}
@Test @Test
public void testRemovedSubtree() throws Exception { public void testRemovedSubtree() throws Exception {
@ -424,7 +430,7 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
final DirCache dc = DirCache.read(path, FS.DETECTED); final DirCache dc = DirCache.read(path, FS.DETECTED);
assertEquals(2, dc.getEntryCount()); assertEquals(2, dc.getEntryCount());
final TreeWalk tw = new TreeWalk(db); try (final TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true); tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc)); tw.addTree(new DirCacheIterator(dc));
@ -438,4 +444,5 @@ public class DirCacheIteratorTest extends RepositoryTestCase {
assertFalse(tw.next()); assertFalse(tw.next());
} }
}
} }

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

@ -43,8 +43,9 @@
package org.eclipse.jgit.gitrepo; package org.eclipse.jgit.gitrepo;
import static org.junit.Assert.assertTrue; 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.HashSet;
import java.util.Set; import java.util.Set;
@ -77,7 +78,7 @@ public class ManifestParserTest {
ManifestParser parser = new ManifestParser( ManifestParser parser = new ManifestParser(
null, null, "master", baseUrl, null, null); 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. // Unfiltered projects should have them all.
results.clear(); results.clear();
results.add("foo"); 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("t1", a);
tr.lightweightTag("t2", a); tr.lightweightTag("t2", a);
LockFile refLock = new LockFile(new File(repo.getDirectory(), LockFile refLock = new LockFile(new File(repo.getDirectory(),
"refs/tags/t1"), repo.getFS()); "refs/tags/t1"));
try { try {
refLock.lock(); refLock.lock();
gc.packRefs(); 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 @Test
public void lockFailedExceptionRecovery() throws Exception { public void lockFailedExceptionRecovery() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("file.txt", "content"); writeTrashFile("file.txt", "content");
git.add().addFilepattern("file.txt").call(); git.add().addFilepattern("file.txt").call();
RevCommit commit1 = git.commit().setMessage("create file").call(); RevCommit commit1 = git.commit().setMessage("create file").call();
@ -71,7 +71,7 @@ public class LockFileTest extends RepositoryTestCase {
git.add().addFilepattern("file.txt").call(); git.add().addFilepattern("file.txt").call();
assertNotNull(git.commit().setMessage("edit file").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()); assertTrue(lf.lock());
try { try {
git.checkout().setName(commit1.name()).call(); git.checkout().setName(commit1.name()).call();
@ -82,4 +82,5 @@ public class LockFileTest extends RepositoryTestCase {
git.checkout().setName(commit1.name()).call(); git.checkout().setName(commit1.name()).call();
} }
} }
}
} }

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"); RefUpdate updateRef = db.updateRef("refs/heads/master");
updateRef.setNewObjectId(pid); updateRef.setNewObjectId(pid);
LockFile lockFile1 = new LockFile(new File(db.getDirectory(), LockFile lockFile1 = new LockFile(new File(db.getDirectory(),
"refs/heads/master"), db.getFS()); "refs/heads/master"));
try { try {
assertTrue(lockFile1.lock()); // precondition to test assertTrue(lockFile1.lock()); // precondition to test
Result update = updateRef.update(); Result update = updateRef.update();
assertEquals(Result.LOCK_FAILURE, update); assertEquals(Result.LOCK_FAILURE, update);
assertEquals(opid, db.resolve("refs/heads/master")); assertEquals(opid, db.resolve("refs/heads/master"));
LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"), LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"));
db.getFS());
assertFalse(lockFile2.lock()); // was locked, still is assertFalse(lockFile2.lock()); // was locked, still is
} finally { } finally {
lockFile1.unlock(); lockFile1.unlock();
@ -747,8 +746,7 @@ public class RefUpdateTest extends SampleDataRepositoryTestCase {
"logs/" + fromName).exists()); "logs/" + fromName).exists());
// "someone" has branch X locked // "someone" has branch X locked
LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock), LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock));
db.getFS());
try { try {
assertTrue(lockFile.lock()); 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, private void testMaliciousPath(boolean good, boolean secondCheckout,
String... path) throws GitAPIException, IOException { String... path) throws GitAPIException, IOException {
Git git = new Git(db); try (Git git = new Git(db);
RevWalk revWalk = new RevWalk(git.getRepository())) {
ObjectInserter newObjectInserter; ObjectInserter newObjectInserter;
newObjectInserter = git.getRepository().newObjectInserter(); newObjectInserter = git.getRepository().newObjectInserter();
ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB, ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB,
@ -379,7 +380,6 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
commitBuilder.setParentId(firstCommitId); commitBuilder.setParentId(firstCommitId);
ObjectId commitId = newObjectInserter.insert(commitBuilder); ObjectId commitId = newObjectInserter.insert(commitBuilder);
RevWalk revWalk = new RevWalk(git.getRepository());
if (!secondCheckout) if (!secondCheckout)
git.checkout().setStartPoint(revWalk.parseCommit(firstCommitId)) git.checkout().setStartPoint(revWalk.parseCommit(firstCommitId))
.setName("refs/heads/master").setCreateBranch(true).call(); .setName("refs/heads/master").setCreateBranch(true).call();
@ -402,5 +402,6 @@ public class DirCacheCheckoutMaliciousPathTest extends RepositoryTestCase {
assertTrue(e.getMessage().startsWith("Invalid path")); 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("file2", "file2");
writeTrashFile("dir/file3", "dir/file3"); writeTrashFile("dir/file3", "dir/file3");
Git git = new Git(db); try (Git git = new Git(db)) {
git.add().addFilepattern("file2").addFilepattern("dir/file3").call(); git.add().addFilepattern("file2").addFilepattern("dir/file3").call();
}
writeTrashFile("dir/file3", "changed"); writeTrashFile("dir/file3", "changed");
@ -177,8 +178,7 @@ public class IndexDiffTest extends RepositoryTestCase {
@Test @Test
public void testConflicting() throws Exception { public void testConflicting() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call(); git.add().addFilepattern("a").addFilepattern("b").call();
@ -202,6 +202,7 @@ public class IndexDiffTest extends RepositoryTestCase {
MergeResult result = git.merge().include(secondCommit.getId()) MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call(); .setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
FileTreeIterator iterator = new FileTreeIterator(db); FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -221,8 +222,7 @@ public class IndexDiffTest extends RepositoryTestCase {
@Test @Test
public void testConflictingDeletedAndModified() throws Exception { public void testConflictingDeletedAndModified() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
writeTrashFile("b", "1\nb\n3\n"); writeTrashFile("b", "1\nb\n3\n");
git.add().addFilepattern("a").addFilepattern("b").call(); git.add().addFilepattern("a").addFilepattern("b").call();
@ -244,6 +244,7 @@ public class IndexDiffTest extends RepositoryTestCase {
MergeResult result = git.merge().include(secondCommit.getId()) MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call(); .setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
FileTreeIterator iterator = new FileTreeIterator(db); FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -262,8 +263,7 @@ public class IndexDiffTest extends RepositoryTestCase {
@Test @Test
public void testConflictingFromMultipleCreations() throws Exception { public void testConflictingFromMultipleCreations() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "1\na\n3\n"); writeTrashFile("a", "1\na\n3\n");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call(); RevCommit initialCommit = git.commit().setMessage("initial").call();
@ -284,6 +284,7 @@ public class IndexDiffTest extends RepositoryTestCase {
MergeResult result = git.merge().include(secondCommit.getId()) MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call(); .setStrategy(MergeStrategy.RESOLVE).call();
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus()); assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
FileTreeIterator iterator = new FileTreeIterator(db); FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); 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=c", "a=c"); writeTrashFile("a=c", "a=c");
writeTrashFile("a=d", "a=d"); 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.b").call();
git.add().addFilepattern("a.c").call(); git.add().addFilepattern("a.c").call();
git.add().addFilepattern("a=c").call(); git.add().addFilepattern("a=c").call();
git.add().addFilepattern("a=d").call(); git.add().addFilepattern("a=d").call();
}
TreeFormatter tree = new TreeFormatter(); TreeFormatter tree = new TreeFormatter();
// got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin // 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 @Test
public void testUnchangedComplex() throws IOException, GitAPIException { public void testUnchangedComplex() throws IOException, GitAPIException {
Git git = new Git(db);
writeTrashFile("a.b", "a.b"); writeTrashFile("a.b", "a.b");
writeTrashFile("a.c", "a.c"); writeTrashFile("a.c", "a.c");
writeTrashFile("a/b.b/b", "a/b.b/b"); 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=c", "a=c"); writeTrashFile("a=c", "a=c");
writeTrashFile("a=d", "a=d"); writeTrashFile("a=d", "a=d");
try (Git git = new Git(db)) {
git.add().addFilepattern("a.b").addFilepattern("a.c") git.add().addFilepattern("a.b").addFilepattern("a.c")
.addFilepattern("a/b.b/b").addFilepattern("a/b") .addFilepattern("a/b.b/b").addFilepattern("a/b")
.addFilepattern("a/c").addFilepattern("a=c") .addFilepattern("a/c").addFilepattern("a=c")
.addFilepattern("a=d").call(); .addFilepattern("a=d").call();
}
// got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin // 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 @Test
public void testRemovedUntracked() throws Exception{ public void testRemovedUntracked() throws Exception{
Git git = new Git(db);
String path = "file"; String path = "file";
try (Git git = new Git(db)) {
writeTrashFile(path, "content"); writeTrashFile(path, "content");
git.add().addFilepattern(path).call(); git.add().addFilepattern(path).call();
git.commit().setMessage("commit").call(); git.commit().setMessage("commit").call();
}
removeFromIndex(path); removeFromIndex(path);
FileTreeIterator iterator = new FileTreeIterator(db); FileTreeIterator iterator = new FileTreeIterator(db);
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator); IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
@ -417,8 +421,7 @@ public class IndexDiffTest extends RepositoryTestCase {
*/ */
@Test @Test
public void testUntrackedFolders() throws Exception { public void testUntrackedFolders() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
IndexDiff diff = new IndexDiff(db, Constants.HEAD, IndexDiff diff = new IndexDiff(db, Constants.HEAD,
new FileTreeIterator(db)); new FileTreeIterator(db));
diff.diff(); diff.diff();
@ -463,6 +466,7 @@ public class IndexDiffTest extends RepositoryTestCase {
"target")), "target")),
diff.getUntrackedFolders()); diff.getUntrackedFolders());
} }
}
/** /**
* Test that ignored folders aren't listed as untracked * Test that ignored folders aren't listed as untracked
@ -471,8 +475,7 @@ public class IndexDiffTest extends RepositoryTestCase {
*/ */
@Test @Test
public void testUntrackedNotIgnoredFolders() throws Exception { public void testUntrackedNotIgnoredFolders() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
IndexDiff diff = new IndexDiff(db, Constants.HEAD, IndexDiff diff = new IndexDiff(db, Constants.HEAD,
new FileTreeIterator(db)); new FileTreeIterator(db));
diff.diff(); diff.diff();
@ -510,10 +513,11 @@ public class IndexDiffTest extends RepositoryTestCase {
"target")), "target")),
diff.getUntrackedFolders()); diff.getUntrackedFolders());
} }
}
@Test @Test
public void testAssumeUnchanged() throws Exception { public void testAssumeUnchanged() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
String path = "file"; String path = "file";
writeTrashFile(path, "content"); writeTrashFile(path, "content");
git.add().addFilepattern(path).call(); git.add().addFilepattern(path).call();
@ -551,6 +555,7 @@ public class IndexDiffTest extends RepositoryTestCase {
assertTrue(diff.getChanged().contains("file")); assertTrue(diff.getChanged().contains("file"));
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders()); assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
} }
}
@Test @Test
public void testStageState() throws IOException { public void testStageState() throws IOException {
@ -575,8 +580,7 @@ public class IndexDiffTest extends RepositoryTestCase {
@Test @Test
public void testStageState_mergeAndReset_bug() throws Exception { public void testStageState_mergeAndReset_bug() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "content"); writeTrashFile("a", "content");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial commit") RevCommit initialCommit = git.commit().setMessage("initial commit")
@ -635,11 +639,11 @@ public class IndexDiffTest extends RepositoryTestCase {
.get("b")); .get("b"));
assertTrue(diff.getUntrackedFolders().isEmpty()); assertTrue(diff.getUntrackedFolders().isEmpty());
} }
}
@Test @Test
public void testStageState_simulated_bug() throws Exception { public void testStageState_simulated_bug() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
writeTrashFile("a", "content"); writeTrashFile("a", "content");
git.add().addFilepattern("a").call(); git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial commit") RevCommit initialCommit = git.commit().setMessage("initial commit")
@ -688,10 +692,11 @@ public class IndexDiffTest extends RepositoryTestCase {
.get("b")); .get("b"));
assertTrue(diff.getUntrackedFolders().isEmpty()); assertTrue(diff.getUntrackedFolders().isEmpty());
} }
}
@Test @Test
public void testAutoCRLFInput() throws Exception { public void testAutoCRLFInput() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
FileBasedConfig config = db.getConfig(); FileBasedConfig config = db.getConfig();
// Make sure core.autocrlf is false before adding // Make sure core.autocrlf is false before adding
@ -717,6 +722,7 @@ public class IndexDiffTest extends RepositoryTestCase {
"Expected no modified files, but there were: " "Expected no modified files, but there were: "
+ diff.getModified(), diff.getModified().isEmpty()); + diff.getModified(), diff.getModified().isEmpty());
} }
}
private void verifyStageState(StageState expected, int... stages) private void verifyStageState(StageState expected, int... stages)
throws IOException { throws IOException {

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

@ -49,7 +49,7 @@ public class IndexModificationTimesTest extends RepositoryTestCase {
@Test @Test
public void testLastModifiedTimes() throws Exception { public void testLastModifiedTimes() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
String path = "file"; String path = "file";
writeTrashFile(path, "content"); writeTrashFile(path, "content");
String path2 = "file2"; String path2 = "file2";
@ -83,10 +83,11 @@ public class IndexModificationTimesTest extends RepositoryTestCase {
assertTrue("last modified shall not be zero!", assertTrue("last modified shall not be zero!",
entry2.getLastModified() != 0); entry2.getLastModified() != 0);
} }
}
@Test @Test
public void testModify() throws Exception { public void testModify() throws Exception {
Git git = new Git(db); try (Git git = new Git(db)) {
String path = "file"; String path = "file";
writeTrashFile(path, "content"); writeTrashFile(path, "content");
@ -122,7 +123,7 @@ public class IndexModificationTimesTest extends RepositoryTestCase {
assertTrue("shall have equal mod time!", masterLastMod == sideLastMode); assertTrue("shall have equal mod time!", masterLastMod == sideLastMode);
assertTrue("shall not equal master timestamp!", assertTrue("shall not equal master timestamp!",
entry.getLastModified() == masterLastMod); 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 { 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)); T(commonBase), T(ours), T(theirs));
ByteArrayOutputStream bo=new ByteArrayOutputStream(50); ByteArrayOutputStream bo=new ByteArrayOutputStream(50);
fmt.formatMerge(bo, r, "B", "O", "T", Constants.CHARACTER_ENCODING); 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); ObjectId tree = tree0.writeTree(oi);
// Find the directories that were implicitly created above. // Find the directories that were implicitly created above.
TreeWalk tw = new TreeWalk(or);
tw.addTree(tree);
ObjectId a = null; ObjectId a = null;
ObjectId aSlashC = null; ObjectId aSlashC = null;
try (TreeWalk tw = new TreeWalk(or)) {
tw.addTree(tree);
while (tw.next()) { while (tw.next()) {
if (tw.getPathString().equals("a")) { if (tw.getPathString().equals("a")) {
a = tw.getObjectId(0); a = tw.getObjectId(0);
@ -101,6 +101,7 @@ public class ForPathTest extends RepositoryTestCase {
break; break;
} }
} }
}
assertEquals(a, TreeWalk.forPath(or, "a", tree).getObjectId(0)); assertEquals(a, TreeWalk.forPath(or, "a", tree).getObjectId(0));
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 { public void testEmpty() throws IOException {
DirCache dc1 = DirCache.newInCore(); DirCache dc1 = DirCache.newInCore();
DirCache dc2 = 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(dc1));
tw.addTree(new DirCacheIterator(dc2)); tw.addTree(new DirCacheIterator(dc2));
assertFalse(tw.next()); assertFalse(tw.next());
} }
}
static final class AddEdit extends PathEdit { 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.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false));
editor.finish(); editor.finish();
TreeWalk tw = new TreeWalk(db); try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true); tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc1)); tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2)); tw.addTree(new DirCacheIterator(dc2));
@ -133,6 +134,7 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
assertEquals("a/a", tw.getPathString()); assertEquals("a/a", tw.getPathString());
assertFalse(tw.next()); assertFalse(tw.next());
} }
}
@Test @Test
public void testTwoSame() throws IOException { 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.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false));
ed2.finish(); ed2.finish();
TreeWalk tw = new TreeWalk(db); try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true); tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc1)); tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2)); tw.addTree(new DirCacheIterator(dc2));
@ -153,6 +155,7 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
assertFalse(tw.next()); assertFalse(tw.next());
} }
}
@Test @Test
public void testTwoSameDifferByAssumeValid() throws IOException { 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.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, true));
ed2.finish(); ed2.finish();
TreeWalk tw = new TreeWalk(db); try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true); tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc1)); tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2)); tw.addTree(new DirCacheIterator(dc2));
@ -175,6 +178,7 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
assertEquals("a/a", tw.getPathString()); assertEquals("a/a", tw.getPathString());
assertFalse(tw.next()); assertFalse(tw.next());
} }
}
@Test @Test
public void testTwoSameSameAssumeValidDifferentContent() 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.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("b"), 1, true));
ed2.finish(); ed2.finish();
TreeWalk tw = new TreeWalk(db); try (TreeWalk tw = new TreeWalk(db)) {
tw.setRecursive(true); tw.setRecursive(true);
tw.addTree(new DirCacheIterator(dc1)); tw.addTree(new DirCacheIterator(dc1));
tw.addTree(new DirCacheIterator(dc2)); tw.addTree(new DirCacheIterator(dc2));
@ -196,4 +200,5 @@ public class InterIndexDiffFilterTest extends LocalDiskRepositoryTestCase {
assertFalse(tw.next()); 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. */ /** Our active lock (if we hold it); null if we don't have it locked. */
private LockFile myLock; private LockFile myLock;
/** file system abstraction **/
private final FS fs;
/** Keep track of whether the index has changed or not */ /** Keep track of whether the index has changed or not */
private FileSnapshot snapshot; private FileSnapshot snapshot;
@ -376,7 +373,6 @@ public class DirCache {
*/ */
public DirCache(final File indexLocation, final FS fs) { public DirCache(final File indexLocation, final FS fs) {
liveFile = indexLocation; liveFile = indexLocation;
this.fs = fs;
clear(); clear();
} }
@ -611,7 +607,7 @@ public class DirCache {
public boolean lock() throws IOException { public boolean lock() throws IOException {
if (liveFile == null) if (liveFile == null)
throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile); throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile);
final LockFile tmp = new LockFile(liveFile, fs); final LockFile tmp = new LockFile(liveFile);
if (tmp.lock()) { if (tmp.lock()) {
tmp.setNeedStatInformation(true); tmp.setNeedStatInformation(true);
myLock = tmp; 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()) { if (performsAtomicTransactions()) {
try { try {
lock.writeLock().lock(); lock.writeLock().lock();
batch(walk, getCommands()); batch(getCommands());
} finally { } finally {
lock.writeLock().unlock(); lock.writeLock().unlock();
} }
@ -304,7 +304,7 @@ public class InMemoryRepository extends DfsRepository {
return new RefCache(ids.toRefList(), sym.toRefList()); 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 // Validate that the target exists in a new RevWalk, as the RevWalk
// from the RefUpdate might be reading back unflushed objects. // from the RefUpdate might be reading back unflushed objects.
Map<ObjectId, ObjectId> peeled = new HashMap<>(); 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() ConfigConstants.CONFIG_KEY_WORKTREE, getWorkTree()
.getAbsolutePath()); .getAbsolutePath());
LockFile dotGitLockFile = new LockFile(new File(workTree, LockFile dotGitLockFile = new LockFile(new File(workTree,
Constants.DOT_GIT), getFS()); Constants.DOT_GIT));
try { try {
if (dotGitLockFile.lock()) { if (dotGitLockFile.lock()) {
dotGitLockFile.write(Constants.encode(Constants.GITDIR 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. */ /** Keeps track of a {@link PackFile}'s associated <code>.keep</code> file. */
public class PackLock { public class PackLock {
private final File keepFile; private final File keepFile;
private final FS fs;
/** /**
* Create a new lock for a pack file. * Create a new lock for a pack file.
@ -67,7 +66,6 @@ public class PackLock {
final File p = packFile.getParentFile(); final File p = packFile.getParentFile();
final String n = packFile.getName(); final String n = packFile.getName();
keepFile = new File(p, n.substring(0, n.length() - 5) + ".keep"); //$NON-NLS-1$ 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; return false;
if (!msg.endsWith("\n")) //$NON-NLS-1$ if (!msg.endsWith("\n")) //$NON-NLS-1$
msg += "\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()) if (!lf.lock())
return false; return false;
lf.write(Constants.encode(msg)); 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. // we don't miss an edit made externally.
final PackedRefList packed = getPackedRefs(); final PackedRefList packed = getPackedRefs();
if (packed.contains(name)) { if (packed.contains(name)) {
LockFile lck = new LockFile(packedRefsFile, LockFile lck = new LockFile(packedRefsFile);
update.getRepository().getFS());
if (!lck.lock()) if (!lck.lock())
throw new LockFailedException(packedRefsFile); throw new LockFailedException(packedRefsFile);
try { try {
@ -639,7 +638,7 @@ public class RefDirectory extends RefDatabase {
FS fs = parent.getFS(); FS fs = parent.getFS();
// Lock the packed refs file and read the content // Lock the packed refs file and read the content
LockFile lck = new LockFile(packedRefsFile, fs); LockFile lck = new LockFile(packedRefsFile);
if (!lck.lock()) if (!lck.lock())
throw new IOException(MessageFormat.format( throw new IOException(MessageFormat.format(
JGitText.get().cannotLock, packedRefsFile)); JGitText.get().cannotLock, packedRefsFile));
@ -670,8 +669,7 @@ public class RefDirectory extends RefDatabase {
File refFile = fileFor(refName); File refFile = fileFor(refName);
if (!fs.exists(refFile)) if (!fs.exists(refFile))
continue; continue;
LockFile rLck = new LockFile(refFile, LockFile rLck = new LockFile(refFile);
parent.getFS());
if (!rLck.lock()) if (!rLck.lock())
continue; continue;
try { try {

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

@ -79,7 +79,7 @@ class RefDirectoryUpdate extends RefUpdate {
if (deref) if (deref)
dst = dst.getLeaf(); dst = dst.getLeaf();
String name = dst.getName(); String name = dst.getName();
lock = new LockFile(database.fileFor(name), getRepository().getFS()); lock = new LockFile(database.fileFor(name));
if (lock.lock()) { if (lock.lock()) {
dst = database.getRef(name); dst = database.getRef(name);
setOldObjectId(dst != null ? dst.getObjectId() : null); 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 * metadata
* @throws IOException * @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 { String oursName, String theirsName, String charsetName) throws IOException {
List<String> names = new ArrayList<String>(3); List<String> names = new ArrayList<String>(3);
names.add(baseName); 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 { public class FileBasedConfig extends StoredConfig {
private final File configFile; private final File configFile;
private final FS fs;
private boolean utf8Bom; private boolean utf8Bom;
private volatile FileSnapshot snapshot; private volatile FileSnapshot snapshot;
@ -109,7 +107,6 @@ public class FileBasedConfig extends StoredConfig {
public FileBasedConfig(Config base, File cfgLocation, FS fs) { public FileBasedConfig(Config base, File cfgLocation, FS fs) {
super(base); super(base);
configFile = cfgLocation; configFile = cfgLocation;
this.fs = fs;
this.snapshot = FileSnapshot.DIRTY; this.snapshot = FileSnapshot.DIRTY;
this.hash = ObjectId.zeroId(); this.hash = ObjectId.zeroId();
} }
@ -203,7 +200,7 @@ public class FileBasedConfig extends StoredConfig {
out = Constants.encode(text); out = Constants.encode(text);
} }
final LockFile lf = new LockFile(getFile(), fs); final LockFile lf = new LockFile(getFile());
if (!lf.lock()) if (!lf.lock())
throw new LockFailedException(getFile()); throw new LockFailedException(getFile());
try { try {

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

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

Loading…
Cancel
Save