You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FileTreeIteratorTest.java 19KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542
  1. /*
  2. * Copyright (C) 2008, Google Inc.
  3. * and other copyright owners as documented in the project's IP log.
  4. *
  5. * This program and the accompanying materials are made available
  6. * under the terms of the Eclipse Distribution License v1.0 which
  7. * accompanies this distribution, is reproduced below, and is
  8. * available at http://www.eclipse.org/org/documents/edl-v10.php
  9. *
  10. * All rights reserved.
  11. *
  12. * Redistribution and use in source and binary forms, with or
  13. * without modification, are permitted provided that the following
  14. * conditions are met:
  15. *
  16. * - Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. *
  19. * - Redistributions in binary form must reproduce the above
  20. * copyright notice, this list of conditions and the following
  21. * disclaimer in the documentation and/or other materials provided
  22. * with the distribution.
  23. *
  24. * - Neither the name of the Eclipse Foundation, Inc. nor the
  25. * names of its contributors may be used to endorse or promote
  26. * products derived from this software without specific prior
  27. * written permission.
  28. *
  29. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  30. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  31. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  32. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  33. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  34. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  35. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  36. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  37. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  38. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  39. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  40. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  41. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  42. */
  43. package org.eclipse.jgit.treewalk;
  44. import static org.junit.Assert.assertEquals;
  45. import static org.junit.Assert.assertFalse;
  46. import static org.junit.Assert.assertNotNull;
  47. import static org.junit.Assert.assertTrue;
  48. import java.io.File;
  49. import java.io.IOException;
  50. import java.security.MessageDigest;
  51. import org.eclipse.jgit.api.Git;
  52. import org.eclipse.jgit.dircache.DirCache;
  53. import org.eclipse.jgit.dircache.DirCacheCheckout;
  54. import org.eclipse.jgit.dircache.DirCacheEditor;
  55. import org.eclipse.jgit.dircache.DirCacheEditor.PathEdit;
  56. import org.eclipse.jgit.dircache.DirCacheEntry;
  57. import org.eclipse.jgit.dircache.DirCacheIterator;
  58. import org.eclipse.jgit.errors.CorruptObjectException;
  59. import org.eclipse.jgit.errors.IncorrectObjectTypeException;
  60. import org.eclipse.jgit.errors.MissingObjectException;
  61. import org.eclipse.jgit.junit.RepositoryTestCase;
  62. import org.eclipse.jgit.lib.ConfigConstants;
  63. import org.eclipse.jgit.lib.Constants;
  64. import org.eclipse.jgit.lib.FileMode;
  65. import org.eclipse.jgit.lib.ObjectId;
  66. import org.eclipse.jgit.lib.ObjectReader;
  67. import org.eclipse.jgit.revwalk.RevCommit;
  68. import org.eclipse.jgit.treewalk.WorkingTreeIterator.MetadataDiff;
  69. import org.eclipse.jgit.treewalk.filter.PathFilter;
  70. import org.eclipse.jgit.util.FileUtils;
  71. import org.eclipse.jgit.util.RawParseUtils;
  72. import org.junit.Before;
  73. import org.junit.Test;
  74. public class FileTreeIteratorTest extends RepositoryTestCase {
  75. private final String[] paths = { "a,", "a,b", "a/b", "a0b" };
  76. private long[] mtime;
  77. @Before
  78. public void setUp() throws Exception {
  79. super.setUp();
  80. // We build the entries backwards so that on POSIX systems we
  81. // are likely to get the entries in the trash directory in the
  82. // opposite order of what they should be in for the iteration.
  83. // This should stress the sorting code better than doing it in
  84. // the correct order.
  85. //
  86. mtime = new long[paths.length];
  87. for (int i = paths.length - 1; i >= 0; i--) {
  88. final String s = paths[i];
  89. writeTrashFile(s, s);
  90. mtime[i] = new File(trash, s).lastModified();
  91. }
  92. }
  93. @Test
  94. public void testGetEntryContentLength() throws Exception {
  95. final FileTreeIterator fti = new FileTreeIterator(db);
  96. fti.next(1);
  97. assertEquals(3, fti.getEntryContentLength());
  98. fti.back(1);
  99. assertEquals(2, fti.getEntryContentLength());
  100. fti.next(1);
  101. assertEquals(3, fti.getEntryContentLength());
  102. fti.reset();
  103. assertEquals(2, fti.getEntryContentLength());
  104. }
  105. @Test
  106. public void testEmptyIfRootIsFile() throws Exception {
  107. final File r = new File(trash, paths[0]);
  108. assertTrue(r.isFile());
  109. final FileTreeIterator fti = new FileTreeIterator(r, db.getFS(),
  110. db.getConfig().get(WorkingTreeOptions.KEY));
  111. assertTrue(fti.first());
  112. assertTrue(fti.eof());
  113. }
  114. @Test
  115. public void testEmptyIfRootDoesNotExist() throws Exception {
  116. final File r = new File(trash, "not-existing-file");
  117. assertFalse(r.exists());
  118. final FileTreeIterator fti = new FileTreeIterator(r, db.getFS(),
  119. db.getConfig().get(WorkingTreeOptions.KEY));
  120. assertTrue(fti.first());
  121. assertTrue(fti.eof());
  122. }
  123. @Test
  124. public void testEmptyIfRootIsEmpty() throws Exception {
  125. final File r = new File(trash, "not-existing-file");
  126. assertFalse(r.exists());
  127. FileUtils.mkdir(r);
  128. final FileTreeIterator fti = new FileTreeIterator(r, db.getFS(),
  129. db.getConfig().get(WorkingTreeOptions.KEY));
  130. assertTrue(fti.first());
  131. assertTrue(fti.eof());
  132. }
  133. @Test
  134. public void testEmptyIteratorOnEmptyDirectory() throws Exception {
  135. String nonExistingFileName = "not-existing-file";
  136. final File r = new File(trash, nonExistingFileName);
  137. assertFalse(r.exists());
  138. FileUtils.mkdir(r);
  139. final FileTreeIterator parent = new FileTreeIterator(db);
  140. while (!parent.getEntryPathString().equals(nonExistingFileName))
  141. parent.next(1);
  142. final FileTreeIterator childIter = new FileTreeIterator(parent, r,
  143. db.getFS());
  144. assertTrue(childIter.first());
  145. assertTrue(childIter.eof());
  146. String parentPath = parent.getEntryPathString();
  147. assertEquals(nonExistingFileName, parentPath);
  148. // must be "not-existing-file/", but getEntryPathString() was broken by
  149. // 445363 too
  150. String childPath = childIter.getEntryPathString();
  151. // in bug 445363 the iterator wrote garbage to the parent "path" field
  152. EmptyTreeIterator e = childIter.createEmptyTreeIterator();
  153. assertNotNull(e);
  154. // check if parent path is not overridden by empty iterator (bug 445363)
  155. // due bug 445363 this was "/ot-existing-file" instead of
  156. // "not-existing-file"
  157. assertEquals(parentPath, parent.getEntryPathString());
  158. assertEquals(parentPath + "/", childPath);
  159. assertEquals(parentPath + "/", childIter.getEntryPathString());
  160. assertEquals(childPath + "/", e.getEntryPathString());
  161. }
  162. @Test
  163. public void testSimpleIterate() throws Exception {
  164. final FileTreeIterator top = new FileTreeIterator(trash, db.getFS(),
  165. db.getConfig().get(WorkingTreeOptions.KEY));
  166. assertTrue(top.first());
  167. assertFalse(top.eof());
  168. assertEquals(FileMode.REGULAR_FILE.getBits(), top.mode);
  169. assertEquals(paths[0], nameOf(top));
  170. assertEquals(paths[0].length(), top.getEntryLength());
  171. assertEquals(mtime[0], top.getEntryLastModified());
  172. top.next(1);
  173. assertFalse(top.first());
  174. assertFalse(top.eof());
  175. assertEquals(FileMode.REGULAR_FILE.getBits(), top.mode);
  176. assertEquals(paths[1], nameOf(top));
  177. assertEquals(paths[1].length(), top.getEntryLength());
  178. assertEquals(mtime[1], top.getEntryLastModified());
  179. top.next(1);
  180. assertFalse(top.first());
  181. assertFalse(top.eof());
  182. assertEquals(FileMode.TREE.getBits(), top.mode);
  183. final ObjectReader reader = db.newObjectReader();
  184. final AbstractTreeIterator sub = top.createSubtreeIterator(reader);
  185. assertTrue(sub instanceof FileTreeIterator);
  186. final FileTreeIterator subfti = (FileTreeIterator) sub;
  187. assertTrue(sub.first());
  188. assertFalse(sub.eof());
  189. assertEquals(paths[2], nameOf(sub));
  190. assertEquals(paths[2].length(), subfti.getEntryLength());
  191. assertEquals(mtime[2], subfti.getEntryLastModified());
  192. sub.next(1);
  193. assertTrue(sub.eof());
  194. top.next(1);
  195. assertFalse(top.first());
  196. assertFalse(top.eof());
  197. assertEquals(FileMode.REGULAR_FILE.getBits(), top.mode);
  198. assertEquals(paths[3], nameOf(top));
  199. assertEquals(paths[3].length(), top.getEntryLength());
  200. assertEquals(mtime[3], top.getEntryLastModified());
  201. top.next(1);
  202. assertTrue(top.eof());
  203. }
  204. @Test
  205. public void testComputeFileObjectId() throws Exception {
  206. final FileTreeIterator top = new FileTreeIterator(trash, db.getFS(),
  207. db.getConfig().get(WorkingTreeOptions.KEY));
  208. final MessageDigest md = Constants.newMessageDigest();
  209. md.update(Constants.encodeASCII(Constants.TYPE_BLOB));
  210. md.update((byte) ' ');
  211. md.update(Constants.encodeASCII(paths[0].length()));
  212. md.update((byte) 0);
  213. md.update(Constants.encode(paths[0]));
  214. final ObjectId expect = ObjectId.fromRaw(md.digest());
  215. assertEquals(expect, top.getEntryObjectId());
  216. // Verify it was cached by removing the file and getting it again.
  217. //
  218. FileUtils.delete(new File(trash, paths[0]));
  219. assertEquals(expect, top.getEntryObjectId());
  220. }
  221. @Test
  222. public void testDirCacheMatchingId() throws Exception {
  223. File f = writeTrashFile("file", "content");
  224. Git git = new Git(db);
  225. writeTrashFile("file", "content");
  226. fsTick(f);
  227. git.add().addFilepattern("file").call();
  228. DirCacheEntry dce = db.readDirCache().getEntry("file");
  229. TreeWalk tw = new TreeWalk(db);
  230. FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
  231. .getConfig().get(WorkingTreeOptions.KEY));
  232. tw.addTree(fti);
  233. DirCacheIterator dci = new DirCacheIterator(db.readDirCache());
  234. tw.addTree(dci);
  235. fti.setDirCacheIterator(tw, 1);
  236. while (tw.next() && !tw.getPathString().equals("file")) {
  237. //
  238. }
  239. assertEquals(MetadataDiff.EQUAL, fti.compareMetadata(dce));
  240. ObjectId fromRaw = ObjectId.fromRaw(fti.idBuffer(), fti.idOffset());
  241. assertEquals("6b584e8ece562ebffc15d38808cd6b98fc3d97ea",
  242. fromRaw.getName());
  243. ObjectReader objectReader = db.newObjectReader();
  244. assertFalse(fti.isModified(dce, false, objectReader));
  245. objectReader.release();
  246. }
  247. @Test
  248. public void testIsModifiedSymlinkAsFile() throws Exception {
  249. writeTrashFile("symlink", "content");
  250. Git git = new Git(db);
  251. db.getConfig().setString(ConfigConstants.CONFIG_CORE_SECTION, null,
  252. ConfigConstants.CONFIG_KEY_SYMLINKS, "false");
  253. git.add().addFilepattern("symlink").call();
  254. git.commit().setMessage("commit").call();
  255. // Modify previously committed DirCacheEntry and write it back to disk
  256. DirCacheEntry dce = db.readDirCache().getEntry("symlink");
  257. dce.setFileMode(FileMode.SYMLINK);
  258. ObjectReader objectReader = db.newObjectReader();
  259. DirCacheCheckout.checkoutEntry(db, dce, objectReader);
  260. FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
  261. .getConfig().get(WorkingTreeOptions.KEY));
  262. while (!fti.getEntryPathString().equals("symlink"))
  263. fti.next(1);
  264. assertFalse(fti.isModified(dce, false, objectReader));
  265. objectReader.release();
  266. }
  267. @Test
  268. public void testIsModifiedFileSmudged() throws Exception {
  269. File f = writeTrashFile("file", "content");
  270. Git git = new Git(db);
  271. // The idea of this test is to check the smudged handling
  272. // Hopefully fsTick will make sure our entry gets smudged
  273. fsTick(f);
  274. writeTrashFile("file", "content");
  275. long lastModified = f.lastModified();
  276. git.add().addFilepattern("file").call();
  277. writeTrashFile("file", "conten2");
  278. f.setLastModified(lastModified);
  279. // We cannot trust this to go fast enough on
  280. // a system with less than one-second lastModified
  281. // resolution, so we force the index to have the
  282. // same timestamp as the file we look at.
  283. db.getIndexFile().setLastModified(lastModified);
  284. DirCacheEntry dce = db.readDirCache().getEntry("file");
  285. FileTreeIterator fti = new FileTreeIterator(trash, db.getFS(), db
  286. .getConfig().get(WorkingTreeOptions.KEY));
  287. while (!fti.getEntryPathString().equals("file"))
  288. fti.next(1);
  289. // If the rounding trick does not work we could skip the compareMetaData
  290. // test and hope that we are usually testing the intended code path.
  291. assertEquals(MetadataDiff.SMUDGED, fti.compareMetadata(dce));
  292. ObjectReader objectReader = db.newObjectReader();
  293. assertTrue(fti.isModified(dce, false, objectReader));
  294. objectReader.release();
  295. }
  296. @Test
  297. public void submoduleHeadMatchesIndex() throws Exception {
  298. Git git = new Git(db);
  299. writeTrashFile("file.txt", "content");
  300. git.add().addFilepattern("file.txt").call();
  301. final RevCommit id = git.commit().setMessage("create file").call();
  302. final String path = "sub";
  303. DirCache cache = db.lockDirCache();
  304. DirCacheEditor editor = cache.editor();
  305. editor.add(new PathEdit(path) {
  306. public void apply(DirCacheEntry ent) {
  307. ent.setFileMode(FileMode.GITLINK);
  308. ent.setObjectId(id);
  309. }
  310. });
  311. editor.commit();
  312. Git.cloneRepository().setURI(db.getDirectory().toURI().toString())
  313. .setDirectory(new File(db.getWorkTree(), path)).call()
  314. .getRepository().close();
  315. TreeWalk walk = new TreeWalk(db);
  316. DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
  317. FileTreeIterator workTreeIter = new FileTreeIterator(db);
  318. walk.addTree(indexIter);
  319. walk.addTree(workTreeIter);
  320. walk.setFilter(PathFilter.create(path));
  321. assertTrue(walk.next());
  322. assertTrue(indexIter.idEqual(workTreeIter));
  323. }
  324. @Test
  325. public void submoduleWithNoGitDirectory() throws Exception {
  326. Git git = new Git(db);
  327. writeTrashFile("file.txt", "content");
  328. git.add().addFilepattern("file.txt").call();
  329. final RevCommit id = git.commit().setMessage("create file").call();
  330. final String path = "sub";
  331. DirCache cache = db.lockDirCache();
  332. DirCacheEditor editor = cache.editor();
  333. editor.add(new PathEdit(path) {
  334. public void apply(DirCacheEntry ent) {
  335. ent.setFileMode(FileMode.GITLINK);
  336. ent.setObjectId(id);
  337. }
  338. });
  339. editor.commit();
  340. File submoduleRoot = new File(db.getWorkTree(), path);
  341. assertTrue(submoduleRoot.mkdir());
  342. assertTrue(new File(submoduleRoot, Constants.DOT_GIT).mkdir());
  343. TreeWalk walk = new TreeWalk(db);
  344. DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
  345. FileTreeIterator workTreeIter = new FileTreeIterator(db);
  346. walk.addTree(indexIter);
  347. walk.addTree(workTreeIter);
  348. walk.setFilter(PathFilter.create(path));
  349. assertTrue(walk.next());
  350. assertFalse(indexIter.idEqual(workTreeIter));
  351. assertEquals(ObjectId.zeroId(), workTreeIter.getEntryObjectId());
  352. }
  353. @Test
  354. public void submoduleWithNoHead() throws Exception {
  355. Git git = new Git(db);
  356. writeTrashFile("file.txt", "content");
  357. git.add().addFilepattern("file.txt").call();
  358. final RevCommit id = git.commit().setMessage("create file").call();
  359. final String path = "sub";
  360. DirCache cache = db.lockDirCache();
  361. DirCacheEditor editor = cache.editor();
  362. editor.add(new PathEdit(path) {
  363. public void apply(DirCacheEntry ent) {
  364. ent.setFileMode(FileMode.GITLINK);
  365. ent.setObjectId(id);
  366. }
  367. });
  368. editor.commit();
  369. assertNotNull(Git.init().setDirectory(new File(db.getWorkTree(), path))
  370. .call().getRepository());
  371. TreeWalk walk = new TreeWalk(db);
  372. DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
  373. FileTreeIterator workTreeIter = new FileTreeIterator(db);
  374. walk.addTree(indexIter);
  375. walk.addTree(workTreeIter);
  376. walk.setFilter(PathFilter.create(path));
  377. assertTrue(walk.next());
  378. assertFalse(indexIter.idEqual(workTreeIter));
  379. assertEquals(ObjectId.zeroId(), workTreeIter.getEntryObjectId());
  380. }
  381. @Test
  382. public void submoduleDirectoryIterator() throws Exception {
  383. Git git = new Git(db);
  384. writeTrashFile("file.txt", "content");
  385. git.add().addFilepattern("file.txt").call();
  386. final RevCommit id = git.commit().setMessage("create file").call();
  387. final String path = "sub";
  388. DirCache cache = db.lockDirCache();
  389. DirCacheEditor editor = cache.editor();
  390. editor.add(new PathEdit(path) {
  391. public void apply(DirCacheEntry ent) {
  392. ent.setFileMode(FileMode.GITLINK);
  393. ent.setObjectId(id);
  394. }
  395. });
  396. editor.commit();
  397. Git.cloneRepository().setURI(db.getDirectory().toURI().toString())
  398. .setDirectory(new File(db.getWorkTree(), path)).call()
  399. .getRepository().close();
  400. TreeWalk walk = new TreeWalk(db);
  401. DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
  402. FileTreeIterator workTreeIter = new FileTreeIterator(db.getWorkTree(),
  403. db.getFS(), db.getConfig().get(WorkingTreeOptions.KEY));
  404. walk.addTree(indexIter);
  405. walk.addTree(workTreeIter);
  406. walk.setFilter(PathFilter.create(path));
  407. assertTrue(walk.next());
  408. assertTrue(indexIter.idEqual(workTreeIter));
  409. }
  410. @Test
  411. public void submoduleNestedWithHeadMatchingIndex() throws Exception {
  412. Git git = new Git(db);
  413. writeTrashFile("file.txt", "content");
  414. git.add().addFilepattern("file.txt").call();
  415. final RevCommit id = git.commit().setMessage("create file").call();
  416. final String path = "sub/dir1/dir2";
  417. DirCache cache = db.lockDirCache();
  418. DirCacheEditor editor = cache.editor();
  419. editor.add(new PathEdit(path) {
  420. public void apply(DirCacheEntry ent) {
  421. ent.setFileMode(FileMode.GITLINK);
  422. ent.setObjectId(id);
  423. }
  424. });
  425. editor.commit();
  426. Git.cloneRepository().setURI(db.getDirectory().toURI().toString())
  427. .setDirectory(new File(db.getWorkTree(), path)).call()
  428. .getRepository().close();
  429. TreeWalk walk = new TreeWalk(db);
  430. DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
  431. FileTreeIterator workTreeIter = new FileTreeIterator(db);
  432. walk.addTree(indexIter);
  433. walk.addTree(workTreeIter);
  434. walk.setFilter(PathFilter.create(path));
  435. assertTrue(walk.next());
  436. assertTrue(indexIter.idEqual(workTreeIter));
  437. }
  438. @Test
  439. public void idOffset() throws Exception {
  440. Git git = new Git(db);
  441. writeTrashFile("fileAinfsonly", "A");
  442. File fileBinindex = writeTrashFile("fileBinindex", "B");
  443. fsTick(fileBinindex);
  444. git.add().addFilepattern("fileBinindex").call();
  445. writeTrashFile("fileCinfsonly", "C");
  446. TreeWalk tw = new TreeWalk(db);
  447. DirCacheIterator indexIter = new DirCacheIterator(db.readDirCache());
  448. FileTreeIterator workTreeIter = new FileTreeIterator(db);
  449. tw.addTree(indexIter);
  450. tw.addTree(workTreeIter);
  451. workTreeIter.setDirCacheIterator(tw, 0);
  452. assertEntry("d46c305e85b630558ee19cc47e73d2e5c8c64cdc", "a,", tw);
  453. assertEntry("58ee403f98538ec02409538b3f80adf610accdec", "a,b", tw);
  454. assertEntry("0000000000000000000000000000000000000000", "a", tw);
  455. assertEntry("b8d30ff397626f0f1d3538d66067edf865e201d6", "a0b", tw);
  456. // The reason for adding this test. Check that the id is correct for
  457. // mixed
  458. assertEntry("8c7e5a667f1b771847fe88c01c3de34413a1b220",
  459. "fileAinfsonly", tw);
  460. assertEntry("7371f47a6f8bd23a8fa1a8b2a9479cdd76380e54", "fileBinindex",
  461. tw);
  462. assertEntry("96d80cd6c4e7158dbebd0849f4fb7ce513e5828c",
  463. "fileCinfsonly", tw);
  464. assertFalse(tw.next());
  465. }
  466. private static void assertEntry(String sha1string, String path, TreeWalk tw)
  467. throws MissingObjectException, IncorrectObjectTypeException,
  468. CorruptObjectException, IOException {
  469. assertTrue(tw.next());
  470. assertEquals(path, tw.getPathString());
  471. assertEquals(sha1string, tw.getObjectId(1).getName() /* 1=filetree here */);
  472. }
  473. private static String nameOf(final AbstractTreeIterator i) {
  474. return RawParseUtils.decode(Constants.CHARSET, i.path, 0, i.pathLen);
  475. }
  476. }