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();
|
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;
|
||||||
|
|
|
@ -77,6 +77,7 @@ public void setUp() throws Exception {
|
||||||
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;
|
||||||
|
|
|
@ -62,7 +62,7 @@ public String getInitParameter(String name) {
|
||||||
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() {
|
||||||
|
|
|
@ -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,
|
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 {
|
||||||
|
|
|
@ -155,16 +155,16 @@ protected void run() throws Exception {
|
||||||
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 @@ private void run(Repository db) throws Exception {
|
||||||
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 @@ private void run(Repository db) throws Exception {
|
||||||
|
|
||||||
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();
|
||||||
|
|
|
@ -235,7 +235,7 @@ private void detachHead() throws IOException {
|
||||||
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 @@ private void recreateRefs() throws Exception {
|
||||||
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 {
|
||||||
|
|
|
@ -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())
|
||||||
|
|
|
@ -51,6 +51,8 @@
|
||||||
|
|
||||||
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 void testAddHugeFile() throws Exception {
|
||||||
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");
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -255,9 +255,11 @@ public void testRejectInvalidWindowsPaths() throws Exception {
|
||||||
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();
|
||||||
|
|
|
@ -78,23 +78,24 @@ public void testPathFilterGroup_DoesNotSkipTail() throws Exception {
|
||||||
|
|
||||||
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());
|
||||||
|
|
|
@ -98,17 +98,18 @@ public void testTreeWalk_LsFiles() throws Exception {
|
||||||
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -76,9 +76,10 @@ public void testEmptyTree_WithTreeWalk() throws Exception {
|
||||||
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 void testNoSubtree_WithTreeWalk() throws Exception {
|
||||||
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 void testSingleSubtree_NoRecursion() throws Exception {
|
||||||
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 void testSingleSubtree_Recursive() throws Exception {
|
||||||
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 void testTwoLevelSubtree_Recursive() throws Exception {
|
||||||
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 void testTwoLevelSubtree_FilterPath() throws Exception {
|
||||||
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 void testRemovedSubtree() throws Exception {
|
||||||
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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 void testManifestParser() throws Exception {
|
||||||
|
|
||||||
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");
|
||||||
|
|
|
@ -118,7 +118,7 @@ public void whileRefLockedRefNotPackedNoError()
|
||||||
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();
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -597,14 +597,13 @@ public void testUpdateRefLockFailureLocked() throws IOException {
|
||||||
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 void tryRenameWhenLocked(String toLock, String fromName,
|
||||||
"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());
|
||||||
|
|
||||||
|
|
|
@ -338,68 +338,69 @@ private void testMaliciousPathGoodSecondCheckout(String... paths) throws Excepti
|
||||||
*/
|
*/
|
||||||
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
|
|
||||||
commitBuilder = new CommitBuilder();
|
// Create another commit
|
||||||
commitBuilder.setAuthor(author);
|
commitBuilder = new CommitBuilder();
|
||||||
commitBuilder.setCommitter(committer);
|
commitBuilder.setAuthor(author);
|
||||||
commitBuilder.setMessage("foo#2");
|
commitBuilder.setCommitter(committer);
|
||||||
commitBuilder.setTreeId(insertId);
|
commitBuilder.setMessage("foo#2");
|
||||||
commitBuilder.setParentId(firstCommitId);
|
commitBuilder.setTreeId(insertId);
|
||||||
ObjectId commitId = newObjectInserter.insert(commitBuilder);
|
commitBuilder.setParentId(firstCommitId);
|
||||||
|
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"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -148,8 +148,9 @@ public void testModified() throws IOException, GitAPIException {
|
||||||
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 void testModified() throws IOException, GitAPIException {
|
||||||
|
|
||||||
@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("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");
|
// create side branch with two modifications
|
||||||
writeTrashFile("b", "1\nb\n3\n");
|
createBranch(initialCommit, "refs/heads/side");
|
||||||
git.add().addFilepattern("a").addFilepattern("b").call();
|
checkoutBranch("refs/heads/side");
|
||||||
RevCommit initialCommit = git.commit().setMessage("initial").call();
|
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
|
// update a on master to generate conflict
|
||||||
createBranch(initialCommit, "refs/heads/side");
|
checkoutBranch("refs/heads/master");
|
||||||
checkoutBranch("refs/heads/side");
|
writeTrashFile("a", "1\na(main)\n3\n");
|
||||||
writeTrashFile("a", "1\na(side)\n3\n");
|
git.add().addFilepattern("a").call();
|
||||||
writeTrashFile("b", "1\nb\n3\n(side)");
|
git.commit().setMessage("main").call();
|
||||||
git.add().addFilepattern("a").addFilepattern("b").call();
|
|
||||||
RevCommit secondCommit = git.commit().setMessage("side").call();
|
|
||||||
|
|
||||||
// update a on master to generate conflict
|
// merge side with master
|
||||||
checkoutBranch("refs/heads/master");
|
MergeResult result = git.merge().include(secondCommit.getId())
|
||||||
writeTrashFile("a", "1\na(main)\n3\n");
|
.setStrategy(MergeStrategy.RESOLVE).call();
|
||||||
git.add().addFilepattern("a").call();
|
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
|
||||||
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());
|
|
||||||
|
|
||||||
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 void testConflicting() throws Exception {
|
||||||
|
|
||||||
@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("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");
|
// create side branch and delete "a"
|
||||||
writeTrashFile("b", "1\nb\n3\n");
|
createBranch(initialCommit, "refs/heads/side");
|
||||||
git.add().addFilepattern("a").addFilepattern("b").call();
|
checkoutBranch("refs/heads/side");
|
||||||
RevCommit initialCommit = git.commit().setMessage("initial").call();
|
git.rm().addFilepattern("a").call();
|
||||||
|
RevCommit secondCommit = git.commit().setMessage("side").call();
|
||||||
|
|
||||||
// create side branch and delete "a"
|
// update a on master to generate conflict
|
||||||
createBranch(initialCommit, "refs/heads/side");
|
checkoutBranch("refs/heads/master");
|
||||||
checkoutBranch("refs/heads/side");
|
writeTrashFile("a", "1\na(main)\n3\n");
|
||||||
git.rm().addFilepattern("a").call();
|
git.add().addFilepattern("a").call();
|
||||||
RevCommit secondCommit = git.commit().setMessage("side").call();
|
git.commit().setMessage("main").call();
|
||||||
|
|
||||||
// update a on master to generate conflict
|
// merge side with master
|
||||||
checkoutBranch("refs/heads/master");
|
MergeResult result = git.merge().include(secondCommit.getId())
|
||||||
writeTrashFile("a", "1\na(main)\n3\n");
|
.setStrategy(MergeStrategy.RESOLVE).call();
|
||||||
git.add().addFilepattern("a").call();
|
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
|
||||||
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());
|
|
||||||
|
|
||||||
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 void testConflictingDeletedAndModified() throws Exception {
|
||||||
|
|
||||||
@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 void testUnchangedSimple() throws IOException, GitAPIException {
|
||||||
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 void testUnchangedSimple() throws IOException, GitAPIException {
|
||||||
*/
|
*/
|
||||||
@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 void testUnchangedComplex() throws IOException, GitAPIException {
|
||||||
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 @@ private ObjectId insertTree(TreeFormatter tree) throws IOException {
|
||||||
*/
|
*/
|
||||||
@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 void testRemovedUntracked() throws Exception{
|
||||||
*/
|
*/
|
||||||
@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,
|
||||||
|
new FileTreeIterator(db));
|
||||||
|
diff.diff();
|
||||||
|
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
|
||||||
|
|
||||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD,
|
writeTrashFile("readme", "");
|
||||||
new FileTreeIterator(db));
|
writeTrashFile("src/com/A.java", "");
|
||||||
diff.diff();
|
writeTrashFile("src/com/B.java", "");
|
||||||
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
|
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", "");
|
git.add().addFilepattern("src").addFilepattern("readme").call();
|
||||||
writeTrashFile("src/com/A.java", "");
|
git.commit().setMessage("initial").call();
|
||||||
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();
|
diff = new IndexDiff(db, Constants.HEAD,
|
||||||
git.commit().setMessage("initial").call();
|
new FileTreeIterator(db));
|
||||||
|
diff.diff();
|
||||||
|
assertEquals(new HashSet<String>(Arrays.asList("target")),
|
||||||
|
diff.getUntrackedFolders());
|
||||||
|
|
||||||
diff = new IndexDiff(db, Constants.HEAD,
|
writeTrashFile("src/tst/A.java", "");
|
||||||
new FileTreeIterator(db));
|
writeTrashFile("src/tst/B.java", "");
|
||||||
diff.diff();
|
|
||||||
assertEquals(new HashSet<String>(Arrays.asList("target")),
|
|
||||||
diff.getUntrackedFolders());
|
|
||||||
|
|
||||||
writeTrashFile("src/tst/A.java", "");
|
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
||||||
writeTrashFile("src/tst/B.java", "");
|
diff.diff();
|
||||||
|
assertEquals(new HashSet<String>(Arrays.asList("target", "src/tst")),
|
||||||
|
diff.getUntrackedFolders());
|
||||||
|
|
||||||
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
git.rm().addFilepattern("src/com/B.java").addFilepattern("src/org")
|
||||||
diff.diff();
|
.call();
|
||||||
assertEquals(new HashSet<String>(Arrays.asList("target", "src/tst")),
|
git.commit().setMessage("second").call();
|
||||||
diff.getUntrackedFolders());
|
writeTrashFile("src/org/C.java", "");
|
||||||
|
|
||||||
git.rm().addFilepattern("src/com/B.java").addFilepattern("src/org")
|
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
||||||
.call();
|
diff.diff();
|
||||||
git.commit().setMessage("second").call();
|
assertEquals(
|
||||||
writeTrashFile("src/org/C.java", "");
|
new HashSet<String>(Arrays.asList("src/org", "src/tst",
|
||||||
|
"target")),
|
||||||
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
diff.getUntrackedFolders());
|
||||||
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
|
@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,
|
||||||
|
new FileTreeIterator(db));
|
||||||
|
diff.diff();
|
||||||
|
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
|
||||||
|
|
||||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD,
|
writeTrashFile("readme", "");
|
||||||
new FileTreeIterator(db));
|
writeTrashFile("sr/com/X.java", "");
|
||||||
diff.diff();
|
writeTrashFile("src/com/A.java", "");
|
||||||
assertEquals(Collections.EMPTY_SET, diff.getUntrackedFolders());
|
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", "");
|
git.add().addFilepattern("readme").addFilepattern(".gitignore")
|
||||||
writeTrashFile("sr/com/X.java", "");
|
.addFilepattern("srcs/").call();
|
||||||
writeTrashFile("src/com/A.java", "");
|
git.commit().setMessage("initial").call();
|
||||||
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")
|
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
||||||
.addFilepattern("srcs/").call();
|
diff.diff();
|
||||||
git.commit().setMessage("initial").call();
|
assertEquals(new HashSet<String>(Arrays.asList("src")),
|
||||||
|
diff.getUntrackedFolders());
|
||||||
|
|
||||||
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
git.add().addFilepattern("src").call();
|
||||||
diff.diff();
|
writeTrashFile("sr/com/X1.java", "");
|
||||||
assertEquals(new HashSet<String>(Arrays.asList("src")),
|
writeTrashFile("src/tst/A.java", "");
|
||||||
diff.getUntrackedFolders());
|
writeTrashFile("src/tst/B.java", "");
|
||||||
|
writeTrashFile("srcs/com/Y1.java", "");
|
||||||
|
deleteTrashFile(".gitignore");
|
||||||
|
|
||||||
git.add().addFilepattern("src").call();
|
diff = new IndexDiff(db, Constants.HEAD, new FileTreeIterator(db));
|
||||||
writeTrashFile("sr/com/X1.java", "");
|
diff.diff();
|
||||||
writeTrashFile("src/tst/A.java", "");
|
assertEquals(
|
||||||
writeTrashFile("src/tst/B.java", "");
|
new HashSet<String>(Arrays.asList("srcs/com", "sr", "src/tst",
|
||||||
writeTrashFile("srcs/com/Y1.java", "");
|
"target")),
|
||||||
deleteTrashFile(".gitignore");
|
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
|
@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 void testStageState() throws IOException {
|
||||||
|
|
||||||
@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");
|
||||||
|
git.add().addFilepattern("a").call();
|
||||||
|
RevCommit initialCommit = git.commit().setMessage("initial commit")
|
||||||
|
.call();
|
||||||
|
|
||||||
writeTrashFile("a", "content");
|
// create branch and add a new file
|
||||||
git.add().addFilepattern("a").call();
|
final String branchName = Constants.R_HEADS + "branch";
|
||||||
RevCommit initialCommit = git.commit().setMessage("initial commit")
|
createBranch(initialCommit, branchName);
|
||||||
.call();
|
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
|
// checkout master and add the same new file
|
||||||
final String branchName = Constants.R_HEADS + "branch";
|
checkoutBranch(Constants.R_HEADS + Constants.MASTER);
|
||||||
createBranch(initialCommit, branchName);
|
writeTrashFile("b", "second file content - master");
|
||||||
checkoutBranch(branchName);
|
git.add().addFilepattern("b").call();
|
||||||
writeTrashFile("b", "second file content - branch");
|
git.commit().setMessage("master commit").call();
|
||||||
git.add().addFilepattern("b").call();
|
|
||||||
RevCommit branchCommit = git.commit().setMessage("branch commit")
|
|
||||||
.call();
|
|
||||||
|
|
||||||
// checkout master and add the same new file
|
// try and merge
|
||||||
checkoutBranch(Constants.R_HEADS + Constants.MASTER);
|
MergeResult result = git.merge().include(branchCommit).call();
|
||||||
writeTrashFile("b", "second file content - master");
|
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
|
||||||
git.add().addFilepattern("b").call();
|
|
||||||
git.commit().setMessage("master commit").call();
|
|
||||||
|
|
||||||
// try and merge
|
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||||
MergeResult result = git.merge().include(branchCommit).call();
|
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||||
assertEquals(MergeStatus.CONFLICTING, result.getMergeStatus());
|
diff.diff();
|
||||||
|
|
||||||
FileTreeIterator iterator = new FileTreeIterator(db);
|
assertTrue(diff.getChanged().isEmpty());
|
||||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
assertTrue(diff.getAdded().isEmpty());
|
||||||
diff.diff();
|
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());
|
// reset file b to its master state without altering the index
|
||||||
assertTrue(diff.getAdded().isEmpty());
|
writeTrashFile("b", "second file content - master");
|
||||||
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
|
// we should have the same result
|
||||||
writeTrashFile("b", "second file content - master");
|
iterator = new FileTreeIterator(db);
|
||||||
|
diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||||
|
diff.diff();
|
||||||
|
|
||||||
// we should have the same result
|
assertTrue(diff.getChanged().isEmpty());
|
||||||
iterator = new FileTreeIterator(db);
|
assertTrue(diff.getAdded().isEmpty());
|
||||||
diff = new IndexDiff(db, Constants.HEAD, iterator);
|
assertTrue(diff.getRemoved().isEmpty());
|
||||||
diff.diff();
|
assertTrue(diff.getMissing().isEmpty());
|
||||||
|
assertTrue(diff.getModified().isEmpty());
|
||||||
assertTrue(diff.getChanged().isEmpty());
|
assertEquals(1, diff.getConflicting().size());
|
||||||
assertTrue(diff.getAdded().isEmpty());
|
assertTrue(diff.getConflicting().contains("b"));
|
||||||
assertTrue(diff.getRemoved().isEmpty());
|
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
|
||||||
assertTrue(diff.getMissing().isEmpty());
|
.get("b"));
|
||||||
assertTrue(diff.getModified().isEmpty());
|
assertTrue(diff.getUntrackedFolders().isEmpty());
|
||||||
assertEquals(1, diff.getConflicting().size());
|
}
|
||||||
assertTrue(diff.getConflicting().contains("b"));
|
|
||||||
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
|
|
||||||
.get("b"));
|
|
||||||
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");
|
||||||
|
git.add().addFilepattern("a").call();
|
||||||
|
RevCommit initialCommit = git.commit().setMessage("initial commit")
|
||||||
|
.call();
|
||||||
|
|
||||||
writeTrashFile("a", "content");
|
// create branch and add a new file
|
||||||
git.add().addFilepattern("a").call();
|
final String branchName = Constants.R_HEADS + "branch";
|
||||||
RevCommit initialCommit = git.commit().setMessage("initial commit")
|
createBranch(initialCommit, branchName);
|
||||||
.call();
|
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
|
// checkout master and add the same new file
|
||||||
final String branchName = Constants.R_HEADS + "branch";
|
checkoutBranch(Constants.R_HEADS + Constants.MASTER);
|
||||||
createBranch(initialCommit, branchName);
|
writeTrashFile("b", "second file content - master");
|
||||||
checkoutBranch(branchName);
|
git.add().addFilepattern("b").call();
|
||||||
writeTrashFile("b", "second file content - branch");
|
git.commit().setMessage("master commit").call();
|
||||||
git.add().addFilepattern("b").call();
|
|
||||||
git.commit().setMessage("branch commit")
|
|
||||||
.call();
|
|
||||||
|
|
||||||
// checkout master and add the same new file
|
// Simulate a failed merge of branch into master
|
||||||
checkoutBranch(Constants.R_HEADS + Constants.MASTER);
|
DirCacheBuilder builder = db.lockDirCache().builder();
|
||||||
writeTrashFile("b", "second file content - master");
|
DirCacheEntry entry = createEntry("a", FileMode.REGULAR_FILE, 0,
|
||||||
git.add().addFilepattern("b").call();
|
"content");
|
||||||
git.commit().setMessage("master commit").call();
|
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
|
FileTreeIterator iterator = new FileTreeIterator(db);
|
||||||
DirCacheBuilder builder = db.lockDirCache().builder();
|
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
||||||
DirCacheEntry entry = createEntry("a", FileMode.REGULAR_FILE, 0,
|
diff.diff();
|
||||||
"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);
|
assertTrue(diff.getChanged().isEmpty());
|
||||||
IndexDiff diff = new IndexDiff(db, Constants.HEAD, iterator);
|
assertTrue(diff.getAdded().isEmpty());
|
||||||
diff.diff();
|
assertTrue(diff.getRemoved().isEmpty());
|
||||||
|
assertTrue(diff.getMissing().isEmpty());
|
||||||
assertTrue(diff.getChanged().isEmpty());
|
assertTrue(diff.getModified().isEmpty());
|
||||||
assertTrue(diff.getAdded().isEmpty());
|
assertEquals(1, diff.getConflicting().size());
|
||||||
assertTrue(diff.getRemoved().isEmpty());
|
assertTrue(diff.getConflicting().contains("b"));
|
||||||
assertTrue(diff.getMissing().isEmpty());
|
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
|
||||||
assertTrue(diff.getModified().isEmpty());
|
.get("b"));
|
||||||
assertEquals(1, diff.getConflicting().size());
|
assertTrue(diff.getUntrackedFolders().isEmpty());
|
||||||
assertTrue(diff.getConflicting().contains("b"));
|
}
|
||||||
assertEquals(StageState.BOTH_ADDED, diff.getConflictingStageStates()
|
|
||||||
.get("b"));
|
|
||||||
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)
|
||||||
|
|
|
@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -259,7 +259,7 @@ public void testEmptyTexts() throws IOException {
|
||||||
}
|
}
|
||||||
|
|
||||||
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);
|
||||||
|
|
|
@ -84,21 +84,22 @@ public void testFindObjects() throws Exception {
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -76,10 +76,11 @@ public void setUp() throws Exception {
|
||||||
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 void testOneOnly() throws IOException {
|
||||||
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 void testTwoSame() throws IOException {
|
||||||
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 void testTwoSameDifferByAssumeValid() throws IOException {
|
||||||
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 void testTwoSameSameAssumeValidDifferentContent()
|
||||||
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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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. */
|
/** 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 static DirCache lock(final File indexLocation, final FS fs,
|
||||||
*/
|
*/
|
||||||
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 @@ private static boolean is_DIRC(final byte[] hdr) {
|
||||||
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;
|
||||||
|
|
|
@ -274,7 +274,7 @@ public void execute(RevWalk walk, ProgressMonitor monitor)
|
||||||
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 @@ protected RefCache scanAllRefs() throws IOException {
|
||||||
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<>();
|
||||||
|
|
|
@ -354,7 +354,7 @@ && getDirectory().getName().startsWith(".")) //$NON-NLS-1$
|
||||||
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
|
||||||
|
|
|
@ -53,7 +53,6 @@
|
||||||
/** 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 PackLock(final File packFile, final FS fs) {
|
||||||
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 boolean lock(String msg) throws IOException {
|
||||||
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));
|
||||||
|
|
|
@ -588,8 +588,7 @@ void delete(RefDirectoryUpdate update) throws IOException {
|
||||||
// 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 void pack(List<String> refs) throws IOException {
|
||||||
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 void pack(List<String> refs) throws IOException {
|
||||||
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 {
|
||||||
|
|
|
@ -79,7 +79,7 @@ protected boolean tryLock(boolean deref) throws IOException {
|
||||||
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);
|
||||||
|
|
|
@ -102,7 +102,7 @@ public void formatMerge(OutputStream out, MergeResult<RawText> res,
|
||||||
* 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);
|
||||||
|
|
|
@ -74,8 +74,6 @@
|
||||||
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 FileBasedConfig(File cfgLocation, FS fs) {
|
||||||
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 void save() throws IOException {
|
||||||
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 {
|
||||||
|
|
|
@ -314,8 +314,7 @@ private void updateFETCH_HEAD(final FetchResult result) throws IOException {
|
||||||
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…
Reference in New Issue