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. 11
      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. 2423
      org.eclipse.jgit.test/tst/org/eclipse/jgit/api/MergeCommandTest.java
  10. 8
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBasicTest.java
  11. 31
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheBuilderIteratorTest.java
  12. 23
      org.eclipse.jgit.test/tst/org/eclipse/jgit/dircache/DirCacheCGitCompatabilityTest.java
  13. 181
      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. 35
      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. 121
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/DirCacheCheckoutMaliciousPathTest.java
  19. 674
      org.eclipse.jgit.test/tst/org/eclipse/jgit/lib/IndexDiffTest.java
  20. 103
      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. 23
      org.eclipse.jgit.test/tst/org/eclipse/jgit/treewalk/ForPathTest.java
  23. 69
      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 {

11
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");

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

File diff suppressed because it is too large Load Diff

8
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()) {
Constants.OBJ_BLOB, e.setObjectId(formatter.idFor(
Constants.encode(path))); Constants.OBJ_BLOB,
Constants.encode(path)));
}
b.add(e); b.add(e);
b.commit(); b.commit();
db.readDirCache(); db.readDirCache();

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

@ -78,23 +78,24 @@ 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
.singleton(paths[expIdx]))); .singleton(paths[expIdx])));
assertTrue("found " + paths[expIdx], tw.next()); assertTrue("found " + paths[expIdx], tw.next());
final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
assertNotNull(c); assertNotNull(c);
assertEquals(expIdx, c.ptr); assertEquals(expIdx, c.ptr);
assertSame(ents[expIdx], c.getDirCacheEntry()); assertSame(ents[expIdx], c.getDirCacheEntry());
assertEquals(paths[expIdx], tw.getPathString()); assertEquals(paths[expIdx], tw.getPathString());
assertEquals(mode.getBits(), tw.getRawMode(0)); assertEquals(mode.getBits(), tw.getRawMode(0));
assertSame(mode, tw.getFileMode(0)); assertSame(mode, tw.getFileMode(0));
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());

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

@ -98,17 +98,18 @@ 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()) {
final DirCacheIterator dcItr; final DirCacheIterator dcItr;
assertTrue(tw.next()); assertTrue(tw.next());
dcItr = tw.getTree(0, DirCacheIterator.class); dcItr = tw.getTree(0, DirCacheIterator.class);
assertNotNull(dcItr); assertNotNull(dcItr);
assertEqual(rItr.next(), dcItr.getDirCacheEntry()); assertEqual(rItr.next(), dcItr.getDirCacheEntry());
}
} }
} }
} }

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

@ -76,9 +76,10 @@ 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
@ -125,19 +126,20 @@ 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()) {
assertSame(i, tw.getTree(0, DirCacheIterator.class)); assertSame(i, tw.getTree(0, DirCacheIterator.class));
assertEquals(pathIdx, i.ptr); assertEquals(pathIdx, i.ptr);
assertSame(ents[pathIdx], i.getDirCacheEntry()); assertSame(ents[pathIdx], i.getDirCacheEntry());
assertEquals(paths[pathIdx], tw.getPathString()); assertEquals(paths[pathIdx], tw.getPathString());
assertEquals(modes[pathIdx].getBits(), tw.getRawMode(0)); assertEquals(modes[pathIdx].getBits(), tw.getRawMode(0));
assertSame(modes[pathIdx], tw.getFileMode(0)); assertSame(modes[pathIdx], tw.getFileMode(0));
pathIdx++; pathIdx++;
}
assertEquals(paths.length, pathIdx);
} }
assertEquals(paths.length, pathIdx);
} }
@Test @Test
@ -162,26 +164,27 @@ 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;
while (tw.next()) { while (tw.next()) {
assertSame(i, tw.getTree(0, DirCacheIterator.class)); assertSame(i, tw.getTree(0, DirCacheIterator.class));
assertEquals(expModes[pathIdx].getBits(), tw.getRawMode(0)); assertEquals(expModes[pathIdx].getBits(), tw.getRawMode(0));
assertSame(expModes[pathIdx], tw.getFileMode(0)); assertSame(expModes[pathIdx], tw.getFileMode(0));
assertEquals(expPaths[pathIdx], tw.getPathString()); assertEquals(expPaths[pathIdx], tw.getPathString());
if (expPos[pathIdx] >= 0) { if (expPos[pathIdx] >= 0) {
assertEquals(expPos[pathIdx], i.ptr); assertEquals(expPos[pathIdx], i.ptr);
assertSame(ents[expPos[pathIdx]], i.getDirCacheEntry()); assertSame(ents[expPos[pathIdx]], i.getDirCacheEntry());
} else { } else {
assertSame(FileMode.TREE, tw.getFileMode(0)); assertSame(FileMode.TREE, tw.getFileMode(0));
}
pathIdx++;
} }
assertEquals(expPaths.length, pathIdx);
pathIdx++;
} }
assertEquals(expPaths.length, pathIdx);
} }
@Test @Test
@ -202,21 +205,22 @@ 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;
while (tw.next()) { while (tw.next()) {
final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
assertNotNull(c); assertNotNull(c);
assertEquals(pathIdx, c.ptr); assertEquals(pathIdx, c.ptr);
assertSame(ents[pathIdx], c.getDirCacheEntry()); assertSame(ents[pathIdx], c.getDirCacheEntry());
assertEquals(paths[pathIdx], tw.getPathString()); assertEquals(paths[pathIdx], tw.getPathString());
assertEquals(mode.getBits(), tw.getRawMode(0)); assertEquals(mode.getBits(), tw.getRawMode(0));
assertSame(mode, tw.getFileMode(0)); assertSame(mode, tw.getFileMode(0));
pathIdx++; pathIdx++;
}
assertEquals(paths.length, pathIdx);
} }
assertEquals(paths.length, pathIdx);
} }
@Test @Test
@ -236,21 +240,22 @@ 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;
while (tw.next()) { while (tw.next()) {
final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
assertNotNull(c); assertNotNull(c);
assertEquals(pathIdx, c.ptr); assertEquals(pathIdx, c.ptr);
assertSame(ents[pathIdx], c.getDirCacheEntry()); assertSame(ents[pathIdx], c.getDirCacheEntry());
assertEquals(paths[pathIdx], tw.getPathString()); assertEquals(paths[pathIdx], tw.getPathString());
assertEquals(mode.getBits(), tw.getRawMode(0)); assertEquals(mode.getBits(), tw.getRawMode(0));
assertSame(mode, tw.getFileMode(0)); assertSame(mode, tw.getFileMode(0));
pathIdx++; pathIdx++;
}
assertEquals(paths.length, pathIdx);
} }
assertEquals(paths.length, pathIdx);
} }
@Test @Test
@ -397,22 +402,23 @@ 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));
tw.setFilter(PathFilterGroup.createFromStrings(Collections tw.setFilter(PathFilterGroup.createFromStrings(Collections
.singleton(paths[victimIdx]))); .singleton(paths[victimIdx])));
tw.setRecursive(tw.getFilter().shouldBeRecursive()); tw.setRecursive(tw.getFilter().shouldBeRecursive());
assertTrue(tw.next()); assertTrue(tw.next());
final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class); final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
assertNotNull(c); assertNotNull(c);
assertEquals(victimIdx, c.ptr); assertEquals(victimIdx, c.ptr);
assertSame(ents[victimIdx], c.getDirCacheEntry()); assertSame(ents[victimIdx], c.getDirCacheEntry());
assertEquals(paths[victimIdx], tw.getPathString()); assertEquals(paths[victimIdx], tw.getPathString());
assertEquals(mode.getBits(), tw.getRawMode(0)); assertEquals(mode.getBits(), tw.getRawMode(0));
assertSame(mode, tw.getFileMode(0)); assertSame(mode, tw.getFileMode(0));
assertFalse(tw.next()); assertFalse(tw.next());
}
} }
} }
@ -424,18 +430,19 @@ 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));
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("a/a", tw.getPathString()); assertEquals("a/a", tw.getPathString());
assertSame(FileMode.REGULAR_FILE, tw.getFileMode(0)); assertSame(FileMode.REGULAR_FILE, tw.getFileMode(0));
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("q", tw.getPathString()); assertEquals("q", tw.getPathString());
assertSame(FileMode.REGULAR_FILE, tw.getFileMode(0)); assertSame(FileMode.REGULAR_FILE, tw.getFileMode(0));
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();

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

@ -61,25 +61,26 @@ 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();
assertNotNull(commit1); assertNotNull(commit1);
writeTrashFile("file.txt", "content2"); writeTrashFile("file.txt", "content2");
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();
fail("JGitInternalException not thrown"); fail("JGitInternalException not thrown");
} catch (JGitInternalException e) { } catch (JGitInternalException e) {
assertTrue(e.getCause() instanceof LockFailedException); assertTrue(e.getCause() instanceof LockFailedException);
lf.unlock(); lf.unlock();
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());

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

@ -338,68 +338,69 @@ 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);
ObjectInserter newObjectInserter; RevWalk revWalk = new RevWalk(git.getRepository())) {
newObjectInserter = git.getRepository().newObjectInserter(); ObjectInserter newObjectInserter;
ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB, newObjectInserter = git.getRepository().newObjectInserter();
"data".getBytes()); ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB,
newObjectInserter = git.getRepository().newObjectInserter(); "data".getBytes());
FileMode mode = FileMode.REGULAR_FILE; newObjectInserter = git.getRepository().newObjectInserter();
ObjectId insertId = blobId; FileMode mode = FileMode.REGULAR_FILE;
for (int i = path.length - 1; i >= 0; --i) { ObjectId insertId = blobId;
TreeFormatter treeFormatter = new TreeFormatter(); for (int i = path.length - 1; i >= 0; --i) {
treeFormatter.append("goodpath", mode, insertId); TreeFormatter treeFormatter = new TreeFormatter();
insertId = newObjectInserter.insert(treeFormatter); treeFormatter.append("goodpath", mode, insertId);
mode = FileMode.TREE; insertId = newObjectInserter.insert(treeFormatter);
} mode = FileMode.TREE;
newObjectInserter = git.getRepository().newObjectInserter(); }
CommitBuilder commitBuilder = new CommitBuilder(); newObjectInserter = git.getRepository().newObjectInserter();
commitBuilder.setAuthor(author); CommitBuilder commitBuilder = new CommitBuilder();
commitBuilder.setCommitter(committer); commitBuilder.setAuthor(author);
commitBuilder.setMessage("foo#1"); commitBuilder.setCommitter(committer);
commitBuilder.setTreeId(insertId); commitBuilder.setMessage("foo#1");
ObjectId firstCommitId = newObjectInserter.insert(commitBuilder); commitBuilder.setTreeId(insertId);
ObjectId firstCommitId = newObjectInserter.insert(commitBuilder);
newObjectInserter = git.getRepository().newObjectInserter();
mode = FileMode.REGULAR_FILE; newObjectInserter = git.getRepository().newObjectInserter();
insertId = blobId; mode = FileMode.REGULAR_FILE;
for (int i = path.length - 1; i >= 0; --i) { insertId = blobId;
TreeFormatter treeFormatter = new TreeFormatter(); for (int i = path.length - 1; i >= 0; --i) {
treeFormatter.append(path[i], mode, insertId); TreeFormatter treeFormatter = new TreeFormatter();
insertId = newObjectInserter.insert(treeFormatter); treeFormatter.append(path[i], mode, insertId);
mode = FileMode.TREE; insertId = newObjectInserter.insert(treeFormatter);
} mode = FileMode.TREE;
}
// Create another commit // Create another commit
commitBuilder = new CommitBuilder(); commitBuilder = new CommitBuilder();
commitBuilder.setAuthor(author); commitBuilder.setAuthor(author);
commitBuilder.setCommitter(committer); commitBuilder.setCommitter(committer);
commitBuilder.setMessage("foo#2"); commitBuilder.setMessage("foo#2");
commitBuilder.setTreeId(insertId); commitBuilder.setTreeId(insertId);
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(); try {
try { if (secondCheckout) {
if (secondCheckout) { git.checkout().setStartPoint(revWalk.parseCommit(commitId))
git.checkout().setStartPoint(revWalk.parseCommit(commitId)) .setName("refs/heads/master").setCreateBranch(true)
.setName("refs/heads/master").setCreateBranch(true) .call();
.call(); } else {
} else { git.branchCreate().setName("refs/heads/next")
git.branchCreate().setName("refs/heads/next") .setStartPoint(commitId.name()).call();
.setStartPoint(commitId.name()).call(); git.checkout().setName("refs/heads/next")
git.checkout().setName("refs/heads/next") .call();
.call(); }
if (!good)
fail("Checkout of Tree " + Arrays.asList(path) + " should fail");
} catch (InvalidPathException e) {
if (good)
throw e;
assertTrue(e.getMessage().startsWith("Invalid path"));
} }
if (!good)
fail("Checkout of Tree " + Arrays.asList(path) + " should fail");
} catch (InvalidPathException e) {
if (good)
throw e;
assertTrue(e.getMessage().startsWith("Invalid path"));
} }
} }

674
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,31 +178,31 @@ 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(); RevCommit initialCommit = git.commit().setMessage("initial").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
// create side branch with two modifications
// create side branch with two modifications createBranch(initialCommit, "refs/heads/side");
createBranch(initialCommit, "refs/heads/side"); checkoutBranch("refs/heads/side");
checkoutBranch("refs/heads/side"); writeTrashFile("a", "1\na(side)\n3\n");
writeTrashFile("a", "1\na(side)\n3\n"); writeTrashFile("b", "1\nb\n3\n(side)");
writeTrashFile("b", "1\nb\n3\n(side)"); git.add().addFilepattern("a").addFilepattern("b").call();
git.add().addFilepattern("a").addFilepattern("b").call(); RevCommit secondCommit = git.commit().setMessage("side").call();
RevCommit secondCommit = git.commit().setMessage("side").call();
// update a on master to generate conflict
// update a on master to generate conflict checkoutBranch("refs/heads/master");
checkoutBranch("refs/heads/master"); writeTrashFile("a", "1\na(main)\n3\n");
writeTrashFile("a", "1\na(main)\n3\n"); git.add().addFilepattern("a").call();
git.add().addFilepattern("a").call(); git.commit().setMessage("main").call();
git.commit().setMessage("main").call();
// merge side with master
// merge side with master 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,29 +222,29 @@ 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(); RevCommit initialCommit = git.commit().setMessage("initial").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
// create side branch and delete "a"
// create side branch and delete "a" createBranch(initialCommit, "refs/heads/side");
createBranch(initialCommit, "refs/heads/side"); checkoutBranch("refs/heads/side");
checkoutBranch("refs/heads/side"); git.rm().addFilepattern("a").call();
git.rm().addFilepattern("a").call(); RevCommit secondCommit = git.commit().setMessage("side").call();
RevCommit secondCommit = git.commit().setMessage("side").call();
// update a on master to generate conflict
// update a on master to generate conflict checkoutBranch("refs/heads/master");
checkoutBranch("refs/heads/master"); writeTrashFile("a", "1\na(main)\n3\n");
writeTrashFile("a", "1\na(main)\n3\n"); git.add().addFilepattern("a").call();
git.add().addFilepattern("a").call(); git.commit().setMessage("main").call();
git.commit().setMessage("main").call();
// merge side with master
// merge side with master 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,28 +263,28 @@ 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");
git.add().addFilepattern("a").call();
RevCommit initialCommit = git.commit().setMessage("initial").call();
writeTrashFile("a", "1\na\n3\n"); createBranch(initialCommit, "refs/heads/side");
git.add().addFilepattern("a").call(); checkoutBranch("refs/heads/side");
RevCommit initialCommit = git.commit().setMessage("initial").call();
createBranch(initialCommit, "refs/heads/side"); writeTrashFile("b", "1\nb(side)\n3\n");
checkoutBranch("refs/heads/side"); git.add().addFilepattern("b").call();
RevCommit secondCommit = git.commit().setMessage("side").call();
writeTrashFile("b", "1\nb(side)\n3\n"); checkoutBranch("refs/heads/master");
git.add().addFilepattern("b").call();
RevCommit secondCommit = git.commit().setMessage("side").call();
checkoutBranch("refs/heads/master"); writeTrashFile("b", "1\nb(main)\n3\n");
git.add().addFilepattern("b").call();
git.commit().setMessage("main").call();
writeTrashFile("b", "1\nb(main)\n3\n"); MergeResult result = git.merge().include(secondCommit.getId())
git.add().addFilepattern("b").call(); .setStrategy(MergeStrategy.RESOLVE).call();
git.commit().setMessage("main").call(); assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
}
MergeResult result = git.merge().include(secondCommit.getId())
.setStrategy(MergeStrategy.RESOLVE).call();
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");
git.add().addFilepattern("a.b").addFilepattern("a.c") try (Git git = new Git(db)) {
.addFilepattern("a/b.b/b").addFilepattern("a/b") git.add().addFilepattern("a.b").addFilepattern("a.c")
.addFilepattern("a/c").addFilepattern("a=c") .addFilepattern("a/b.b/b").addFilepattern("a/b")
.addFilepattern("a=d").call(); .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 // 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";
writeTrashFile(path, "content"); try (Git git = new Git(db)) {
git.add().addFilepattern(path).call(); writeTrashFile(path, "content");
git.commit().setMessage("commit").call(); git.add().addFilepattern(path).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,51 +421,51 @@ 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(); assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
writeTrashFile("readme", "");
writeTrashFile("readme", ""); writeTrashFile("src/com/A.java", "");
writeTrashFile("src/com/A.java", ""); writeTrashFile("src/com/B.java", "");
writeTrashFile("src/com/B.java", ""); writeTrashFile("src/org/A.java", "");
writeTrashFile("src/org/A.java", ""); writeTrashFile("src/org/B.java", "");
writeTrashFile("src/org/B.java", ""); writeTrashFile("target/com/A.java", "");
writeTrashFile("target/com/A.java", ""); writeTrashFile("target/com/B.java", "");
writeTrashFile("target/com/B.java", ""); writeTrashFile("target/org/A.java", "");
writeTrashFile("target/org/A.java", ""); writeTrashFile("target/org/B.java", "");
writeTrashFile("target/org/B.java", "");
git.add().addFilepattern("src").addFilepattern("readme").call();
git.add().addFilepattern("src").addFilepattern("readme").call(); git.commit().setMessage("initial").call();
git.commit().setMessage("initial").call();
diff = new IndexDiff(db, Constants.HEAD,
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
new FileTreeIterator(db)); diff.diff();
diff.diff(); assertEquals(new HashSet<String>(Arrays.asList("target")),
assertEquals(new HashSet<String>(Arrays.asList("target")), diff.getUntrackedFolders());
diff.getUntrackedFolders());
writeTrashFile("src/tst/A.java", "");
writeTrashFile("src/tst/A.java", ""); writeTrashFile("src/tst/B.java", "");
writeTrashFile("src/tst/B.java", "");
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); diff.diff();
diff.diff(); assertEquals(new HashSet<String>(Arrays.asList("target", "src/tst")),
assertEquals(new HashSet<String>(Arrays.asList("target", "src/tst")), diff.getUntrackedFolders());
diff.getUntrackedFolders());
git.rm().addFilepattern("src/com/B.java").addFilepattern("src/org")
git.rm().addFilepattern("src/com/B.java").addFilepattern("src/org") .call();
.call(); git.commit().setMessage("second").call();
git.commit().setMessage("second").call(); writeTrashFile("src/org/C.java", "");
writeTrashFile("src/org/C.java", "");
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); diff.diff();
diff.diff(); assertEquals(
assertEquals( new HashSet<String>(Arrays.asList("src/org", "src/tst",
new HashSet<String>(Arrays.asList("src/org", "src/tst", "target")),
"target")), diff.getUntrackedFolders());
diff.getUntrackedFolders()); }
} }
/** /**
@ -471,85 +475,86 @@ 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(); assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
writeTrashFile("readme", "");
writeTrashFile("readme", ""); writeTrashFile("sr/com/X.java", "");
writeTrashFile("sr/com/X.java", ""); writeTrashFile("src/com/A.java", "");
writeTrashFile("src/com/A.java", ""); writeTrashFile("src/org/B.java", "");
writeTrashFile("src/org/B.java", ""); writeTrashFile("srcs/org/Y.java", "");
writeTrashFile("srcs/org/Y.java", ""); writeTrashFile("target/com/A.java", "");
writeTrashFile("target/com/A.java", ""); writeTrashFile("target/org/B.java", "");
writeTrashFile("target/org/B.java", ""); writeTrashFile(".gitignore", "/target\n/sr");
writeTrashFile(".gitignore", "/target\n/sr");
git.add().addFilepattern("readme").addFilepattern(".gitignore")
git.add().addFilepattern("readme").addFilepattern(".gitignore") .addFilepattern("srcs/").call();
.addFilepattern("srcs/").call(); git.commit().setMessage("initial").call();
git.commit().setMessage("initial").call();
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); diff.diff();
diff.diff(); assertEquals(new HashSet<String>(Arrays.asList("src")),
assertEquals(new HashSet<String>(Arrays.asList("src")), diff.getUntrackedFolders());
diff.getUntrackedFolders());
git.add().addFilepattern("src").call();
git.add().addFilepattern("src").call(); writeTrashFile("sr/com/X1.java", "");
writeTrashFile("sr/com/X1.java", ""); writeTrashFile("src/tst/A.java", "");
writeTrashFile("src/tst/A.java", ""); writeTrashFile("src/tst/B.java", "");
writeTrashFile("src/tst/B.java", ""); writeTrashFile("srcs/com/Y1.java", "");
writeTrashFile("srcs/com/Y1.java", ""); deleteTrashFile(".gitignore");
deleteTrashFile(".gitignore");
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db)); diff.diff();
diff.diff(); assertEquals(
assertEquals( new HashSet<String>(Arrays.asList("srcs/com", "sr", "src/tst",
new HashSet<String>(Arrays.asList("srcs/com", "sr", "src/tst", "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();
String path2 = "file2"; String path2 = "file2";
writeTrashFile(path2, "content"); writeTrashFile(path2, "content");
String path3 = "file3"; String path3 = "file3";
writeTrashFile(path3, "some content"); writeTrashFile(path3, "some content");
git.add().addFilepattern(path2).addFilepattern(path3).call(); git.add().addFilepattern(path2).addFilepattern(path3).call();
git.commit().setMessage("commit").call(); git.commit().setMessage("commit").call();
assumeUnchanged(path2); assumeUnchanged(path2);
assumeUnchanged(path3); assumeUnchanged(path3);
writeTrashFile(path, "more content"); writeTrashFile(path, "more content");
deleteTrashFile(path3); deleteTrashFile(path3);
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);
diff.diff(); diff.diff();
assertEquals(2, diff.getAssumeUnchanged().size()); assertEquals(2, diff.getAssumeUnchanged().size());
assertEquals(1, diff.getModified().size()); assertEquals(1, diff.getModified().size());
assertEquals(0, diff.getChanged().size()); assertEquals(0, diff.getChanged().size());
assertTrue(diff.getAssumeUnchanged().contains("file2")); assertTrue(diff.getAssumeUnchanged().contains("file2"));
assertTrue(diff.getAssumeUnchanged().contains("file3")); assertTrue(diff.getAssumeUnchanged().contains("file3"));
assertTrue(diff.getModified().contains("file")); assertTrue(diff.getModified().contains("file"));
git.add().addFilepattern(".").call(); git.add().addFilepattern(".").call();
iterator = new FileTreeIterator(db); iterator = new FileTreeIterator(db);
diff = new IndexDiff(db, Constants.HEAD, iterator); diff = new IndexDiff(db, Constants.HEAD, iterator);
diff.diff(); diff.diff();
assertEquals(2, diff.getAssumeUnchanged().size()); assertEquals(2, diff.getAssumeUnchanged().size());
assertEquals(0, diff.getModified().size()); assertEquals(0, diff.getModified().size());
assertEquals(1, diff.getChanged().size()); assertEquals(1, diff.getChanged().size());
assertTrue(diff.getAssumeUnchanged().contains("file2")); assertTrue(diff.getAssumeUnchanged().contains("file2"));
assertTrue(diff.getAssumeUnchanged().contains("file3")); assertTrue(diff.getAssumeUnchanged().contains("file3"));
assertTrue(diff.getChanged().contains("file")); assertTrue(diff.getChanged().contains("file"));
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders()); assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
}
} }
@Test @Test
@ -575,147 +580,148 @@ 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") .call();
.call();
// create branch and add a new file
// create branch and add a new file final String branchName = Constants.R_HEADS + "branch";
final String branchName = Constants.R_HEADS + "branch"; createBranch(initialCommit, branchName);
createBranch(initialCommit, branchName); checkoutBranch(branchName);
checkoutBranch(branchName); writeTrashFile("b", "second file content - branch");
writeTrashFile("b", "second file content - branch"); git.add().addFilepattern("b").call();
git.add().addFilepattern("b").call(); RevCommit branchCommit = git.commit().setMessage("branch commit")
RevCommit branchCommit = git.commit().setMessage("branch commit") .call();
.call();
// checkout master and add the same new file
// checkout master and add the same new file checkoutBranch(Constants.R_HEADS + Constants.MASTER);
checkoutBranch(Constants.R_HEADS + Constants.MASTER); writeTrashFile("b", "second file content - master");
writeTrashFile("b", "second file content - master"); git.add().addFilepattern("b").call();
git.add().addFilepattern("b").call(); git.commit().setMessage("master commit").call();
git.commit().setMessage("master commit").call();
// try and merge
// try and merge MergeResult result = git.merge().include(branchCommit).call();
MergeResult result = git.merge().include(branchCommit).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); diff.diff();
diff.diff();
assertTrue(diff.getChanged().isEmpty());
assertTrue(diff.getChanged().isEmpty()); assertTrue(diff.getAdded().isEmpty());
assertTrue(diff.getAdded().isEmpty()); assertTrue(diff.getRemoved().isEmpty());
assertTrue(diff.getRemoved().isEmpty()); assertTrue(diff.getMissing().isEmpty());
assertTrue(diff.getMissing().isEmpty()); assertTrue(diff.getModified().isEmpty());
assertTrue(diff.getModified().isEmpty()); assertEquals(1, diff.getConflicting().size());
assertEquals(1, diff.getConflicting().size()); assertTrue(diff.getConflicting().contains("b"));
assertTrue(diff.getConflicting().contains("b")); assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates() .get("b"));
.get("b")); assertTrue(diff.getUntrackedFolders().isEmpty());
assertTrue(diff.getUntrackedFolders().isEmpty());
// reset file b to its master state without altering the index
// reset file b to its master state without altering the index writeTrashFile("b", "second file content - master");
writeTrashFile("b", "second file content - master");
// we should have the same result
// we should have the same result iterator = new FileTreeIterator(db);
iterator = new FileTreeIterator(db); diff = new IndexDiff(db, Constants.HEAD, iterator);
diff = new IndexDiff(db, Constants.HEAD, iterator); diff.diff();
diff.diff();
assertTrue(diff.getChanged().isEmpty());
assertTrue(diff.getChanged().isEmpty()); assertTrue(diff.getAdded().isEmpty());
assertTrue(diff.getAdded().isEmpty()); assertTrue(diff.getRemoved().isEmpty());
assertTrue(diff.getRemoved().isEmpty()); assertTrue(diff.getMissing().isEmpty());
assertTrue(diff.getMissing().isEmpty()); assertTrue(diff.getModified().isEmpty());
assertTrue(diff.getModified().isEmpty()); assertEquals(1, diff.getConflicting().size());
assertEquals(1, diff.getConflicting().size()); assertTrue(diff.getConflicting().contains("b"));
assertTrue(diff.getConflicting().contains("b")); assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates() .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") .call();
.call();
// create branch and add a new file
// create branch and add a new file final String branchName = Constants.R_HEADS + "branch";
final String branchName = Constants.R_HEADS + "branch"; createBranch(initialCommit, branchName);
createBranch(initialCommit, branchName); checkoutBranch(branchName);
checkoutBranch(branchName); writeTrashFile("b", "second file content - branch");
writeTrashFile("b", "second file content - branch"); git.add().addFilepattern("b").call();
git.add().addFilepattern("b").call(); git.commit().setMessage("branch commit")
git.commit().setMessage("branch commit") .call();
.call();
// checkout master and add the same new file
// checkout master and add the same new file checkoutBranch(Constants.R_HEADS + Constants.MASTER);
checkoutBranch(Constants.R_HEADS + Constants.MASTER); writeTrashFile("b", "second file content - master");
writeTrashFile("b", "second file content - master"); git.add().addFilepattern("b").call();
git.add().addFilepattern("b").call(); git.commit().setMessage("master commit").call();
git.commit().setMessage("master commit").call();
// Simulate a failed merge of branch into master
// Simulate a failed merge of branch into master DirCacheBuilder builder = db.lockDirCache().builder();
DirCacheBuilder builder = db.lockDirCache().builder(); DirCacheEntry entry = createEntry("a", FileMode.REGULAR_FILE, 0,
DirCacheEntry entry = createEntry("a", FileMode.REGULAR_FILE, 0, "content");
"content"); builder.add(entry);
builder.add(entry); entry = createEntry("b", FileMode.REGULAR_FILE, 2,
entry = createEntry("b", FileMode.REGULAR_FILE, 2, "second file content - master");
"second file content - master"); builder.add(entry);
builder.add(entry); entry = createEntry("b", FileMode.REGULAR_FILE, 3,
entry = createEntry("b", FileMode.REGULAR_FILE, 3, "second file content - branch");
"second file content - branch"); builder.add(entry);
builder.add(entry); builder.commit();
builder.commit();
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); diff.diff();
diff.diff();
assertTrue(diff.getChanged().isEmpty());
assertTrue(diff.getChanged().isEmpty()); assertTrue(diff.getAdded().isEmpty());
assertTrue(diff.getAdded().isEmpty()); assertTrue(diff.getRemoved().isEmpty());
assertTrue(diff.getRemoved().isEmpty()); assertTrue(diff.getMissing().isEmpty());
assertTrue(diff.getMissing().isEmpty()); assertTrue(diff.getModified().isEmpty());
assertTrue(diff.getModified().isEmpty()); assertEquals(1, diff.getConflicting().size());
assertEquals(1, diff.getConflicting().size()); assertTrue(diff.getConflicting().contains("b"));
assertTrue(diff.getConflicting().contains("b")); assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates() .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
config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null, config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE); ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE);
config.save(); config.save();
// File is already in repository with CRLF // File is already in repository with CRLF
writeTrashFile("crlf.txt", "this\r\ncontains\r\ncrlf\r\n"); writeTrashFile("crlf.txt", "this\r\ncontains\r\ncrlf\r\n");
git.add().addFilepattern("crlf.txt").call(); git.add().addFilepattern("crlf.txt").call();
git.commit().setMessage("Add crlf.txt").call(); git.commit().setMessage("Add crlf.txt").call();
// Now set core.autocrlf to input // Now set core.autocrlf to input
config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null, config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.INPUT); ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.INPUT);
config.save(); config.save();
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);
diff.diff(); diff.diff();
assertTrue( assertTrue(
"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)

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

@ -49,80 +49,81 @@ 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";
writeTrashFile(path2, "content2"); writeTrashFile(path2, "content2");
git.add().addFilepattern(path).call(); git.add().addFilepattern(path).call();
git.add().addFilepattern(path2).call(); git.add().addFilepattern(path2).call();
git.commit().setMessage("commit").call(); git.commit().setMessage("commit").call();
DirCache dc = db.readDirCache(); DirCache dc = db.readDirCache();
DirCacheEntry entry = dc.getEntry(path); DirCacheEntry entry = dc.getEntry(path);
DirCacheEntry entry2 = dc.getEntry(path); DirCacheEntry entry2 = dc.getEntry(path);
assertTrue("last modified shall not be zero!", assertTrue("last modified shall not be zero!",
entry.getLastModified() != 0); entry.getLastModified() != 0);
assertTrue("last modified shall not be zero!", assertTrue("last modified shall not be zero!",
entry2.getLastModified() != 0); entry2.getLastModified() != 0);
writeTrashFile(path, "new content"); writeTrashFile(path, "new content");
git.add().addFilepattern(path).call(); git.add().addFilepattern(path).call();
git.commit().setMessage("commit2").call(); git.commit().setMessage("commit2").call();
dc = db.readDirCache(); dc = db.readDirCache();
entry = dc.getEntry(path); entry = dc.getEntry(path);
entry2 = dc.getEntry(path); entry2 = dc.getEntry(path);
assertTrue("last modified shall not be zero!", assertTrue("last modified shall not be zero!",
entry.getLastModified() != 0); entry.getLastModified() != 0);
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");
git.add().addFilepattern(path).call(); git.add().addFilepattern(path).call();
git.commit().setMessage("commit").call(); git.commit().setMessage("commit").call();
DirCache dc = db.readDirCache(); DirCache dc = db.readDirCache();
DirCacheEntry entry = dc.getEntry(path); DirCacheEntry entry = dc.getEntry(path);
long masterLastMod = entry.getLastModified(); long masterLastMod = entry.getLastModified();
git.checkout().setCreateBranch(true).setName("side").call(); git.checkout().setCreateBranch(true).setName("side").call();
Thread.sleep(10); Thread.sleep(10);
String path2 = "file2"; String path2 = "file2";
writeTrashFile(path2, "side content"); writeTrashFile(path2, "side content");
git.add().addFilepattern(path2).call(); git.add().addFilepattern(path2).call();
git.commit().setMessage("commit").call(); git.commit().setMessage("commit").call();
dc = db.readDirCache(); dc = db.readDirCache();
entry = dc.getEntry(path); entry = dc.getEntry(path);
long sideLastMode = entry.getLastModified(); long sideLastMode = entry.getLastModified();
Thread.sleep(2000); Thread.sleep(2000);
writeTrashFile(path, "uncommitted content"); writeTrashFile(path, "uncommitted content");
git.checkout().setName("master").call(); git.checkout().setName("master").call();
dc = db.readDirCache(); dc = db.readDirCache();
entry = dc.getEntry(path); entry = dc.getEntry(path);
assertTrue("shall have equal mod time!", masterLastMod == sideLastMode);
assertTrue("shall not equal master timestamp!",
entry.getLastModified() == masterLastMod);
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 { 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);

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

@ -84,21 +84,22 @@ 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;
while (tw.next()) { try (TreeWalk tw = new TreeWalk(or)) {
if (tw.getPathString().equals("a")) { tw.addTree(tree);
a = tw.getObjectId(0); while (tw.next()) {
tw.enterSubtree(); if (tw.getPathString().equals("a")) {
while (tw.next()) { a = tw.getObjectId(0);
if (tw.getPathString().equals("a/c")) { tw.enterSubtree();
aSlashC = tw.getObjectId(0); while (tw.next()) {
break; if (tw.getPathString().equals("a/c")) {
aSlashC = tw.getObjectId(0);
break;
}
} }
break;
} }
break;
} }
} }

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

@ -76,10 +76,11 @@ 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,14 +125,15 @@ 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));
tw.setFilter(InterIndexDiffFilter.INSTANCE); tw.setFilter(InterIndexDiffFilter.INSTANCE);
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("a/a", tw.getPathString()); assertEquals("a/a", tw.getPathString());
assertFalse(tw.next()); assertFalse(tw.next());
}
} }
@Test @Test
@ -145,13 +147,14 @@ 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));
tw.setFilter(InterIndexDiffFilter.INSTANCE); tw.setFilter(InterIndexDiffFilter.INSTANCE);
assertFalse(tw.next()); assertFalse(tw.next());
}
} }
@Test @Test
@ -165,15 +168,16 @@ 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));
tw.setFilter(InterIndexDiffFilter.INSTANCE); tw.setFilter(InterIndexDiffFilter.INSTANCE);
assertTrue(tw.next()); assertTrue(tw.next());
assertEquals("a/a", tw.getPathString()); assertEquals("a/a", tw.getPathString());
assertFalse(tw.next()); assertFalse(tw.next());
}
} }
@Test @Test
@ -188,12 +192,13 @@ 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));
tw.setFilter(InterIndexDiffFilter.INSTANCE); tw.setFilter(InterIndexDiffFilter.INSTANCE);
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