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>
This commit is contained in:
commit
514b11ddcc
|
@ -79,6 +79,7 @@ public void setUp() throws Exception {
|
|||
factory = new DefaultReceivePackFactory();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testDisabledSingleton() throws ServiceNotAuthorizedException {
|
||||
factory = (ReceivePackFactory<HttpServletRequest>) ReceivePackFactory.DISABLED;
|
||||
|
|
|
@ -77,6 +77,7 @@ public void setUp() throws Exception {
|
|||
factory = new DefaultUploadPackFactory();
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void testDisabledSingleton() throws ServiceNotAuthorizedException {
|
||||
factory = (UploadPackFactory<HttpServletRequest>) UploadPackFactory.DISABLED;
|
||||
|
|
|
@ -62,7 +62,7 @@ public String getInitParameter(String name) {
|
|||
return parameters.get(name);
|
||||
}
|
||||
|
||||
public Enumeration getInitParameterNames() {
|
||||
public Enumeration<String> getInitParameterNames() {
|
||||
final Iterator<String> i = parameters.keySet().iterator();
|
||||
return new Enumeration<String>() {
|
||||
public boolean hasMoreElements() {
|
||||
|
|
|
@ -905,7 +905,7 @@ private static File nameFor(ObjectDirectory odb, ObjectId name, String t) {
|
|||
|
||||
private void writeFile(final File p, final byte[] bin) throws IOException,
|
||||
ObjectWritingException {
|
||||
final LockFile lck = new LockFile(p, db.getFS());
|
||||
final LockFile lck = new LockFile(p);
|
||||
if (!lck.lock())
|
||||
throw new ObjectWritingException("Can't write " + p);
|
||||
try {
|
||||
|
|
|
@ -155,16 +155,16 @@ protected void run() throws Exception {
|
|||
else
|
||||
rb.findGitDir(dir);
|
||||
|
||||
Repository db = rb.build();
|
||||
Repository repo = rb.build();
|
||||
try {
|
||||
run(db);
|
||||
run(repo);
|
||||
} finally {
|
||||
db.close();
|
||||
repo.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void run(Repository db) throws Exception {
|
||||
private void run(Repository repo) throws Exception {
|
||||
List<Test> all = init();
|
||||
|
||||
long files = 0;
|
||||
|
@ -173,14 +173,14 @@ private void run(Repository db) throws Exception {
|
|||
int maxN = 0;
|
||||
|
||||
AbbreviatedObjectId startId;
|
||||
try (ObjectReader or = db.newObjectReader();
|
||||
try (ObjectReader or = repo.newObjectReader();
|
||||
RevWalk rw = new RevWalk(or)) {
|
||||
final MutableObjectId id = new MutableObjectId();
|
||||
TreeWalk tw = new TreeWalk(or);
|
||||
tw.setFilter(TreeFilter.ANY_DIFF);
|
||||
tw.setRecursive(true);
|
||||
|
||||
ObjectId start = db.resolve(Constants.HEAD);
|
||||
ObjectId start = repo.resolve(Constants.HEAD);
|
||||
startId = or.abbreviate(start);
|
||||
rw.markStart(rw.parseCommit(start));
|
||||
for (;;) {
|
||||
|
@ -235,14 +235,15 @@ private void run(Repository db) throws Exception {
|
|||
|
||||
Collections.sort(all, new Comparator<Test>() {
|
||||
public int compare(Test a, Test b) {
|
||||
int cmp = Long.signum(a.runningTimeNanos - b.runningTimeNanos);
|
||||
if (cmp == 0)
|
||||
cmp = a.algorithm.name.compareTo(b.algorithm.name);
|
||||
return cmp;
|
||||
int result = Long.signum(a.runningTimeNanos - b.runningTimeNanos);
|
||||
if (result == 0) {
|
||||
result = a.algorithm.name.compareTo(b.algorithm.name);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
});
|
||||
|
||||
File directory = db.getDirectory();
|
||||
File directory = repo.getDirectory();
|
||||
if (directory != null) {
|
||||
String name = directory.getName();
|
||||
File parent = directory.getParentFile();
|
||||
|
|
|
@ -235,7 +235,7 @@ private void detachHead() throws IOException {
|
|||
final ObjectId id = db.resolve(Constants.HEAD);
|
||||
if (!ObjectId.isId(head) && id != null) {
|
||||
final LockFile lf;
|
||||
lf = new LockFile(new File(db.getDirectory(), Constants.HEAD), db.getFS());
|
||||
lf = new LockFile(new File(db.getDirectory(), Constants.HEAD));
|
||||
if (!lf.lock())
|
||||
throw new IOException(MessageFormat.format(CLIText.get().cannotLock, Constants.HEAD));
|
||||
lf.write(id);
|
||||
|
@ -263,7 +263,7 @@ private void recreateRefs() throws Exception {
|
|||
protected void writeFile(final String name, final byte[] content)
|
||||
throws IOException {
|
||||
final File file = new File(db.getDirectory(), name);
|
||||
final LockFile lck = new LockFile(file, db.getFS());
|
||||
final LockFile lck = new LockFile(file);
|
||||
if (!lck.lock())
|
||||
throw new ObjectWritingException(MessageFormat.format(CLIText.get().cantWrite, file));
|
||||
try {
|
||||
|
|
|
@ -66,11 +66,12 @@ public class GitConstructionTest extends RepositoryTestCase {
|
|||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
Git git = new Git(db);
|
||||
git.commit().setMessage("initial commit").call();
|
||||
writeTrashFile("Test.txt", "Hello world");
|
||||
git.add().addFilepattern("Test.txt").call();
|
||||
git.commit().setMessage("Initial commit").call();
|
||||
try (Git git = new Git(db)) {
|
||||
git.commit().setMessage("initial commit").call();
|
||||
writeTrashFile("Test.txt", "Hello world");
|
||||
git.add().addFilepattern("Test.txt").call();
|
||||
git.commit().setMessage("Initial commit").call();
|
||||
}
|
||||
|
||||
bareRepo = Git.cloneRepository().setBare(true)
|
||||
.setURI(db.getDirectory().toURI().toString())
|
||||
|
|
|
@ -51,6 +51,8 @@
|
|||
|
||||
import org.eclipse.jgit.api.ResetCommand.ResetType;
|
||||
import org.eclipse.jgit.junit.RepositoryTestCase;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
|
@ -60,12 +62,26 @@ public class HugeFileTest extends RepositoryTestCase {
|
|||
|
||||
private long lastt = t;
|
||||
|
||||
private Git git;
|
||||
|
||||
private void measure(String name) {
|
||||
long c = System.currentTimeMillis();
|
||||
System.out.println(name + ", dt=" + (c - lastt) / 1000.0 + "s");
|
||||
lastt = c;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void before() {
|
||||
git = new Git(db);
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
if (git != null) {
|
||||
git.close();
|
||||
}
|
||||
}
|
||||
|
||||
@Ignore("Test takes way too long (~10 minutes) to be part of the standard suite")
|
||||
@Test
|
||||
public void testAddHugeFile() throws Exception {
|
||||
|
@ -75,7 +91,6 @@ public void testAddHugeFile() throws Exception {
|
|||
rf.setLength(4429185024L);
|
||||
rf.close();
|
||||
measure("Created file");
|
||||
Git git = new Git(db);
|
||||
|
||||
git.add().addFilepattern("a.txt").call();
|
||||
measure("Added file");
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -255,9 +255,11 @@ public void testRejectInvalidWindowsPaths() throws Exception {
|
|||
DirCacheBuilder b = dc.builder();
|
||||
DirCacheEntry e = new DirCacheEntry(path);
|
||||
e.setFileMode(FileMode.REGULAR_FILE);
|
||||
e.setObjectId(new ObjectInserter.Formatter().idFor(
|
||||
Constants.OBJ_BLOB,
|
||||
Constants.encode(path)));
|
||||
try (ObjectInserter.Formatter formatter = new ObjectInserter.Formatter()) {
|
||||
e.setObjectId(formatter.idFor(
|
||||
Constants.OBJ_BLOB,
|
||||
Constants.encode(path)));
|
||||
}
|
||||
b.add(e);
|
||||
b.commit();
|
||||
db.readDirCache();
|
||||
|
|
|
@ -78,23 +78,24 @@ public void testPathFilterGroup_DoesNotSkipTail() throws Exception {
|
|||
|
||||
final int expIdx = 2;
|
||||
final DirCacheBuilder b = dc.builder();
|
||||
final TreeWalk tw = new TreeWalk(db);
|
||||
tw.addTree(new DirCacheBuildIterator(b));
|
||||
tw.setRecursive(true);
|
||||
tw.setFilter(PathFilterGroup.createFromStrings(Collections
|
||||
.singleton(paths[expIdx])));
|
||||
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.addTree(new DirCacheBuildIterator(b));
|
||||
tw.setRecursive(true);
|
||||
tw.setFilter(PathFilterGroup.createFromStrings(Collections
|
||||
.singleton(paths[expIdx])));
|
||||
|
||||
assertTrue("found " + paths[expIdx], tw.next());
|
||||
final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
|
||||
assertNotNull(c);
|
||||
assertEquals(expIdx, c.ptr);
|
||||
assertSame(ents[expIdx], c.getDirCacheEntry());
|
||||
assertEquals(paths[expIdx], tw.getPathString());
|
||||
assertEquals(mode.getBits(), tw.getRawMode(0));
|
||||
assertSame(mode, tw.getFileMode(0));
|
||||
b.add(c.getDirCacheEntry());
|
||||
assertTrue("found " + paths[expIdx], tw.next());
|
||||
final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
|
||||
assertNotNull(c);
|
||||
assertEquals(expIdx, c.ptr);
|
||||
assertSame(ents[expIdx], c.getDirCacheEntry());
|
||||
assertEquals(paths[expIdx], tw.getPathString());
|
||||
assertEquals(mode.getBits(), tw.getRawMode(0));
|
||||
assertSame(mode, tw.getFileMode(0));
|
||||
b.add(c.getDirCacheEntry());
|
||||
|
||||
assertFalse("no more entries", tw.next());
|
||||
assertFalse("no more entries", tw.next());
|
||||
}
|
||||
|
||||
b.finish();
|
||||
assertEquals(ents.length, dc.getEntryCount());
|
||||
|
|
|
@ -98,17 +98,18 @@ public void testTreeWalk_LsFiles() throws Exception {
|
|||
assertEquals(ls.size(), dc.getEntryCount());
|
||||
{
|
||||
final Iterator<CGitIndexRecord> rItr = ls.values().iterator();
|
||||
final TreeWalk tw = new TreeWalk(db);
|
||||
tw.setRecursive(true);
|
||||
tw.addTree(new DirCacheIterator(dc));
|
||||
while (rItr.hasNext()) {
|
||||
final DirCacheIterator dcItr;
|
||||
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.setRecursive(true);
|
||||
tw.addTree(new DirCacheIterator(dc));
|
||||
while (rItr.hasNext()) {
|
||||
final DirCacheIterator dcItr;
|
||||
|
||||
assertTrue(tw.next());
|
||||
dcItr = tw.getTree(0, DirCacheIterator.class);
|
||||
assertNotNull(dcItr);
|
||||
assertTrue(tw.next());
|
||||
dcItr = tw.getTree(0, DirCacheIterator.class);
|
||||
assertNotNull(dcItr);
|
||||
|
||||
assertEqual(rItr.next(), dcItr.getDirCacheEntry());
|
||||
assertEqual(rItr.next(), dcItr.getDirCacheEntry());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -76,9 +76,10 @@ public void testEmptyTree_WithTreeWalk() throws Exception {
|
|||
final DirCache dc = DirCache.newInCore();
|
||||
assertEquals(0, dc.getEntryCount());
|
||||
|
||||
final TreeWalk tw = new TreeWalk(db);
|
||||
tw.addTree(new DirCacheIterator(dc));
|
||||
assertFalse(tw.next());
|
||||
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.addTree(new DirCacheIterator(dc));
|
||||
assertFalse(tw.next());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -125,19 +126,20 @@ public void testNoSubtree_WithTreeWalk() throws Exception {
|
|||
b.finish();
|
||||
|
||||
final DirCacheIterator i = new DirCacheIterator(dc);
|
||||
final TreeWalk tw = new TreeWalk(db);
|
||||
tw.addTree(i);
|
||||
int pathIdx = 0;
|
||||
while (tw.next()) {
|
||||
assertSame(i, tw.getTree(0, DirCacheIterator.class));
|
||||
assertEquals(pathIdx, i.ptr);
|
||||
assertSame(ents[pathIdx], i.getDirCacheEntry());
|
||||
assertEquals(paths[pathIdx], tw.getPathString());
|
||||
assertEquals(modes[pathIdx].getBits(), tw.getRawMode(0));
|
||||
assertSame(modes[pathIdx], tw.getFileMode(0));
|
||||
pathIdx++;
|
||||
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.addTree(i);
|
||||
int pathIdx = 0;
|
||||
while (tw.next()) {
|
||||
assertSame(i, tw.getTree(0, DirCacheIterator.class));
|
||||
assertEquals(pathIdx, i.ptr);
|
||||
assertSame(ents[pathIdx], i.getDirCacheEntry());
|
||||
assertEquals(paths[pathIdx], tw.getPathString());
|
||||
assertEquals(modes[pathIdx].getBits(), tw.getRawMode(0));
|
||||
assertSame(modes[pathIdx], tw.getFileMode(0));
|
||||
pathIdx++;
|
||||
}
|
||||
assertEquals(paths.length, pathIdx);
|
||||
}
|
||||
assertEquals(paths.length, pathIdx);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -162,26 +164,27 @@ public void testSingleSubtree_NoRecursion() throws Exception {
|
|||
final int expPos[] = { 0, -1, 4 };
|
||||
|
||||
final DirCacheIterator i = new DirCacheIterator(dc);
|
||||
final TreeWalk tw = new TreeWalk(db);
|
||||
tw.addTree(i);
|
||||
tw.setRecursive(false);
|
||||
int pathIdx = 0;
|
||||
while (tw.next()) {
|
||||
assertSame(i, tw.getTree(0, DirCacheIterator.class));
|
||||
assertEquals(expModes[pathIdx].getBits(), tw.getRawMode(0));
|
||||
assertSame(expModes[pathIdx], tw.getFileMode(0));
|
||||
assertEquals(expPaths[pathIdx], tw.getPathString());
|
||||
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.addTree(i);
|
||||
tw.setRecursive(false);
|
||||
int pathIdx = 0;
|
||||
while (tw.next()) {
|
||||
assertSame(i, tw.getTree(0, DirCacheIterator.class));
|
||||
assertEquals(expModes[pathIdx].getBits(), tw.getRawMode(0));
|
||||
assertSame(expModes[pathIdx], tw.getFileMode(0));
|
||||
assertEquals(expPaths[pathIdx], tw.getPathString());
|
||||
|
||||
if (expPos[pathIdx] >= 0) {
|
||||
assertEquals(expPos[pathIdx], i.ptr);
|
||||
assertSame(ents[expPos[pathIdx]], i.getDirCacheEntry());
|
||||
} else {
|
||||
assertSame(FileMode.TREE, tw.getFileMode(0));
|
||||
if (expPos[pathIdx] >= 0) {
|
||||
assertEquals(expPos[pathIdx], i.ptr);
|
||||
assertSame(ents[expPos[pathIdx]], i.getDirCacheEntry());
|
||||
} else {
|
||||
assertSame(FileMode.TREE, tw.getFileMode(0));
|
||||
}
|
||||
|
||||
pathIdx++;
|
||||
}
|
||||
|
||||
pathIdx++;
|
||||
assertEquals(expPaths.length, pathIdx);
|
||||
}
|
||||
assertEquals(expPaths.length, pathIdx);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -202,21 +205,22 @@ public void testSingleSubtree_Recursive() throws Exception {
|
|||
b.finish();
|
||||
|
||||
final DirCacheIterator i = new DirCacheIterator(dc);
|
||||
final TreeWalk tw = new TreeWalk(db);
|
||||
tw.addTree(i);
|
||||
tw.setRecursive(true);
|
||||
int pathIdx = 0;
|
||||
while (tw.next()) {
|
||||
final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
|
||||
assertNotNull(c);
|
||||
assertEquals(pathIdx, c.ptr);
|
||||
assertSame(ents[pathIdx], c.getDirCacheEntry());
|
||||
assertEquals(paths[pathIdx], tw.getPathString());
|
||||
assertEquals(mode.getBits(), tw.getRawMode(0));
|
||||
assertSame(mode, tw.getFileMode(0));
|
||||
pathIdx++;
|
||||
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.addTree(i);
|
||||
tw.setRecursive(true);
|
||||
int pathIdx = 0;
|
||||
while (tw.next()) {
|
||||
final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
|
||||
assertNotNull(c);
|
||||
assertEquals(pathIdx, c.ptr);
|
||||
assertSame(ents[pathIdx], c.getDirCacheEntry());
|
||||
assertEquals(paths[pathIdx], tw.getPathString());
|
||||
assertEquals(mode.getBits(), tw.getRawMode(0));
|
||||
assertSame(mode, tw.getFileMode(0));
|
||||
pathIdx++;
|
||||
}
|
||||
assertEquals(paths.length, pathIdx);
|
||||
}
|
||||
assertEquals(paths.length, pathIdx);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -236,21 +240,22 @@ public void testTwoLevelSubtree_Recursive() throws Exception {
|
|||
b.add(ents[i]);
|
||||
b.finish();
|
||||
|
||||
final TreeWalk tw = new TreeWalk(db);
|
||||
tw.addTree(new DirCacheIterator(dc));
|
||||
tw.setRecursive(true);
|
||||
int pathIdx = 0;
|
||||
while (tw.next()) {
|
||||
final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
|
||||
assertNotNull(c);
|
||||
assertEquals(pathIdx, c.ptr);
|
||||
assertSame(ents[pathIdx], c.getDirCacheEntry());
|
||||
assertEquals(paths[pathIdx], tw.getPathString());
|
||||
assertEquals(mode.getBits(), tw.getRawMode(0));
|
||||
assertSame(mode, tw.getFileMode(0));
|
||||
pathIdx++;
|
||||
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.addTree(new DirCacheIterator(dc));
|
||||
tw.setRecursive(true);
|
||||
int pathIdx = 0;
|
||||
while (tw.next()) {
|
||||
final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
|
||||
assertNotNull(c);
|
||||
assertEquals(pathIdx, c.ptr);
|
||||
assertSame(ents[pathIdx], c.getDirCacheEntry());
|
||||
assertEquals(paths[pathIdx], tw.getPathString());
|
||||
assertEquals(mode.getBits(), tw.getRawMode(0));
|
||||
assertSame(mode, tw.getFileMode(0));
|
||||
pathIdx++;
|
||||
}
|
||||
assertEquals(paths.length, pathIdx);
|
||||
}
|
||||
assertEquals(paths.length, pathIdx);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -397,22 +402,23 @@ public void testTwoLevelSubtree_FilterPath() throws Exception {
|
|||
b.add(ents[i]);
|
||||
b.finish();
|
||||
|
||||
final TreeWalk tw = new TreeWalk(db);
|
||||
for (int victimIdx = 0; victimIdx < paths.length; victimIdx++) {
|
||||
tw.reset();
|
||||
tw.addTree(new DirCacheIterator(dc));
|
||||
tw.setFilter(PathFilterGroup.createFromStrings(Collections
|
||||
.singleton(paths[victimIdx])));
|
||||
tw.setRecursive(tw.getFilter().shouldBeRecursive());
|
||||
assertTrue(tw.next());
|
||||
final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
|
||||
assertNotNull(c);
|
||||
assertEquals(victimIdx, c.ptr);
|
||||
assertSame(ents[victimIdx], c.getDirCacheEntry());
|
||||
assertEquals(paths[victimIdx], tw.getPathString());
|
||||
assertEquals(mode.getBits(), tw.getRawMode(0));
|
||||
assertSame(mode, tw.getFileMode(0));
|
||||
assertFalse(tw.next());
|
||||
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||
for (int victimIdx = 0; victimIdx < paths.length; victimIdx++) {
|
||||
tw.reset();
|
||||
tw.addTree(new DirCacheIterator(dc));
|
||||
tw.setFilter(PathFilterGroup.createFromStrings(Collections
|
||||
.singleton(paths[victimIdx])));
|
||||
tw.setRecursive(tw.getFilter().shouldBeRecursive());
|
||||
assertTrue(tw.next());
|
||||
final DirCacheIterator c = tw.getTree(0, DirCacheIterator.class);
|
||||
assertNotNull(c);
|
||||
assertEquals(victimIdx, c.ptr);
|
||||
assertSame(ents[victimIdx], c.getDirCacheEntry());
|
||||
assertEquals(paths[victimIdx], tw.getPathString());
|
||||
assertEquals(mode.getBits(), tw.getRawMode(0));
|
||||
assertSame(mode, tw.getFileMode(0));
|
||||
assertFalse(tw.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -424,18 +430,19 @@ public void testRemovedSubtree() throws Exception {
|
|||
final DirCache dc = DirCache.read(path, FS.DETECTED);
|
||||
assertEquals(2, dc.getEntryCount());
|
||||
|
||||
final TreeWalk tw = new TreeWalk(db);
|
||||
tw.setRecursive(true);
|
||||
tw.addTree(new DirCacheIterator(dc));
|
||||
try (final TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.setRecursive(true);
|
||||
tw.addTree(new DirCacheIterator(dc));
|
||||
|
||||
assertTrue(tw.next());
|
||||
assertEquals("a/a", tw.getPathString());
|
||||
assertSame(FileMode.REGULAR_FILE, tw.getFileMode(0));
|
||||
assertTrue(tw.next());
|
||||
assertEquals("a/a", tw.getPathString());
|
||||
assertSame(FileMode.REGULAR_FILE, tw.getFileMode(0));
|
||||
|
||||
assertTrue(tw.next());
|
||||
assertEquals("q", tw.getPathString());
|
||||
assertSame(FileMode.REGULAR_FILE, tw.getFileMode(0));
|
||||
assertTrue(tw.next());
|
||||
assertEquals("q", tw.getPathString());
|
||||
assertSame(FileMode.REGULAR_FILE, tw.getFileMode(0));
|
||||
|
||||
assertFalse(tw.next());
|
||||
assertFalse(tw.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,8 +43,9 @@
|
|||
package org.eclipse.jgit.gitrepo;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static java.nio.charset.StandardCharsets.UTF_8;
|
||||
|
||||
import java.io.StringBufferInputStream;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -77,7 +78,7 @@ public void testManifestParser() throws Exception {
|
|||
|
||||
ManifestParser parser = new ManifestParser(
|
||||
null, null, "master", baseUrl, null, null);
|
||||
parser.read(new StringBufferInputStream(xmlContent.toString()));
|
||||
parser.read(new ByteArrayInputStream(xmlContent.toString().getBytes(UTF_8)));
|
||||
// Unfiltered projects should have them all.
|
||||
results.clear();
|
||||
results.add("foo");
|
||||
|
|
|
@ -118,7 +118,7 @@ public void whileRefLockedRefNotPackedNoError()
|
|||
tr.lightweightTag("t1", a);
|
||||
tr.lightweightTag("t2", a);
|
||||
LockFile refLock = new LockFile(new File(repo.getDirectory(),
|
||||
"refs/tags/t1"), repo.getFS());
|
||||
"refs/tags/t1"));
|
||||
try {
|
||||
refLock.lock();
|
||||
gc.packRefs();
|
||||
|
|
|
@ -61,25 +61,26 @@ public class LockFileTest extends RepositoryTestCase {
|
|||
|
||||
@Test
|
||||
public void lockFailedExceptionRecovery() throws Exception {
|
||||
Git git = new Git(db);
|
||||
writeTrashFile("file.txt", "content");
|
||||
git.add().addFilepattern("file.txt").call();
|
||||
RevCommit commit1 = git.commit().setMessage("create file").call();
|
||||
try (Git git = new Git(db)) {
|
||||
writeTrashFile("file.txt", "content");
|
||||
git.add().addFilepattern("file.txt").call();
|
||||
RevCommit commit1 = git.commit().setMessage("create file").call();
|
||||
|
||||
assertNotNull(commit1);
|
||||
writeTrashFile("file.txt", "content2");
|
||||
git.add().addFilepattern("file.txt").call();
|
||||
assertNotNull(git.commit().setMessage("edit file").call());
|
||||
assertNotNull(commit1);
|
||||
writeTrashFile("file.txt", "content2");
|
||||
git.add().addFilepattern("file.txt").call();
|
||||
assertNotNull(git.commit().setMessage("edit file").call());
|
||||
|
||||
LockFile lf = new LockFile(db.getIndexFile(), db.getFS());
|
||||
assertTrue(lf.lock());
|
||||
try {
|
||||
git.checkout().setName(commit1.name()).call();
|
||||
fail("JGitInternalException not thrown");
|
||||
} catch (JGitInternalException e) {
|
||||
assertTrue(e.getCause() instanceof LockFailedException);
|
||||
lf.unlock();
|
||||
git.checkout().setName(commit1.name()).call();
|
||||
LockFile lf = new LockFile(db.getIndexFile());
|
||||
assertTrue(lf.lock());
|
||||
try {
|
||||
git.checkout().setName(commit1.name()).call();
|
||||
fail("JGitInternalException not thrown");
|
||||
} catch (JGitInternalException e) {
|
||||
assertTrue(e.getCause() instanceof LockFailedException);
|
||||
lf.unlock();
|
||||
git.checkout().setName(commit1.name()).call();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -597,14 +597,13 @@ public void testUpdateRefLockFailureLocked() throws IOException {
|
|||
RefUpdate updateRef = db.updateRef("refs/heads/master");
|
||||
updateRef.setNewObjectId(pid);
|
||||
LockFile lockFile1 = new LockFile(new File(db.getDirectory(),
|
||||
"refs/heads/master"), db.getFS());
|
||||
"refs/heads/master"));
|
||||
try {
|
||||
assertTrue(lockFile1.lock()); // precondition to test
|
||||
Result update = updateRef.update();
|
||||
assertEquals(Result.LOCK_FAILURE, update);
|
||||
assertEquals(opid, db.resolve("refs/heads/master"));
|
||||
LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"),
|
||||
db.getFS());
|
||||
LockFile lockFile2 = new LockFile(new File(db.getDirectory(),"refs/heads/master"));
|
||||
assertFalse(lockFile2.lock()); // was locked, still is
|
||||
} finally {
|
||||
lockFile1.unlock();
|
||||
|
@ -747,8 +746,7 @@ public void tryRenameWhenLocked(String toLock, String fromName,
|
|||
"logs/" + fromName).exists());
|
||||
|
||||
// "someone" has branch X locked
|
||||
LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock),
|
||||
db.getFS());
|
||||
LockFile lockFile = new LockFile(new File(db.getDirectory(), toLock));
|
||||
try {
|
||||
assertTrue(lockFile.lock());
|
||||
|
||||
|
|
|
@ -338,68 +338,69 @@ private void testMaliciousPathGoodSecondCheckout(String... paths) throws Excepti
|
|||
*/
|
||||
private void testMaliciousPath(boolean good, boolean secondCheckout,
|
||||
String... path) throws GitAPIException, IOException {
|
||||
Git git = new Git(db);
|
||||
ObjectInserter newObjectInserter;
|
||||
newObjectInserter = git.getRepository().newObjectInserter();
|
||||
ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB,
|
||||
"data".getBytes());
|
||||
newObjectInserter = git.getRepository().newObjectInserter();
|
||||
FileMode mode = FileMode.REGULAR_FILE;
|
||||
ObjectId insertId = blobId;
|
||||
for (int i = path.length - 1; i >= 0; --i) {
|
||||
TreeFormatter treeFormatter = new TreeFormatter();
|
||||
treeFormatter.append("goodpath", mode, insertId);
|
||||
insertId = newObjectInserter.insert(treeFormatter);
|
||||
mode = FileMode.TREE;
|
||||
}
|
||||
newObjectInserter = git.getRepository().newObjectInserter();
|
||||
CommitBuilder commitBuilder = new CommitBuilder();
|
||||
commitBuilder.setAuthor(author);
|
||||
commitBuilder.setCommitter(committer);
|
||||
commitBuilder.setMessage("foo#1");
|
||||
commitBuilder.setTreeId(insertId);
|
||||
ObjectId firstCommitId = newObjectInserter.insert(commitBuilder);
|
||||
|
||||
newObjectInserter = git.getRepository().newObjectInserter();
|
||||
mode = FileMode.REGULAR_FILE;
|
||||
insertId = blobId;
|
||||
for (int i = path.length - 1; i >= 0; --i) {
|
||||
TreeFormatter treeFormatter = new TreeFormatter();
|
||||
treeFormatter.append(path[i], mode, insertId);
|
||||
insertId = newObjectInserter.insert(treeFormatter);
|
||||
mode = FileMode.TREE;
|
||||
}
|
||||
|
||||
// Create another commit
|
||||
commitBuilder = new CommitBuilder();
|
||||
commitBuilder.setAuthor(author);
|
||||
commitBuilder.setCommitter(committer);
|
||||
commitBuilder.setMessage("foo#2");
|
||||
commitBuilder.setTreeId(insertId);
|
||||
commitBuilder.setParentId(firstCommitId);
|
||||
ObjectId commitId = newObjectInserter.insert(commitBuilder);
|
||||
|
||||
RevWalk revWalk = new RevWalk(git.getRepository());
|
||||
if (!secondCheckout)
|
||||
git.checkout().setStartPoint(revWalk.parseCommit(firstCommitId))
|
||||
.setName("refs/heads/master").setCreateBranch(true).call();
|
||||
try {
|
||||
if (secondCheckout) {
|
||||
git.checkout().setStartPoint(revWalk.parseCommit(commitId))
|
||||
.setName("refs/heads/master").setCreateBranch(true)
|
||||
.call();
|
||||
} else {
|
||||
git.branchCreate().setName("refs/heads/next")
|
||||
.setStartPoint(commitId.name()).call();
|
||||
git.checkout().setName("refs/heads/next")
|
||||
.call();
|
||||
try (Git git = new Git(db);
|
||||
RevWalk revWalk = new RevWalk(git.getRepository())) {
|
||||
ObjectInserter newObjectInserter;
|
||||
newObjectInserter = git.getRepository().newObjectInserter();
|
||||
ObjectId blobId = newObjectInserter.insert(Constants.OBJ_BLOB,
|
||||
"data".getBytes());
|
||||
newObjectInserter = git.getRepository().newObjectInserter();
|
||||
FileMode mode = FileMode.REGULAR_FILE;
|
||||
ObjectId insertId = blobId;
|
||||
for (int i = path.length - 1; i >= 0; --i) {
|
||||
TreeFormatter treeFormatter = new TreeFormatter();
|
||||
treeFormatter.append("goodpath", mode, insertId);
|
||||
insertId = newObjectInserter.insert(treeFormatter);
|
||||
mode = FileMode.TREE;
|
||||
}
|
||||
newObjectInserter = git.getRepository().newObjectInserter();
|
||||
CommitBuilder commitBuilder = new CommitBuilder();
|
||||
commitBuilder.setAuthor(author);
|
||||
commitBuilder.setCommitter(committer);
|
||||
commitBuilder.setMessage("foo#1");
|
||||
commitBuilder.setTreeId(insertId);
|
||||
ObjectId firstCommitId = newObjectInserter.insert(commitBuilder);
|
||||
|
||||
newObjectInserter = git.getRepository().newObjectInserter();
|
||||
mode = FileMode.REGULAR_FILE;
|
||||
insertId = blobId;
|
||||
for (int i = path.length - 1; i >= 0; --i) {
|
||||
TreeFormatter treeFormatter = new TreeFormatter();
|
||||
treeFormatter.append(path[i], mode, insertId);
|
||||
insertId = newObjectInserter.insert(treeFormatter);
|
||||
mode = FileMode.TREE;
|
||||
}
|
||||
|
||||
// Create another commit
|
||||
commitBuilder = new CommitBuilder();
|
||||
commitBuilder.setAuthor(author);
|
||||
commitBuilder.setCommitter(committer);
|
||||
commitBuilder.setMessage("foo#2");
|
||||
commitBuilder.setTreeId(insertId);
|
||||
commitBuilder.setParentId(firstCommitId);
|
||||
ObjectId commitId = newObjectInserter.insert(commitBuilder);
|
||||
|
||||
if (!secondCheckout)
|
||||
git.checkout().setStartPoint(revWalk.parseCommit(firstCommitId))
|
||||
.setName("refs/heads/master").setCreateBranch(true).call();
|
||||
try {
|
||||
if (secondCheckout) {
|
||||
git.checkout().setStartPoint(revWalk.parseCommit(commitId))
|
||||
.setName("refs/heads/master").setCreateBranch(true)
|
||||
.call();
|
||||
} else {
|
||||
git.branchCreate().setName("refs/heads/next")
|
||||
.setStartPoint(commitId.name()).call();
|
||||
git.checkout().setName("refs/heads/next")
|
||||
.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"));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -148,8 +148,9 @@ public void testModified() throws IOException, GitAPIException {
|
|||
writeTrashFile("file2", "file2");
|
||||
writeTrashFile("dir/file3", "dir/file3");
|
||||
|
||||
Git git = new Git(db);
|
||||
git.add().addFilepattern("file2").addFilepattern("dir/file3").call();
|
||||
try (Git git = new Git(db)) {
|
||||
git.add().addFilepattern("file2").addFilepattern("dir/file3").call();
|
||||
}
|
||||
|
||||
writeTrashFile("dir/file3", "changed");
|
||||
|
||||
|
@ -177,31 +178,31 @@ public void testModified() throws IOException, GitAPIException {
|
|||
|
||||
@Test
|
||||
public void testConflicting() throws Exception {
|
||||
Git git = new Git(db);
|
||||
try (Git git = new Git(db)) {
|
||||
writeTrashFile("a", "1\na\n3\n");
|
||||
writeTrashFile("b", "1\nb\n3\n");
|
||||
git.add().addFilepattern("a").addFilepattern("b").call();
|
||||
RevCommit initialCommit = git.commit().setMessage("initial").call();
|
||||
|
||||
writeTrashFile("a", "1\na\n3\n");
|
||||
writeTrashFile("b", "1\nb\n3\n");
|
||||
git.add().addFilepattern("a").addFilepattern("b").call();
|
||||
RevCommit initialCommit = git.commit().setMessage("initial").call();
|
||||
// create side branch with two modifications
|
||||
createBranch(initialCommit, "refs/heads/side");
|
||||
checkoutBranch("refs/heads/side");
|
||||
writeTrashFile("a", "1\na(side)\n3\n");
|
||||
writeTrashFile("b", "1\nb\n3\n(side)");
|
||||
git.add().addFilepattern("a").addFilepattern("b").call();
|
||||
RevCommit secondCommit = git.commit().setMessage("side").call();
|
||||
|
||||
// create side branch with two modifications
|
||||
createBranch(initialCommit, "refs/heads/side");
|
||||
checkoutBranch("refs/heads/side");
|
||||
writeTrashFile("a", "1\na(side)\n3\n");
|
||||
writeTrashFile("b", "1\nb\n3\n(side)");
|
||||
git.add().addFilepattern("a").addFilepattern("b").call();
|
||||
RevCommit secondCommit = git.commit().setMessage("side").call();
|
||||
// update a on master to generate conflict
|
||||
checkoutBranch("refs/heads/master");
|
||||
writeTrashFile("a", "1\na(main)\n3\n");
|
||||
git.add().addFilepattern("a").call();
|
||||
git.commit().setMessage("main").call();
|
||||
|
||||
// update a on master to generate conflict
|
||||
checkoutBranch("refs/heads/master");
|
||||
writeTrashFile("a", "1\na(main)\n3\n");
|
||||
git.add().addFilepattern("a").call();
|
||||
git.commit().setMessage("main").call();
|
||||
|
||||
// merge side with master
|
||||
MergeResult result = git.merge().include(secondCommit.getId())
|
||||
.setStrategy(MergeStrategy.RESOLVE).call();
|
||||
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
|
||||
// merge side with master
|
||||
MergeResult result = git.merge().include(secondCommit.getId())
|
||||
.setStrategy(MergeStrategy.RESOLVE).call();
|
||||
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
|
||||
}
|
||||
|
||||
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
|
@ -221,29 +222,29 @@ public void testConflicting() throws Exception {
|
|||
|
||||
@Test
|
||||
public void testConflictingDeletedAndModified() throws Exception {
|
||||
Git git = new Git(db);
|
||||
try (Git git = new Git(db)) {
|
||||
writeTrashFile("a", "1\na\n3\n");
|
||||
writeTrashFile("b", "1\nb\n3\n");
|
||||
git.add().addFilepattern("a").addFilepattern("b").call();
|
||||
RevCommit initialCommit = git.commit().setMessage("initial").call();
|
||||
|
||||
writeTrashFile("a", "1\na\n3\n");
|
||||
writeTrashFile("b", "1\nb\n3\n");
|
||||
git.add().addFilepattern("a").addFilepattern("b").call();
|
||||
RevCommit initialCommit = git.commit().setMessage("initial").call();
|
||||
// create side branch and delete "a"
|
||||
createBranch(initialCommit, "refs/heads/side");
|
||||
checkoutBranch("refs/heads/side");
|
||||
git.rm().addFilepattern("a").call();
|
||||
RevCommit secondCommit = git.commit().setMessage("side").call();
|
||||
|
||||
// create side branch and delete "a"
|
||||
createBranch(initialCommit, "refs/heads/side");
|
||||
checkoutBranch("refs/heads/side");
|
||||
git.rm().addFilepattern("a").call();
|
||||
RevCommit secondCommit = git.commit().setMessage("side").call();
|
||||
// update a on master to generate conflict
|
||||
checkoutBranch("refs/heads/master");
|
||||
writeTrashFile("a", "1\na(main)\n3\n");
|
||||
git.add().addFilepattern("a").call();
|
||||
git.commit().setMessage("main").call();
|
||||
|
||||
// update a on master to generate conflict
|
||||
checkoutBranch("refs/heads/master");
|
||||
writeTrashFile("a", "1\na(main)\n3\n");
|
||||
git.add().addFilepattern("a").call();
|
||||
git.commit().setMessage("main").call();
|
||||
|
||||
// merge side with master
|
||||
MergeResult result = git.merge().include(secondCommit.getId())
|
||||
.setStrategy(MergeStrategy.RESOLVE).call();
|
||||
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
|
||||
// merge side with master
|
||||
MergeResult result = git.merge().include(secondCommit.getId())
|
||||
.setStrategy(MergeStrategy.RESOLVE).call();
|
||||
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
|
||||
}
|
||||
|
||||
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
|
@ -262,28 +263,28 @@ public void testConflictingDeletedAndModified() throws Exception {
|
|||
|
||||
@Test
|
||||
public void testConflictingFromMultipleCreations() throws Exception {
|
||||
Git git = new Git(db);
|
||||
try (Git git = new Git(db)) {
|
||||
writeTrashFile("a", "1\na\n3\n");
|
||||
git.add().addFilepattern("a").call();
|
||||
RevCommit initialCommit = git.commit().setMessage("initial").call();
|
||||
|
||||
writeTrashFile("a", "1\na\n3\n");
|
||||
git.add().addFilepattern("a").call();
|
||||
RevCommit initialCommit = git.commit().setMessage("initial").call();
|
||||
createBranch(initialCommit, "refs/heads/side");
|
||||
checkoutBranch("refs/heads/side");
|
||||
|
||||
createBranch(initialCommit, "refs/heads/side");
|
||||
checkoutBranch("refs/heads/side");
|
||||
writeTrashFile("b", "1\nb(side)\n3\n");
|
||||
git.add().addFilepattern("b").call();
|
||||
RevCommit secondCommit = git.commit().setMessage("side").call();
|
||||
|
||||
writeTrashFile("b", "1\nb(side)\n3\n");
|
||||
git.add().addFilepattern("b").call();
|
||||
RevCommit secondCommit = git.commit().setMessage("side").call();
|
||||
checkoutBranch("refs/heads/master");
|
||||
|
||||
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");
|
||||
git.add().addFilepattern("b").call();
|
||||
git.commit().setMessage("main").call();
|
||||
|
||||
MergeResult result = git.merge().include(secondCommit.getId())
|
||||
.setStrategy(MergeStrategy.RESOLVE).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);
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
|
@ -304,11 +305,12 @@ public void testUnchangedSimple() throws IOException, GitAPIException {
|
|||
writeTrashFile("a.c", "a.c");
|
||||
writeTrashFile("a=c", "a=c");
|
||||
writeTrashFile("a=d", "a=d");
|
||||
Git git = new Git(db);
|
||||
git.add().addFilepattern("a.b").call();
|
||||
git.add().addFilepattern("a.c").call();
|
||||
git.add().addFilepattern("a=c").call();
|
||||
git.add().addFilepattern("a=d").call();
|
||||
try (Git git = new Git(db)) {
|
||||
git.add().addFilepattern("a.b").call();
|
||||
git.add().addFilepattern("a.c").call();
|
||||
git.add().addFilepattern("a=c").call();
|
||||
git.add().addFilepattern("a=d").call();
|
||||
}
|
||||
|
||||
TreeFormatter tree = new TreeFormatter();
|
||||
// got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
|
||||
|
@ -338,7 +340,6 @@ public void testUnchangedSimple() throws IOException, GitAPIException {
|
|||
*/
|
||||
@Test
|
||||
public void testUnchangedComplex() throws IOException, GitAPIException {
|
||||
Git git = new Git(db);
|
||||
writeTrashFile("a.b", "a.b");
|
||||
writeTrashFile("a.c", "a.c");
|
||||
writeTrashFile("a/b.b/b", "a/b.b/b");
|
||||
|
@ -346,10 +347,12 @@ public void testUnchangedComplex() throws IOException, GitAPIException {
|
|||
writeTrashFile("a/c", "a/c");
|
||||
writeTrashFile("a=c", "a=c");
|
||||
writeTrashFile("a=d", "a=d");
|
||||
git.add().addFilepattern("a.b").addFilepattern("a.c")
|
||||
.addFilepattern("a/b.b/b").addFilepattern("a/b")
|
||||
.addFilepattern("a/c").addFilepattern("a=c")
|
||||
.addFilepattern("a=d").call();
|
||||
try (Git git = new Git(db)) {
|
||||
git.add().addFilepattern("a.b").addFilepattern("a.c")
|
||||
.addFilepattern("a/b.b/b").addFilepattern("a/b")
|
||||
.addFilepattern("a/c").addFilepattern("a=c")
|
||||
.addFilepattern("a=d").call();
|
||||
}
|
||||
|
||||
|
||||
// got the hash id'd from the data using echo -n a.b|git hash-object -t blob --stdin
|
||||
|
@ -397,11 +400,12 @@ private ObjectId insertTree(TreeFormatter tree) throws IOException {
|
|||
*/
|
||||
@Test
|
||||
public void testRemovedUntracked() throws Exception{
|
||||
Git git = new Git(db);
|
||||
String path = "file";
|
||||
writeTrashFile(path, "content");
|
||||
git.add().addFilepattern(path).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
try (Git git = new Git(db)) {
|
||||
writeTrashFile(path, "content");
|
||||
git.add().addFilepattern(path).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
}
|
||||
removeFromIndex(path);
|
||||
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
|
@ -417,51 +421,51 @@ public void testRemovedUntracked() throws Exception{
|
|||
*/
|
||||
@Test
|
||||
public void testUntrackedFolders() throws Exception {
|
||||
Git git = new Git(db);
|
||||
try (Git git = new Git(db)) {
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD,
|
||||
new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
|
||||
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD,
|
||||
new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
|
||||
writeTrashFile("readme", "");
|
||||
writeTrashFile("src/com/A.java", "");
|
||||
writeTrashFile("src/com/B.java", "");
|
||||
writeTrashFile("src/org/A.java", "");
|
||||
writeTrashFile("src/org/B.java", "");
|
||||
writeTrashFile("target/com/A.java", "");
|
||||
writeTrashFile("target/com/B.java", "");
|
||||
writeTrashFile("target/org/A.java", "");
|
||||
writeTrashFile("target/org/B.java", "");
|
||||
|
||||
writeTrashFile("readme", "");
|
||||
writeTrashFile("src/com/A.java", "");
|
||||
writeTrashFile("src/com/B.java", "");
|
||||
writeTrashFile("src/org/A.java", "");
|
||||
writeTrashFile("src/org/B.java", "");
|
||||
writeTrashFile("target/com/A.java", "");
|
||||
writeTrashFile("target/com/B.java", "");
|
||||
writeTrashFile("target/org/A.java", "");
|
||||
writeTrashFile("target/org/B.java", "");
|
||||
git.add().addFilepattern("src").addFilepattern("readme").call();
|
||||
git.commit().setMessage("initial").call();
|
||||
|
||||
git.add().addFilepattern("src").addFilepattern("readme").call();
|
||||
git.commit().setMessage("initial").call();
|
||||
diff = new IndexDiff(db, Constants.HEAD,
|
||||
new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(new HashSet<String>(Arrays.asList("target")),
|
||||
diff.getUntrackedFolders());
|
||||
|
||||
diff = new IndexDiff(db, Constants.HEAD,
|
||||
new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(new HashSet<String>(Arrays.asList("target")),
|
||||
diff.getUntrackedFolders());
|
||||
writeTrashFile("src/tst/A.java", "");
|
||||
writeTrashFile("src/tst/B.java", "");
|
||||
|
||||
writeTrashFile("src/tst/A.java", "");
|
||||
writeTrashFile("src/tst/B.java", "");
|
||||
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(new HashSet<String>(Arrays.asList("target", "src/tst")),
|
||||
diff.getUntrackedFolders());
|
||||
|
||||
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(new HashSet<String>(Arrays.asList("target", "src/tst")),
|
||||
diff.getUntrackedFolders());
|
||||
git.rm().addFilepattern("src/com/B.java").addFilepattern("src/org")
|
||||
.call();
|
||||
git.commit().setMessage("second").call();
|
||||
writeTrashFile("src/org/C.java", "");
|
||||
|
||||
git.rm().addFilepattern("src/com/B.java").addFilepattern("src/org")
|
||||
.call();
|
||||
git.commit().setMessage("second").call();
|
||||
writeTrashFile("src/org/C.java", "");
|
||||
|
||||
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(
|
||||
new HashSet<String>(Arrays.asList("src/org", "src/tst",
|
||||
"target")),
|
||||
diff.getUntrackedFolders());
|
||||
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(
|
||||
new HashSet<String>(Arrays.asList("src/org", "src/tst",
|
||||
"target")),
|
||||
diff.getUntrackedFolders());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -471,85 +475,86 @@ public void testUntrackedFolders() throws Exception {
|
|||
*/
|
||||
@Test
|
||||
public void testUntrackedNotIgnoredFolders() throws Exception {
|
||||
Git git = new Git(db);
|
||||
try (Git git = new Git(db)) {
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD,
|
||||
new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
|
||||
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD,
|
||||
new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
|
||||
writeTrashFile("readme", "");
|
||||
writeTrashFile("sr/com/X.java", "");
|
||||
writeTrashFile("src/com/A.java", "");
|
||||
writeTrashFile("src/org/B.java", "");
|
||||
writeTrashFile("srcs/org/Y.java", "");
|
||||
writeTrashFile("target/com/A.java", "");
|
||||
writeTrashFile("target/org/B.java", "");
|
||||
writeTrashFile(".gitignore", "/target\n/sr");
|
||||
|
||||
writeTrashFile("readme", "");
|
||||
writeTrashFile("sr/com/X.java", "");
|
||||
writeTrashFile("src/com/A.java", "");
|
||||
writeTrashFile("src/org/B.java", "");
|
||||
writeTrashFile("srcs/org/Y.java", "");
|
||||
writeTrashFile("target/com/A.java", "");
|
||||
writeTrashFile("target/org/B.java", "");
|
||||
writeTrashFile(".gitignore", "/target\n/sr");
|
||||
git.add().addFilepattern("readme").addFilepattern(".gitignore")
|
||||
.addFilepattern("srcs/").call();
|
||||
git.commit().setMessage("initial").call();
|
||||
|
||||
git.add().addFilepattern("readme").addFilepattern(".gitignore")
|
||||
.addFilepattern("srcs/").call();
|
||||
git.commit().setMessage("initial").call();
|
||||
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(new HashSet<String>(Arrays.asList("src")),
|
||||
diff.getUntrackedFolders());
|
||||
|
||||
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(new HashSet<String>(Arrays.asList("src")),
|
||||
diff.getUntrackedFolders());
|
||||
git.add().addFilepattern("src").call();
|
||||
writeTrashFile("sr/com/X1.java", "");
|
||||
writeTrashFile("src/tst/A.java", "");
|
||||
writeTrashFile("src/tst/B.java", "");
|
||||
writeTrashFile("srcs/com/Y1.java", "");
|
||||
deleteTrashFile(".gitignore");
|
||||
|
||||
git.add().addFilepattern("src").call();
|
||||
writeTrashFile("sr/com/X1.java", "");
|
||||
writeTrashFile("src/tst/A.java", "");
|
||||
writeTrashFile("src/tst/B.java", "");
|
||||
writeTrashFile("srcs/com/Y1.java", "");
|
||||
deleteTrashFile(".gitignore");
|
||||
|
||||
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(
|
||||
new HashSet<String>(Arrays.asList("srcs/com", "sr", "src/tst",
|
||||
"target")),
|
||||
diff.getUntrackedFolders());
|
||||
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
||||
diff.diff();
|
||||
assertEquals(
|
||||
new HashSet<String>(Arrays.asList("srcs/com", "sr", "src/tst",
|
||||
"target")),
|
||||
diff.getUntrackedFolders());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAssumeUnchanged() throws Exception {
|
||||
Git git = new Git(db);
|
||||
String path = "file";
|
||||
writeTrashFile(path, "content");
|
||||
git.add().addFilepattern(path).call();
|
||||
String path2 = "file2";
|
||||
writeTrashFile(path2, "content");
|
||||
String path3 = "file3";
|
||||
writeTrashFile(path3, "some content");
|
||||
git.add().addFilepattern(path2).addFilepattern(path3).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
assumeUnchanged(path2);
|
||||
assumeUnchanged(path3);
|
||||
writeTrashFile(path, "more content");
|
||||
deleteTrashFile(path3);
|
||||
try (Git git = new Git(db)) {
|
||||
String path = "file";
|
||||
writeTrashFile(path, "content");
|
||||
git.add().addFilepattern(path).call();
|
||||
String path2 = "file2";
|
||||
writeTrashFile(path2, "content");
|
||||
String path3 = "file3";
|
||||
writeTrashFile(path3, "some content");
|
||||
git.add().addFilepattern(path2).addFilepattern(path3).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
assumeUnchanged(path2);
|
||||
assumeUnchanged(path3);
|
||||
writeTrashFile(path, "more content");
|
||||
deleteTrashFile(path3);
|
||||
|
||||
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
diff.diff();
|
||||
assertEquals(2, diff.getAssumeUnchanged().size());
|
||||
assertEquals(1, diff.getModified().size());
|
||||
assertEquals(0, diff.getChanged().size());
|
||||
assertTrue(diff.getAssumeUnchanged().contains("file2"));
|
||||
assertTrue(diff.getAssumeUnchanged().contains("file3"));
|
||||
assertTrue(diff.getModified().contains("file"));
|
||||
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
diff.diff();
|
||||
assertEquals(2, diff.getAssumeUnchanged().size());
|
||||
assertEquals(1, diff.getModified().size());
|
||||
assertEquals(0, diff.getChanged().size());
|
||||
assertTrue(diff.getAssumeUnchanged().contains("file2"));
|
||||
assertTrue(diff.getAssumeUnchanged().contains("file3"));
|
||||
assertTrue(diff.getModified().contains("file"));
|
||||
|
||||
git.add().addFilepattern(".").call();
|
||||
git.add().addFilepattern(".").call();
|
||||
|
||||
iterator = new FileTreeIterator(db);
|
||||
diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
diff.diff();
|
||||
assertEquals(2, diff.getAssumeUnchanged().size());
|
||||
assertEquals(0, diff.getModified().size());
|
||||
assertEquals(1, diff.getChanged().size());
|
||||
assertTrue(diff.getAssumeUnchanged().contains("file2"));
|
||||
assertTrue(diff.getAssumeUnchanged().contains("file3"));
|
||||
assertTrue(diff.getChanged().contains("file"));
|
||||
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
|
||||
iterator = new FileTreeIterator(db);
|
||||
diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
diff.diff();
|
||||
assertEquals(2, diff.getAssumeUnchanged().size());
|
||||
assertEquals(0, diff.getModified().size());
|
||||
assertEquals(1, diff.getChanged().size());
|
||||
assertTrue(diff.getAssumeUnchanged().contains("file2"));
|
||||
assertTrue(diff.getAssumeUnchanged().contains("file3"));
|
||||
assertTrue(diff.getChanged().contains("file"));
|
||||
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -575,147 +580,148 @@ public void testStageState() throws IOException {
|
|||
|
||||
@Test
|
||||
public void testStageState_mergeAndReset_bug() throws Exception {
|
||||
Git git = new Git(db);
|
||||
try (Git git = new Git(db)) {
|
||||
writeTrashFile("a", "content");
|
||||
git.add().addFilepattern("a").call();
|
||||
RevCommit initialCommit = git.commit().setMessage("initial commit")
|
||||
.call();
|
||||
|
||||
writeTrashFile("a", "content");
|
||||
git.add().addFilepattern("a").call();
|
||||
RevCommit initialCommit = git.commit().setMessage("initial commit")
|
||||
.call();
|
||||
// create branch and add a new file
|
||||
final String branchName = Constants.R_HEADS + "branch";
|
||||
createBranch(initialCommit, branchName);
|
||||
checkoutBranch(branchName);
|
||||
writeTrashFile("b", "second file content - branch");
|
||||
git.add().addFilepattern("b").call();
|
||||
RevCommit branchCommit = git.commit().setMessage("branch commit")
|
||||
.call();
|
||||
|
||||
// create branch and add a new file
|
||||
final String branchName = Constants.R_HEADS + "branch";
|
||||
createBranch(initialCommit, branchName);
|
||||
checkoutBranch(branchName);
|
||||
writeTrashFile("b", "second file content - branch");
|
||||
git.add().addFilepattern("b").call();
|
||||
RevCommit branchCommit = git.commit().setMessage("branch commit")
|
||||
.call();
|
||||
// checkout master and add the same new file
|
||||
checkoutBranch(Constants.R_HEADS + Constants.MASTER);
|
||||
writeTrashFile("b", "second file content - master");
|
||||
git.add().addFilepattern("b").call();
|
||||
git.commit().setMessage("master commit").call();
|
||||
|
||||
// checkout master and add the same new file
|
||||
checkoutBranch(Constants.R_HEADS + Constants.MASTER);
|
||||
writeTrashFile("b", "second file content - master");
|
||||
git.add().addFilepattern("b").call();
|
||||
git.commit().setMessage("master commit").call();
|
||||
// try and merge
|
||||
MergeResult result = git.merge().include(branchCommit).call();
|
||||
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
|
||||
|
||||
// try and merge
|
||||
MergeResult result = git.merge().include(branchCommit).call();
|
||||
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
|
||||
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
diff.diff();
|
||||
|
||||
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
diff.diff();
|
||||
assertTrue(diff.getChanged().isEmpty());
|
||||
assertTrue(diff.getAdded().isEmpty());
|
||||
assertTrue(diff.getRemoved().isEmpty());
|
||||
assertTrue(diff.getMissing().isEmpty());
|
||||
assertTrue(diff.getModified().isEmpty());
|
||||
assertEquals(1, diff.getConflicting().size());
|
||||
assertTrue(diff.getConflicting().contains("b"));
|
||||
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
|
||||
.get("b"));
|
||||
assertTrue(diff.getUntrackedFolders().isEmpty());
|
||||
|
||||
assertTrue(diff.getChanged().isEmpty());
|
||||
assertTrue(diff.getAdded().isEmpty());
|
||||
assertTrue(diff.getRemoved().isEmpty());
|
||||
assertTrue(diff.getMissing().isEmpty());
|
||||
assertTrue(diff.getModified().isEmpty());
|
||||
assertEquals(1, diff.getConflicting().size());
|
||||
assertTrue(diff.getConflicting().contains("b"));
|
||||
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
|
||||
.get("b"));
|
||||
assertTrue(diff.getUntrackedFolders().isEmpty());
|
||||
// reset file b to its master state without altering the index
|
||||
writeTrashFile("b", "second file content - master");
|
||||
|
||||
// reset file b to its master state without altering the index
|
||||
writeTrashFile("b", "second file content - master");
|
||||
// we should have the same result
|
||||
iterator = new FileTreeIterator(db);
|
||||
diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
diff.diff();
|
||||
|
||||
// we should have the same result
|
||||
iterator = new FileTreeIterator(db);
|
||||
diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
diff.diff();
|
||||
|
||||
assertTrue(diff.getChanged().isEmpty());
|
||||
assertTrue(diff.getAdded().isEmpty());
|
||||
assertTrue(diff.getRemoved().isEmpty());
|
||||
assertTrue(diff.getMissing().isEmpty());
|
||||
assertTrue(diff.getModified().isEmpty());
|
||||
assertEquals(1, diff.getConflicting().size());
|
||||
assertTrue(diff.getConflicting().contains("b"));
|
||||
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
|
||||
.get("b"));
|
||||
assertTrue(diff.getUntrackedFolders().isEmpty());
|
||||
assertTrue(diff.getChanged().isEmpty());
|
||||
assertTrue(diff.getAdded().isEmpty());
|
||||
assertTrue(diff.getRemoved().isEmpty());
|
||||
assertTrue(diff.getMissing().isEmpty());
|
||||
assertTrue(diff.getModified().isEmpty());
|
||||
assertEquals(1, diff.getConflicting().size());
|
||||
assertTrue(diff.getConflicting().contains("b"));
|
||||
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
|
||||
.get("b"));
|
||||
assertTrue(diff.getUntrackedFolders().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStageState_simulated_bug() throws Exception {
|
||||
Git git = new Git(db);
|
||||
try (Git git = new Git(db)) {
|
||||
writeTrashFile("a", "content");
|
||||
git.add().addFilepattern("a").call();
|
||||
RevCommit initialCommit = git.commit().setMessage("initial commit")
|
||||
.call();
|
||||
|
||||
writeTrashFile("a", "content");
|
||||
git.add().addFilepattern("a").call();
|
||||
RevCommit initialCommit = git.commit().setMessage("initial commit")
|
||||
.call();
|
||||
// create branch and add a new file
|
||||
final String branchName = Constants.R_HEADS + "branch";
|
||||
createBranch(initialCommit, branchName);
|
||||
checkoutBranch(branchName);
|
||||
writeTrashFile("b", "second file content - branch");
|
||||
git.add().addFilepattern("b").call();
|
||||
git.commit().setMessage("branch commit")
|
||||
.call();
|
||||
|
||||
// create branch and add a new file
|
||||
final String branchName = Constants.R_HEADS + "branch";
|
||||
createBranch(initialCommit, branchName);
|
||||
checkoutBranch(branchName);
|
||||
writeTrashFile("b", "second file content - branch");
|
||||
git.add().addFilepattern("b").call();
|
||||
git.commit().setMessage("branch commit")
|
||||
.call();
|
||||
// checkout master and add the same new file
|
||||
checkoutBranch(Constants.R_HEADS + Constants.MASTER);
|
||||
writeTrashFile("b", "second file content - master");
|
||||
git.add().addFilepattern("b").call();
|
||||
git.commit().setMessage("master commit").call();
|
||||
|
||||
// checkout master and add the same new file
|
||||
checkoutBranch(Constants.R_HEADS + Constants.MASTER);
|
||||
writeTrashFile("b", "second file content - master");
|
||||
git.add().addFilepattern("b").call();
|
||||
git.commit().setMessage("master commit").call();
|
||||
// Simulate a failed merge of branch into master
|
||||
DirCacheBuilder builder = db.lockDirCache().builder();
|
||||
DirCacheEntry entry = createEntry("a", FileMode.REGULAR_FILE, 0,
|
||||
"content");
|
||||
builder.add(entry);
|
||||
entry = createEntry("b", FileMode.REGULAR_FILE, 2,
|
||||
"second file content - master");
|
||||
builder.add(entry);
|
||||
entry = createEntry("b", FileMode.REGULAR_FILE, 3,
|
||||
"second file content - branch");
|
||||
builder.add(entry);
|
||||
builder.commit();
|
||||
|
||||
// Simulate a failed merge of branch into master
|
||||
DirCacheBuilder builder = db.lockDirCache().builder();
|
||||
DirCacheEntry entry = createEntry("a", FileMode.REGULAR_FILE, 0,
|
||||
"content");
|
||||
builder.add(entry);
|
||||
entry = createEntry("b", FileMode.REGULAR_FILE, 2,
|
||||
"second file content - master");
|
||||
builder.add(entry);
|
||||
entry = createEntry("b", FileMode.REGULAR_FILE, 3,
|
||||
"second file content - branch");
|
||||
builder.add(entry);
|
||||
builder.commit();
|
||||
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
diff.diff();
|
||||
|
||||
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
diff.diff();
|
||||
|
||||
assertTrue(diff.getChanged().isEmpty());
|
||||
assertTrue(diff.getAdded().isEmpty());
|
||||
assertTrue(diff.getRemoved().isEmpty());
|
||||
assertTrue(diff.getMissing().isEmpty());
|
||||
assertTrue(diff.getModified().isEmpty());
|
||||
assertEquals(1, diff.getConflicting().size());
|
||||
assertTrue(diff.getConflicting().contains("b"));
|
||||
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
|
||||
.get("b"));
|
||||
assertTrue(diff.getUntrackedFolders().isEmpty());
|
||||
assertTrue(diff.getChanged().isEmpty());
|
||||
assertTrue(diff.getAdded().isEmpty());
|
||||
assertTrue(diff.getRemoved().isEmpty());
|
||||
assertTrue(diff.getMissing().isEmpty());
|
||||
assertTrue(diff.getModified().isEmpty());
|
||||
assertEquals(1, diff.getConflicting().size());
|
||||
assertTrue(diff.getConflicting().contains("b"));
|
||||
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
|
||||
.get("b"));
|
||||
assertTrue(diff.getUntrackedFolders().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAutoCRLFInput() throws Exception {
|
||||
Git git = new Git(db);
|
||||
FileBasedConfig config = db.getConfig();
|
||||
try (Git git = new Git(db)) {
|
||||
FileBasedConfig config = db.getConfig();
|
||||
|
||||
// Make sure core.autocrlf is false before adding
|
||||
config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
|
||||
ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE);
|
||||
config.save();
|
||||
// Make sure core.autocrlf is false before adding
|
||||
config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
|
||||
ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.FALSE);
|
||||
config.save();
|
||||
|
||||
// File is already in repository with CRLF
|
||||
writeTrashFile("crlf.txt", "this\r\ncontains\r\ncrlf\r\n");
|
||||
git.add().addFilepattern("crlf.txt").call();
|
||||
git.commit().setMessage("Add crlf.txt").call();
|
||||
// File is already in repository with CRLF
|
||||
writeTrashFile("crlf.txt", "this\r\ncontains\r\ncrlf\r\n");
|
||||
git.add().addFilepattern("crlf.txt").call();
|
||||
git.commit().setMessage("Add crlf.txt").call();
|
||||
|
||||
// Now set core.autocrlf to input
|
||||
config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
|
||||
ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.INPUT);
|
||||
config.save();
|
||||
// Now set core.autocrlf to input
|
||||
config.setEnum(ConfigConstants.CONFIG_CORE_SECTION, null,
|
||||
ConfigConstants.CONFIG_KEY_AUTOCRLF, AutoCRLF.INPUT);
|
||||
config.save();
|
||||
|
||||
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
diff.diff();
|
||||
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||
diff.diff();
|
||||
|
||||
assertTrue(
|
||||
"Expected no modified files, but there were: "
|
||||
+ diff.getModified(), diff.getModified().isEmpty());
|
||||
assertTrue(
|
||||
"Expected no modified files, but there were: "
|
||||
+ diff.getModified(), diff.getModified().isEmpty());
|
||||
}
|
||||
}
|
||||
|
||||
private void verifyStageState(StageState expected, int... stages)
|
||||
|
|
|
@ -49,80 +49,81 @@ public class IndexModificationTimesTest extends RepositoryTestCase {
|
|||
|
||||
@Test
|
||||
public void testLastModifiedTimes() throws Exception {
|
||||
Git git = new Git(db);
|
||||
String path = "file";
|
||||
writeTrashFile(path, "content");
|
||||
String path2 = "file2";
|
||||
writeTrashFile(path2, "content2");
|
||||
try (Git git = new Git(db)) {
|
||||
String path = "file";
|
||||
writeTrashFile(path, "content");
|
||||
String path2 = "file2";
|
||||
writeTrashFile(path2, "content2");
|
||||
|
||||
git.add().addFilepattern(path).call();
|
||||
git.add().addFilepattern(path2).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
git.add().addFilepattern(path).call();
|
||||
git.add().addFilepattern(path2).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
|
||||
DirCache dc = db.readDirCache();
|
||||
DirCacheEntry entry = dc.getEntry(path);
|
||||
DirCacheEntry entry2 = dc.getEntry(path);
|
||||
DirCache dc = db.readDirCache();
|
||||
DirCacheEntry entry = dc.getEntry(path);
|
||||
DirCacheEntry entry2 = dc.getEntry(path);
|
||||
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry.getLastModified() != 0);
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry.getLastModified() != 0);
|
||||
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry2.getLastModified() != 0);
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry2.getLastModified() != 0);
|
||||
|
||||
writeTrashFile(path, "new content");
|
||||
git.add().addFilepattern(path).call();
|
||||
git.commit().setMessage("commit2").call();
|
||||
writeTrashFile(path, "new content");
|
||||
git.add().addFilepattern(path).call();
|
||||
git.commit().setMessage("commit2").call();
|
||||
|
||||
dc = db.readDirCache();
|
||||
entry = dc.getEntry(path);
|
||||
entry2 = dc.getEntry(path);
|
||||
dc = db.readDirCache();
|
||||
entry = dc.getEntry(path);
|
||||
entry2 = dc.getEntry(path);
|
||||
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry.getLastModified() != 0);
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry.getLastModified() != 0);
|
||||
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry2.getLastModified() != 0);
|
||||
assertTrue("last modified shall not be zero!",
|
||||
entry2.getLastModified() != 0);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testModify() throws Exception {
|
||||
Git git = new Git(db);
|
||||
String path = "file";
|
||||
writeTrashFile(path, "content");
|
||||
try (Git git = new Git(db)) {
|
||||
String path = "file";
|
||||
writeTrashFile(path, "content");
|
||||
|
||||
git.add().addFilepattern(path).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
git.add().addFilepattern(path).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
|
||||
DirCache dc = db.readDirCache();
|
||||
DirCacheEntry entry = dc.getEntry(path);
|
||||
DirCache dc = db.readDirCache();
|
||||
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);
|
||||
String path2 = "file2";
|
||||
writeTrashFile(path2, "side content");
|
||||
git.add().addFilepattern(path2).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
Thread.sleep(10);
|
||||
String path2 = "file2";
|
||||
writeTrashFile(path2, "side content");
|
||||
git.add().addFilepattern(path2).call();
|
||||
git.commit().setMessage("commit").call();
|
||||
|
||||
dc = db.readDirCache();
|
||||
entry = dc.getEntry(path);
|
||||
dc = db.readDirCache();
|
||||
entry = dc.getEntry(path);
|
||||
|
||||
long sideLastMode = entry.getLastModified();
|
||||
long sideLastMode = entry.getLastModified();
|
||||
|
||||
Thread.sleep(2000);
|
||||
Thread.sleep(2000);
|
||||
|
||||
writeTrashFile(path, "uncommitted content");
|
||||
git.checkout().setName("master").call();
|
||||
writeTrashFile(path, "uncommitted content");
|
||||
git.checkout().setName("master").call();
|
||||
|
||||
dc = db.readDirCache();
|
||||
entry = dc.getEntry(path);
|
||||
|
||||
assertTrue("shall have equal mod time!", masterLastMod == sideLastMode);
|
||||
assertTrue("shall not equal master timestamp!",
|
||||
entry.getLastModified() == masterLastMod);
|
||||
dc = db.readDirCache();
|
||||
entry = dc.getEntry(path);
|
||||
|
||||
assertTrue("shall have equal mod time!", masterLastMod == sideLastMode);
|
||||
assertTrue("shall not equal master timestamp!",
|
||||
entry.getLastModified() == masterLastMod);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -259,7 +259,7 @@ public void testEmptyTexts() 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));
|
||||
ByteArrayOutputStream bo=new ByteArrayOutputStream(50);
|
||||
fmt.formatMerge(bo, r, "B", "O", "T", Constants.CHARACTER_ENCODING);
|
||||
|
|
|
@ -84,21 +84,22 @@ public void testFindObjects() throws Exception {
|
|||
ObjectId tree = tree0.writeTree(oi);
|
||||
|
||||
// Find the directories that were implicitly created above.
|
||||
TreeWalk tw = new TreeWalk(or);
|
||||
tw.addTree(tree);
|
||||
ObjectId a = null;
|
||||
ObjectId aSlashC = null;
|
||||
while (tw.next()) {
|
||||
if (tw.getPathString().equals("a")) {
|
||||
a = tw.getObjectId(0);
|
||||
tw.enterSubtree();
|
||||
while (tw.next()) {
|
||||
if (tw.getPathString().equals("a/c")) {
|
||||
aSlashC = tw.getObjectId(0);
|
||||
break;
|
||||
try (TreeWalk tw = new TreeWalk(or)) {
|
||||
tw.addTree(tree);
|
||||
while (tw.next()) {
|
||||
if (tw.getPathString().equals("a")) {
|
||||
a = tw.getObjectId(0);
|
||||
tw.enterSubtree();
|
||||
while (tw.next()) {
|
||||
if (tw.getPathString().equals("a/c")) {
|
||||
aSlashC = tw.getObjectId(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -76,10 +76,11 @@ public void setUp() throws Exception {
|
|||
public void testEmpty() throws IOException {
|
||||
DirCache dc1 = DirCache.newInCore();
|
||||
DirCache dc2 = DirCache.newInCore();
|
||||
TreeWalk tw = new TreeWalk(db);
|
||||
tw.addTree(new DirCacheIterator(dc1));
|
||||
tw.addTree(new DirCacheIterator(dc2));
|
||||
assertFalse(tw.next());
|
||||
try (TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.addTree(new DirCacheIterator(dc1));
|
||||
tw.addTree(new DirCacheIterator(dc2));
|
||||
assertFalse(tw.next());
|
||||
}
|
||||
}
|
||||
|
||||
static final class AddEdit extends PathEdit {
|
||||
|
@ -124,14 +125,15 @@ public void testOneOnly() throws IOException {
|
|||
editor.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false));
|
||||
editor.finish();
|
||||
|
||||
TreeWalk tw = new TreeWalk(db);
|
||||
tw.setRecursive(true);
|
||||
tw.addTree(new DirCacheIterator(dc1));
|
||||
tw.addTree(new DirCacheIterator(dc2));
|
||||
tw.setFilter(InterIndexDiffFilter.INSTANCE);
|
||||
assertTrue(tw.next());
|
||||
assertEquals("a/a", tw.getPathString());
|
||||
assertFalse(tw.next());
|
||||
try (TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.setRecursive(true);
|
||||
tw.addTree(new DirCacheIterator(dc1));
|
||||
tw.addTree(new DirCacheIterator(dc2));
|
||||
tw.setFilter(InterIndexDiffFilter.INSTANCE);
|
||||
assertTrue(tw.next());
|
||||
assertEquals("a/a", tw.getPathString());
|
||||
assertFalse(tw.next());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -145,13 +147,14 @@ public void testTwoSame() throws IOException {
|
|||
ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, false));
|
||||
ed2.finish();
|
||||
|
||||
TreeWalk tw = new TreeWalk(db);
|
||||
tw.setRecursive(true);
|
||||
tw.addTree(new DirCacheIterator(dc1));
|
||||
tw.addTree(new DirCacheIterator(dc2));
|
||||
tw.setFilter(InterIndexDiffFilter.INSTANCE);
|
||||
try (TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.setRecursive(true);
|
||||
tw.addTree(new DirCacheIterator(dc1));
|
||||
tw.addTree(new DirCacheIterator(dc2));
|
||||
tw.setFilter(InterIndexDiffFilter.INSTANCE);
|
||||
|
||||
assertFalse(tw.next());
|
||||
assertFalse(tw.next());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -165,15 +168,16 @@ public void testTwoSameDifferByAssumeValid() throws IOException {
|
|||
ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("a"), 1, true));
|
||||
ed2.finish();
|
||||
|
||||
TreeWalk tw = new TreeWalk(db);
|
||||
tw.setRecursive(true);
|
||||
tw.addTree(new DirCacheIterator(dc1));
|
||||
tw.addTree(new DirCacheIterator(dc2));
|
||||
tw.setFilter(InterIndexDiffFilter.INSTANCE);
|
||||
try (TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.setRecursive(true);
|
||||
tw.addTree(new DirCacheIterator(dc1));
|
||||
tw.addTree(new DirCacheIterator(dc2));
|
||||
tw.setFilter(InterIndexDiffFilter.INSTANCE);
|
||||
|
||||
assertTrue(tw.next());
|
||||
assertEquals("a/a", tw.getPathString());
|
||||
assertFalse(tw.next());
|
||||
assertTrue(tw.next());
|
||||
assertEquals("a/a", tw.getPathString());
|
||||
assertFalse(tw.next());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -188,12 +192,13 @@ public void testTwoSameSameAssumeValidDifferentContent()
|
|||
ed2.add(new AddEdit("a/a", FileMode.REGULAR_FILE, id("b"), 1, true));
|
||||
ed2.finish();
|
||||
|
||||
TreeWalk tw = new TreeWalk(db);
|
||||
tw.setRecursive(true);
|
||||
tw.addTree(new DirCacheIterator(dc1));
|
||||
tw.addTree(new DirCacheIterator(dc2));
|
||||
tw.setFilter(InterIndexDiffFilter.INSTANCE);
|
||||
try (TreeWalk tw = new TreeWalk(db)) {
|
||||
tw.setRecursive(true);
|
||||
tw.addTree(new DirCacheIterator(dc1));
|
||||
tw.addTree(new DirCacheIterator(dc2));
|
||||
tw.setFilter(InterIndexDiffFilter.INSTANCE);
|
||||
|
||||
assertFalse(tw.next());
|
||||
assertFalse(tw.next());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -344,9 +344,6 @@ public static DirCache lock(final File indexLocation, final FS fs,
|
|||
/** Our active lock (if we hold it); null if we don't have it locked. */
|
||||
private LockFile myLock;
|
||||
|
||||
/** file system abstraction **/
|
||||
private final FS fs;
|
||||
|
||||
/** Keep track of whether the index has changed or not */
|
||||
private FileSnapshot snapshot;
|
||||
|
||||
|
@ -376,7 +373,6 @@ public static DirCache lock(final File indexLocation, final FS fs,
|
|||
*/
|
||||
public DirCache(final File indexLocation, final FS fs) {
|
||||
liveFile = indexLocation;
|
||||
this.fs = fs;
|
||||
clear();
|
||||
}
|
||||
|
||||
|
@ -611,7 +607,7 @@ private static boolean is_DIRC(final byte[] hdr) {
|
|||
public boolean lock() throws IOException {
|
||||
if (liveFile == null)
|
||||
throw new IOException(JGitText.get().dirCacheDoesNotHaveABackingFile);
|
||||
final LockFile tmp = new LockFile(liveFile, fs);
|
||||
final LockFile tmp = new LockFile(liveFile);
|
||||
if (tmp.lock()) {
|
||||
tmp.setNeedStatInformation(true);
|
||||
myLock = tmp;
|
||||
|
|
|
@ -274,7 +274,7 @@ public void execute(RevWalk walk, ProgressMonitor monitor)
|
|||
if (performsAtomicTransactions()) {
|
||||
try {
|
||||
lock.writeLock().lock();
|
||||
batch(walk, getCommands());
|
||||
batch(getCommands());
|
||||
} finally {
|
||||
lock.writeLock().unlock();
|
||||
}
|
||||
|
@ -304,7 +304,7 @@ protected RefCache scanAllRefs() throws IOException {
|
|||
return new RefCache(ids.toRefList(), sym.toRefList());
|
||||
}
|
||||
|
||||
private void batch(RevWalk walk, List<ReceiveCommand> cmds) {
|
||||
private void batch(List<ReceiveCommand> cmds) {
|
||||
// Validate that the target exists in a new RevWalk, as the RevWalk
|
||||
// from the RefUpdate might be reading back unflushed objects.
|
||||
Map<ObjectId, ObjectId> peeled = new HashMap<>();
|
||||
|
|
|
@ -354,7 +354,7 @@ && getDirectory().getName().startsWith(".")) //$NON-NLS-1$
|
|||
ConfigConstants.CONFIG_KEY_WORKTREE, getWorkTree()
|
||||
.getAbsolutePath());
|
||||
LockFile dotGitLockFile = new LockFile(new File(workTree,
|
||||
Constants.DOT_GIT), getFS());
|
||||
Constants.DOT_GIT));
|
||||
try {
|
||||
if (dotGitLockFile.lock()) {
|
||||
dotGitLockFile.write(Constants.encode(Constants.GITDIR
|
||||
|
|
|
@ -53,7 +53,6 @@
|
|||
/** Keeps track of a {@link PackFile}'s associated <code>.keep</code> file. */
|
||||
public class PackLock {
|
||||
private final File keepFile;
|
||||
private final FS fs;
|
||||
|
||||
/**
|
||||
* Create a new lock for a pack file.
|
||||
|
@ -67,7 +66,6 @@ public PackLock(final File packFile, final FS fs) {
|
|||
final File p = packFile.getParentFile();
|
||||
final String n = packFile.getName();
|
||||
keepFile = new File(p, n.substring(0, n.length() - 5) + ".keep"); //$NON-NLS-1$
|
||||
this.fs = fs;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -84,7 +82,7 @@ public boolean lock(String msg) throws IOException {
|
|||
return false;
|
||||
if (!msg.endsWith("\n")) //$NON-NLS-1$
|
||||
msg += "\n"; //$NON-NLS-1$
|
||||
final LockFile lf = new LockFile(keepFile, fs);
|
||||
final LockFile lf = new LockFile(keepFile);
|
||||
if (!lf.lock())
|
||||
return false;
|
||||
lf.write(Constants.encode(msg));
|
||||
|
|
|
@ -588,8 +588,7 @@ void delete(RefDirectoryUpdate update) throws IOException {
|
|||
// we don't miss an edit made externally.
|
||||
final PackedRefList packed = getPackedRefs();
|
||||
if (packed.contains(name)) {
|
||||
LockFile lck = new LockFile(packedRefsFile,
|
||||
update.getRepository().getFS());
|
||||
LockFile lck = new LockFile(packedRefsFile);
|
||||
if (!lck.lock())
|
||||
throw new LockFailedException(packedRefsFile);
|
||||
try {
|
||||
|
@ -639,7 +638,7 @@ public void pack(List<String> refs) throws IOException {
|
|||
FS fs = parent.getFS();
|
||||
|
||||
// Lock the packed refs file and read the content
|
||||
LockFile lck = new LockFile(packedRefsFile, fs);
|
||||
LockFile lck = new LockFile(packedRefsFile);
|
||||
if (!lck.lock())
|
||||
throw new IOException(MessageFormat.format(
|
||||
JGitText.get().cannotLock, packedRefsFile));
|
||||
|
@ -670,8 +669,7 @@ public void pack(List<String> refs) throws IOException {
|
|||
File refFile = fileFor(refName);
|
||||
if (!fs.exists(refFile))
|
||||
continue;
|
||||
LockFile rLck = new LockFile(refFile,
|
||||
parent.getFS());
|
||||
LockFile rLck = new LockFile(refFile);
|
||||
if (!rLck.lock())
|
||||
continue;
|
||||
try {
|
||||
|
|
|
@ -79,7 +79,7 @@ protected boolean tryLock(boolean deref) throws IOException {
|
|||
if (deref)
|
||||
dst = dst.getLeaf();
|
||||
String name = dst.getName();
|
||||
lock = new LockFile(database.fileFor(name), getRepository().getFS());
|
||||
lock = new LockFile(database.fileFor(name));
|
||||
if (lock.lock()) {
|
||||
dst = database.getRef(name);
|
||||
setOldObjectId(dst != null ? dst.getObjectId() : null);
|
||||
|
|
|
@ -102,7 +102,7 @@ public void formatMerge(OutputStream out, MergeResult<RawText> res,
|
|||
* metadata
|
||||
* @throws IOException
|
||||
*/
|
||||
public void formatMerge(OutputStream out, MergeResult res, String baseName,
|
||||
public void formatMerge(OutputStream out, MergeResult<RawText> res, String baseName,
|
||||
String oursName, String theirsName, String charsetName) throws IOException {
|
||||
List<String> names = new ArrayList<String>(3);
|
||||
names.add(baseName);
|
||||
|
|
|
@ -74,8 +74,6 @@
|
|||
public class FileBasedConfig extends StoredConfig {
|
||||
private final File configFile;
|
||||
|
||||
private final FS fs;
|
||||
|
||||
private boolean utf8Bom;
|
||||
|
||||
private volatile FileSnapshot snapshot;
|
||||
|
@ -109,7 +107,6 @@ public FileBasedConfig(File cfgLocation, FS fs) {
|
|||
public FileBasedConfig(Config base, File cfgLocation, FS fs) {
|
||||
super(base);
|
||||
configFile = cfgLocation;
|
||||
this.fs = fs;
|
||||
this.snapshot = FileSnapshot.DIRTY;
|
||||
this.hash = ObjectId.zeroId();
|
||||
}
|
||||
|
@ -203,7 +200,7 @@ public void save() throws IOException {
|
|||
out = Constants.encode(text);
|
||||
}
|
||||
|
||||
final LockFile lf = new LockFile(getFile(), fs);
|
||||
final LockFile lf = new LockFile(getFile());
|
||||
if (!lf.lock())
|
||||
throw new LockFailedException(getFile());
|
||||
try {
|
||||
|
|
|
@ -314,8 +314,7 @@ private void updateFETCH_HEAD(final FetchResult result) throws IOException {
|
|||
File meta = transport.local.getDirectory();
|
||||
if (meta == null)
|
||||
return;
|
||||
final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD"), //$NON-NLS-1$
|
||||
transport.local.getFS());
|
||||
final LockFile lock = new LockFile(new File(meta, "FETCH_HEAD")); //$NON-NLS-1$
|
||||
try {
|
||||
if (lock.lock()) {
|
||||
final Writer w = new OutputStreamWriter(lock.getOutputStream());
|
||||
|
|
Loading…
Reference in New Issue