git.add().addFilepattern("a.txt").call();
assertEquals(
- "[a.txt, mode:100644, sha1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea]",
- indexState(CONTENT_ID));
+ "[a.txt, mode:100644, content:content]",
+ indexState(CONTENT));
}
public void testAddExistingSingleFileInSubDir() throws IOException, NoFilepatternException {
git.add().addFilepattern("sub/a.txt").call();
assertEquals(
- "[sub/a.txt, mode:100644, sha1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea]",
- indexState(CONTENT_ID));
+ "[sub/a.txt, mode:100644, content:content]",
+ indexState(CONTENT));
}
public void testAddExistingSingleFileTwice() throws IOException, NoFilepatternException {
dc = git.add().addFilepattern("a.txt").call();
assertEquals(
- "[a.txt, mode:100644, sha1:4f41554f6e0045ef53848fc0c3f33b6a9abc24a9]",
- indexState(CONTENT_ID));
+ "[a.txt, mode:100644, content:other content]",
+ indexState(CONTENT));
}
public void testAddExistingSingleFileTwiceWithCommit() throws Exception {
dc = git.add().addFilepattern("a.txt").call();
assertEquals(
- "[a.txt, mode:100644, sha1:4f41554f6e0045ef53848fc0c3f33b6a9abc24a9]",
- indexState(CONTENT_ID));
+ "[a.txt, mode:100644, content:other content]",
+ indexState(CONTENT));
}
public void testAddRemovedFile() throws Exception {
dc = git.add().addFilepattern("a.txt").call();
assertEquals(
- "[a.txt, mode:100644, sha1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea]",
- indexState(CONTENT_ID));
+ "[a.txt, mode:100644, content:content]",
+ indexState(CONTENT));
}
public void testAddRemovedCommittedFile() throws Exception {
dc = git.add().addFilepattern("a.txt").call();
assertEquals(
- "[a.txt, mode:100644, sha1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea]",
- indexState(CONTENT_ID));
+ "[a.txt, mode:100644, content:content]",
+ indexState(CONTENT));
}
public void testAddWithConflicts() throws Exception {
builder.commit();
assertEquals(
- "[a.txt, mode:100644, stage:1, sha1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea]" +
- "[a.txt, mode:100644, stage:2, sha1:b9f89ff733bdaf49e02711535867bb821f9db55e]" +
- "[a.txt, mode:100644, stage:3, sha1:4f41554f6e0045ef53848fc0c3f33b6a9abc24a9]" +
- "[b.txt, mode:100644, sha1:50e9cdb03f9719261dd39d7f2920b906db3711a3]",
- indexState(CONTENT_ID));
+ "[a.txt, mode:100644, stage:1, content:content]" +
+ "[a.txt, mode:100644, stage:2, content:our content]" +
+ "[a.txt, mode:100644, stage:3, content:other content]" +
+ "[b.txt, mode:100644, content:content b]",
+ indexState(CONTENT));
// now the test begins
dc = git.add().addFilepattern("a.txt").call();
assertEquals(
- "[a.txt, mode:100644, sha1:b9f89ff733bdaf49e02711535867bb821f9db55e]" +
- "[b.txt, mode:100644, sha1:50e9cdb03f9719261dd39d7f2920b906db3711a3]",
- indexState(CONTENT_ID));
+ "[a.txt, mode:100644, content:our content]" +
+ "[b.txt, mode:100644, content:content b]",
+ indexState(CONTENT));
}
public void testAddTwoFiles() throws Exception {
Git git = new Git(db);
git.add().addFilepattern("a.txt").addFilepattern("b.txt").call();
assertEquals(
- "[a.txt, mode:100644, sha1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea]" +
- "[b.txt, mode:100644, sha1:50e9cdb03f9719261dd39d7f2920b906db3711a3]",
- indexState(CONTENT_ID));
+ "[a.txt, mode:100644, content:content]" +
+ "[b.txt, mode:100644, content:content b]",
+ indexState(CONTENT));
}
public void testAddFolder() throws Exception {
Git git = new Git(db);
git.add().addFilepattern("sub").call();
assertEquals(
- "[sub/a.txt, mode:100644, sha1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea]" +
- "[sub/b.txt, mode:100644, sha1:50e9cdb03f9719261dd39d7f2920b906db3711a3]",
- indexState(CONTENT_ID));
+ "[sub/a.txt, mode:100644, content:content]" +
+ "[sub/b.txt, mode:100644, content:content b]",
+ indexState(CONTENT));
}
public void testAddIgnoredFile() throws Exception {
git.add().addFilepattern("sub").call();
assertEquals(
- "[sub/a.txt, mode:100644, sha1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea]",
- indexState(CONTENT_ID));
+ "[sub/a.txt, mode:100644, content:content]",
+ indexState(CONTENT));
}
public void testAddWholeRepo() throws Exception {
Git git = new Git(db);
git.add().addFilepattern(".").call();
assertEquals(
- "[sub/a.txt, mode:100644, sha1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea]" +
- "[sub/b.txt, mode:100644, sha1:50e9cdb03f9719261dd39d7f2920b906db3711a3]",
- indexState(CONTENT_ID));
+ "[sub/a.txt, mode:100644, content:content]" +
+ "[sub/b.txt, mode:100644, content:content b]",
+ indexState(CONTENT));
}
// the same three cases as in testAddWithParameterUpdate
git.add().addFilepattern("sub").call();
assertEquals(
- "[sub/a.txt, mode:100644, sha1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea]" +
- "[sub/b.txt, mode:100644, sha1:50e9cdb03f9719261dd39d7f2920b906db3711a3]",
- indexState(CONTENT_ID));
+ "[sub/a.txt, mode:100644, content:content]" +
+ "[sub/b.txt, mode:100644, content:content b]",
+ indexState(CONTENT));
git.commit().setMessage("commit").call();
// deletion of sub/b.txt is not staged
// sub/c.txt is staged
assertEquals(
- "[sub/a.txt, mode:100644, sha1:268af4e306cfcf6e79edd50fed9c553d211f68e3]" +
- "[sub/b.txt, mode:100644, sha1:50e9cdb03f9719261dd39d7f2920b906db3711a3]" +
- "[sub/c.txt, mode:100644, sha1:fa08654474ae2ddc4f61ee3a43d017ba65a439c3]",
- indexState(CONTENT_ID));
+ "[sub/a.txt, mode:100644, content:modified content]" +
+ "[sub/b.txt, mode:100644, content:content b]" +
+ "[sub/c.txt, mode:100644, content:content c]",
+ indexState(CONTENT));
}
// file a exists in workdir and in index -> added
git.add().addFilepattern("sub").call();
assertEquals(
- "[sub/a.txt, mode:100644, sha1:6b584e8ece562ebffc15d38808cd6b98fc3d97ea]" +
- "[sub/b.txt, mode:100644, sha1:50e9cdb03f9719261dd39d7f2920b906db3711a3]",
- indexState(CONTENT_ID));
+ "[sub/a.txt, mode:100644, content:content]" +
+ "[sub/b.txt, mode:100644, content:content b]",
+ indexState(CONTENT));
git.commit().setMessage("commit").call();
git.add().addFilepattern("sub").setUpdate(true).call();
// change in sub/a.txt is staged
assertEquals(
- "[sub/a.txt, mode:100644, sha1:268af4e306cfcf6e79edd50fed9c553d211f68e3]",
- indexState(CONTENT_ID));
+ "[sub/a.txt, mode:100644, content:modified content]",
+ indexState(CONTENT));
}
private DirCacheEntry addEntryToBuilder(String path, File file,
import org.eclipse.jgit.dircache.DirCache;
import org.eclipse.jgit.dircache.DirCacheBuilder;
import org.eclipse.jgit.dircache.DirCacheEntry;
-import org.eclipse.jgit.dircache.DirCacheIterator;
import org.eclipse.jgit.junit.LocalDiskRepositoryTestCase;
import org.eclipse.jgit.storage.file.FileRepository;
import org.eclipse.jgit.treewalk.FileTreeIterator;
-import org.eclipse.jgit.treewalk.NameConflictTreeWalk;
/**
* Base class for most JGit unit tests.
public static final int CONTENT_ID = 8;
+ public static final int CONTENT = 16;
+
/**
* Represent the state of the index in one String. This representation is
* useful when writing tests which do assertions on the state of the index.
* The format of the returned string is described with this BNF:
*
* <pre>
- * result = ( "[" path mode stage? time? smudge? length? sha1? "]" )* .
+ * result = ( "[" path mode stage? time? smudge? length? sha1? content? "]" )* .
* mode = ", mode:" number .
* stage = ", stage:" number .
* time = ", time:t" timestamp-index .
* smudge = "" | ", smudged" .
* length = ", length:" number .
* sha1 = ", sha1:" hex-sha1 .
+ * content = ", content:" blob-data .
+ * </pre>
*
* 'stage' is only presented when the stage is different from 0. All
* reported time stamps are mapped to strings like "t0", "t1", ... "tn". The
*
* @param includedOptions
* a bitmask constructed out of the constants {@link #MOD_TIME},
- * {@link #SMUDGE}, {@link #LENGTH} and {@link #CONTENT_ID}
+ * {@link #SMUDGE}, {@link #LENGTH}, {@link #CONTENT_ID} and {@link #CONTENT}
* controlling which info is present in the resulting string.
* @return a string encoding the index state
* @throws IllegalStateException
}
// iterate again, now produce the result string
- NameConflictTreeWalk tw = new NameConflictTreeWalk(db);
- tw.setRecursive(true);
- tw.reset();
- tw.addTree(new DirCacheIterator(dc));
- while (tw.next()) {
- DirCacheIterator dcIt = tw.getTree(0, DirCacheIterator.class);
- sb.append("["+tw.getPathString()+", mode:" + dcIt.getEntryFileMode());
- int stage = dcIt.getDirCacheEntry().getStage();
+ for (int i=0; i<dc.getEntryCount(); ++i) {
+ DirCacheEntry entry = dc.getEntry(i);
+ sb.append("["+entry.getPathString()+", mode:" + entry.getFileMode());
+ int stage = entry.getStage();
if (stage != 0)
sb.append(", stage:" + stage);
if (0 != (includedOptions & MOD_TIME)) {
sb.append(", time:t"+
- timeStamps.headSet(Long.valueOf(dcIt.getDirCacheEntry().getLastModified())).size());
+ timeStamps.headSet(Long.valueOf(entry.getLastModified())).size());
}
if (0 != (includedOptions & SMUDGE))
- if (dcIt.getDirCacheEntry().isSmudged())
+ if (entry.isSmudged())
sb.append(", smudged");
if (0 != (includedOptions & LENGTH))
sb.append(", length:"
- + Integer.toString(dcIt.getDirCacheEntry().getLength()));
+ + Integer.toString(entry.getLength()));
if (0 != (includedOptions & CONTENT_ID))
- sb.append(", sha1:" + ObjectId.toString(dcIt
- .getEntryObjectId()));
+ sb.append(", sha1:" + ObjectId.toString(entry.getObjectId()));
+ if (0 != (includedOptions & CONTENT)) {
+ sb.append(", content:"
+ + new String(db.open(entry.getObjectId(),
+ Constants.OBJ_BLOB).getCachedBytes(), "UTF-8"));
+ }
sb.append("]");
}
return sb.toString();