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.

CommitOnlyTest.java 34KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309
  1. /*
  2. * Copyright (C) 2011, Christian Halstrick <christian.halstrick@sap.com>
  3. * Copyright (C) 2011, Philipp Thun <philipp.thun@sap.com>
  4. * and other copyright owners as documented in the project's IP log.
  5. *
  6. * This program and the accompanying materials are made available
  7. * under the terms of the Eclipse Distribution License v1.0 which
  8. * accompanies this distribution, is reproduced below, and is
  9. * available at http://www.eclipse.org/org/documents/edl-v10.php
  10. *
  11. * All rights reserved.
  12. *
  13. * Redistribution and use in source and binary forms, with or
  14. * without modification, are permitted provided that the following
  15. * conditions are met:
  16. *
  17. * - Redistributions of source code must retain the above copyright
  18. * notice, this list of conditions and the following disclaimer.
  19. *
  20. * - Redistributions in binary form must reproduce the above
  21. * copyright notice, this list of conditions and the following
  22. * disclaimer in the documentation and/or other materials provided
  23. * with the distribution.
  24. *
  25. * - Neither the name of the Eclipse Foundation, Inc. nor the
  26. * names of its contributors may be used to endorse or promote
  27. * products derived from this software without specific prior
  28. * written permission.
  29. *
  30. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
  31. * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
  32. * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  33. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  34. * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
  35. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38. * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  39. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40. * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41. * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
  42. * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  43. */
  44. package org.eclipse.jgit.api;
  45. import static org.junit.Assert.assertEquals;
  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 org.eclipse.jgit.api.errors.JGitInternalException;
  51. import org.eclipse.jgit.lib.Constants;
  52. import org.eclipse.jgit.lib.ObjectId;
  53. import org.eclipse.jgit.lib.Repository;
  54. import org.eclipse.jgit.lib.RepositoryTestCase;
  55. import org.eclipse.jgit.revwalk.RevWalk;
  56. import org.eclipse.jgit.treewalk.TreeWalk;
  57. import org.junit.Test;
  58. /**
  59. * Testing the 'commit only' option:
  60. *
  61. * I. A single file (f1.txt) specified as part of the --only/ -o option can have
  62. * one of the following (14) states:
  63. *
  64. * <pre>
  65. * | | expected result
  66. * ---------------------------------------------------------------------
  67. * | HEAD DirCache Worktree | HEAD DirCache
  68. * ---------------------------------------------------------------------
  69. * f1_1 | - - c | => e: path unknown
  70. * f1_2 | - c - | => no changes
  71. * f1_3 | c - - | - -
  72. * f1_4 | - c c | c c
  73. * f1_5 | c c - | - -
  74. * f1_6 | c - c | => no changes
  75. * f1_7 | c c c | => no changes
  76. * ---------------------------------------------------------------------
  77. * f1_8 | - c c' | c' c'
  78. * f1_9 | c - c' | c' c'
  79. * f1_10 | c c' - | - -
  80. * f1_11 | c c c' | c' c'
  81. * f1_12 | c c' c | => no changes
  82. * f1_13 | c c' c' | c' c'
  83. * ---------------------------------------------------------------------
  84. * f1_14 | c c' c'' | c'' c''
  85. * </pre>
  86. *
  87. * II. Scenarios that do not end with a successful commit (1, 2, 6, 7, 12) have
  88. * to be tested with a second file (f2.txt) specified that would lead to a
  89. * successful commit, if it were executed separately (e.g. scenario 14).
  90. *
  91. * <pre>
  92. * | | expected result
  93. * ---------------------------------------------------------------------------
  94. * | HEAD DirCache Worktree | HEAD DirCache
  95. * ---------------------------------------------------------------------------
  96. * f1_1_f2_14 | - - c | => e: path unknown
  97. * f1_2_f2_14 | - c - | - -
  98. * f1_6_f2_14 | c - c | c c
  99. * f1_7_f2_14 | c c c | c c
  100. * ---------------------------------------------------------------------------
  101. * f1_12_f2_14 | c c' c | c c
  102. * </pre>
  103. *
  104. * III. All scenarios (1-14, I-II) have to be tested with different repository
  105. * states, to check that the --only/ -o option does not change existing content
  106. * (HEAD and DirCache). The following states for a file (f3.txt) not specified
  107. * shall be tested:
  108. *
  109. * <pre>
  110. * | HEAD DirCache
  111. * --------------------
  112. * *_a | - -
  113. * *_b | - c
  114. * *_c | c c
  115. * *_d | c -
  116. * --------------------
  117. * *_e | c c'
  118. * </pre>
  119. **/
  120. public class CommitOnlyTest extends RepositoryTestCase {
  121. private static final String F1 = "f1.txt";
  122. private static final String F2 = "f2.txt";
  123. private static final String F3 = "f3.txt";
  124. private static final String MSG = "commit";
  125. private static int A = 0;
  126. private static int B = 1;
  127. private static int C = 2;
  128. private static int D = 3;
  129. private static int E = 4;
  130. @Test
  131. public void testOnlyOption_f1_1_a() throws Exception {
  132. final Git git = new Git(db);
  133. prepare_f3(git, A);
  134. prepare_f1_1(git);
  135. executeAndCheck_f1_1(git, A);
  136. }
  137. @Test
  138. public void testOnlyOption_f1_1_b() throws Exception {
  139. final Git git = new Git(db);
  140. prepare_f3(git, B);
  141. prepare_f1_1(git);
  142. executeAndCheck_f1_1(git, B);
  143. }
  144. @Test
  145. public void testOnlyOption_f1_1_c() throws Exception {
  146. final Git git = new Git(db);
  147. prepare_f3(git, C);
  148. prepare_f1_1(git);
  149. executeAndCheck_f1_1(git, C);
  150. }
  151. @Test
  152. public void testOnlyOption_f1_1_d() throws Exception {
  153. final Git git = new Git(db);
  154. prepare_f3(git, D);
  155. prepare_f1_1(git);
  156. executeAndCheck_f1_1(git, D);
  157. }
  158. @Test
  159. public void testOnlyOption_f1_1_e() throws Exception {
  160. final Git git = new Git(db);
  161. prepare_f3(git, E);
  162. prepare_f1_1(git);
  163. executeAndCheck_f1_1(git, E);
  164. }
  165. @Test
  166. public void testOnlyOption_f1_1_f2_14_a() throws Exception {
  167. final Git git = new Git(db);
  168. prepare_f3_f2_14(git, A);
  169. prepare_f1_1(git);
  170. executeAndCheck_f1_1_f2_f14(git, A);
  171. }
  172. @Test
  173. public void testOnlyOption_f1_1_f2_14_b() throws Exception {
  174. final Git git = new Git(db);
  175. prepare_f3_f2_14(git, B);
  176. prepare_f1_1(git);
  177. executeAndCheck_f1_1_f2_f14(git, B);
  178. }
  179. @Test
  180. public void testOnlyOption_f1_1_f2_14_c() throws Exception {
  181. final Git git = new Git(db);
  182. prepare_f3_f2_14(git, C);
  183. prepare_f1_1(git);
  184. executeAndCheck_f1_1_f2_f14(git, C);
  185. }
  186. @Test
  187. public void testOnlyOption_f1_1_f2_14_d() throws Exception {
  188. final Git git = new Git(db);
  189. prepare_f3_f2_14(git, D);
  190. prepare_f1_1(git);
  191. executeAndCheck_f1_1_f2_f14(git, D);
  192. }
  193. @Test
  194. public void testOnlyOption_f1_1_f2_14_e() throws Exception {
  195. final Git git = new Git(db);
  196. prepare_f3_f2_14(git, E);
  197. prepare_f1_1(git);
  198. executeAndCheck_f1_1_f2_f14(git, E);
  199. }
  200. @Test
  201. public void testOnlyOption_f1_2_a() throws Exception {
  202. final Git git = new Git(db);
  203. prepare_f3(git, A);
  204. prepare_f1_2(git);
  205. executeAndCheck_f1_2(git, A);
  206. }
  207. @Test
  208. public void testOnlyOption_f1_2_b() throws Exception {
  209. final Git git = new Git(db);
  210. prepare_f3(git, B);
  211. prepare_f1_2(git);
  212. executeAndCheck_f1_2(git, B);
  213. }
  214. @Test
  215. public void testOnlyOption_f1_2_c() throws Exception {
  216. final Git git = new Git(db);
  217. prepare_f3(git, C);
  218. prepare_f1_2(git);
  219. executeAndCheck_f1_2(git, C);
  220. }
  221. @Test
  222. public void testOnlyOption_f1_2_d() throws Exception {
  223. final Git git = new Git(db);
  224. prepare_f3(git, D);
  225. prepare_f1_2(git);
  226. executeAndCheck_f1_2(git, D);
  227. }
  228. @Test
  229. public void testOnlyOption_f1_2_e() throws Exception {
  230. final Git git = new Git(db);
  231. prepare_f3(git, E);
  232. prepare_f1_2(git);
  233. executeAndCheck_f1_2(git, E);
  234. }
  235. @Test
  236. public void testOnlyOption_f1_2_f2_14_a() throws Exception {
  237. final Git git = new Git(db);
  238. prepare_f3_f2_14(git, A);
  239. prepare_f1_2(git);
  240. executeAndCheck_f1_2_f2_f14(git, A);
  241. }
  242. @Test
  243. public void testOnlyOption_f1_2_f2_14_b() throws Exception {
  244. final Git git = new Git(db);
  245. prepare_f3_f2_14(git, B);
  246. prepare_f1_2(git);
  247. executeAndCheck_f1_2_f2_f14(git, B);
  248. }
  249. @Test
  250. public void testOnlyOption_f1_2_f2_14_c() throws Exception {
  251. final Git git = new Git(db);
  252. prepare_f3_f2_14(git, C);
  253. prepare_f1_2(git);
  254. executeAndCheck_f1_2_f2_f14(git, C);
  255. }
  256. @Test
  257. public void testOnlyOption_f1_2_f2_14_d() throws Exception {
  258. final Git git = new Git(db);
  259. prepare_f3_f2_14(git, D);
  260. prepare_f1_2(git);
  261. executeAndCheck_f1_2_f2_f14(git, D);
  262. }
  263. @Test
  264. public void testOnlyOption_f1_2_f2_14_e() throws Exception {
  265. final Git git = new Git(db);
  266. prepare_f3_f2_14(git, E);
  267. prepare_f1_2(git);
  268. executeAndCheck_f1_2_f2_f14(git, E);
  269. }
  270. @Test
  271. public void testOnlyOption_f1_3_a() throws Exception {
  272. final Git git = new Git(db);
  273. prepare_f3(git, A);
  274. prepare_f1_3(git);
  275. executeAndCheck_f1_3(git, A);
  276. }
  277. @Test
  278. public void testOnlyOption_f1_3_b() throws Exception {
  279. final Git git = new Git(db);
  280. prepare_f3(git, B);
  281. prepare_f1_3(git);
  282. executeAndCheck_f1_3(git, B);
  283. }
  284. @Test
  285. public void testOnlyOption_f1_3_c() throws Exception {
  286. final Git git = new Git(db);
  287. prepare_f3(git, C);
  288. prepare_f1_3(git);
  289. executeAndCheck_f1_3(git, C);
  290. }
  291. @Test
  292. public void testOnlyOption_f1_3_d() throws Exception {
  293. final Git git = new Git(db);
  294. prepare_f3(git, D);
  295. prepare_f1_3(git);
  296. executeAndCheck_f1_3(git, D);
  297. }
  298. @Test
  299. public void testOnlyOption_f1_3_e() throws Exception {
  300. final Git git = new Git(db);
  301. prepare_f3(git, E);
  302. prepare_f1_3(git);
  303. executeAndCheck_f1_3(git, E);
  304. }
  305. @Test
  306. public void testOnlyOption_f1_4_a() throws Exception {
  307. final Git git = new Git(db);
  308. prepare_f3(git, A);
  309. prepare_f1_4(git);
  310. executeAndCheck_f1_4(git, A);
  311. }
  312. @Test
  313. public void testOnlyOption_f1_4_b() throws Exception {
  314. final Git git = new Git(db);
  315. prepare_f3(git, B);
  316. prepare_f1_4(git);
  317. executeAndCheck_f1_4(git, B);
  318. }
  319. @Test
  320. public void testOnlyOption_f1_4_c() throws Exception {
  321. final Git git = new Git(db);
  322. prepare_f3(git, C);
  323. prepare_f1_4(git);
  324. executeAndCheck_f1_4(git, C);
  325. }
  326. @Test
  327. public void testOnlyOption_f1_4_d() throws Exception {
  328. final Git git = new Git(db);
  329. prepare_f3(git, D);
  330. prepare_f1_4(git);
  331. executeAndCheck_f1_4(git, D);
  332. }
  333. @Test
  334. public void testOnlyOption_f1_4_e() throws Exception {
  335. final Git git = new Git(db);
  336. prepare_f3(git, E);
  337. prepare_f1_4(git);
  338. executeAndCheck_f1_4(git, E);
  339. }
  340. @Test
  341. public void testOnlyOption_f1_5_a() throws Exception {
  342. final Git git = new Git(db);
  343. prepare_f3(git, A);
  344. prepare_f1_5(git);
  345. executeAndCheck_f1_5(git, A);
  346. }
  347. @Test
  348. public void testOnlyOption_f1_5_b() throws Exception {
  349. final Git git = new Git(db);
  350. prepare_f3(git, B);
  351. prepare_f1_5(git);
  352. executeAndCheck_f1_5(git, B);
  353. }
  354. @Test
  355. public void testOnlyOption_f1_5_c() throws Exception {
  356. final Git git = new Git(db);
  357. prepare_f3(git, C);
  358. prepare_f1_5(git);
  359. executeAndCheck_f1_5(git, C);
  360. }
  361. @Test
  362. public void testOnlyOption_f1_5_d() throws Exception {
  363. final Git git = new Git(db);
  364. prepare_f3(git, D);
  365. prepare_f1_5(git);
  366. executeAndCheck_f1_5(git, D);
  367. }
  368. @Test
  369. public void testOnlyOption_f1_5_e() throws Exception {
  370. final Git git = new Git(db);
  371. prepare_f3(git, E);
  372. prepare_f1_5(git);
  373. executeAndCheck_f1_5(git, E);
  374. }
  375. @Test
  376. public void testOnlyOption_f1_6_a() throws Exception {
  377. final Git git = new Git(db);
  378. prepare_f3(git, A);
  379. prepare_f1_6(git);
  380. executeAndCheck_f1_6(git, A);
  381. }
  382. @Test
  383. public void testOnlyOption_f1_6_b() throws Exception {
  384. final Git git = new Git(db);
  385. prepare_f3(git, B);
  386. prepare_f1_6(git);
  387. executeAndCheck_f1_6(git, B);
  388. }
  389. @Test
  390. public void testOnlyOption_f1_6_c() throws Exception {
  391. final Git git = new Git(db);
  392. prepare_f3(git, C);
  393. prepare_f1_6(git);
  394. executeAndCheck_f1_6(git, C);
  395. }
  396. @Test
  397. public void testOnlyOption_f1_6_d() throws Exception {
  398. final Git git = new Git(db);
  399. prepare_f3(git, D);
  400. prepare_f1_6(git);
  401. executeAndCheck_f1_6(git, D);
  402. }
  403. @Test
  404. public void testOnlyOption_f1_6_e() throws Exception {
  405. final Git git = new Git(db);
  406. prepare_f3(git, E);
  407. prepare_f1_6(git);
  408. executeAndCheck_f1_6(git, E);
  409. }
  410. @Test
  411. public void testOnlyOption_f1_6_f2_14_a() throws Exception {
  412. final Git git = new Git(db);
  413. prepare_f3_f2_14(git, A);
  414. prepare_f1_6(git);
  415. executeAndCheck_f1_6_f2_14(git, A);
  416. }
  417. @Test
  418. public void testOnlyOption_f1_6_f2_14_b() throws Exception {
  419. final Git git = new Git(db);
  420. prepare_f3_f2_14(git, B);
  421. prepare_f1_6(git);
  422. executeAndCheck_f1_6_f2_14(git, B);
  423. }
  424. @Test
  425. public void testOnlyOption_f1_6_f2_14_c() throws Exception {
  426. final Git git = new Git(db);
  427. prepare_f3_f2_14(git, C);
  428. prepare_f1_6(git);
  429. executeAndCheck_f1_6_f2_14(git, C);
  430. }
  431. @Test
  432. public void testOnlyOption_f1_6_f2_14_d() throws Exception {
  433. final Git git = new Git(db);
  434. prepare_f3_f2_14(git, D);
  435. prepare_f1_6(git);
  436. executeAndCheck_f1_6_f2_14(git, D);
  437. }
  438. @Test
  439. public void testOnlyOption_f1_6_f2_14_e() throws Exception {
  440. final Git git = new Git(db);
  441. prepare_f3_f2_14(git, E);
  442. prepare_f1_6(git);
  443. executeAndCheck_f1_6_f2_14(git, E);
  444. }
  445. @Test
  446. public void testOnlyOption_f1_7_a() throws Exception {
  447. final Git git = new Git(db);
  448. prepare_f3(git, A);
  449. prepare_f1_7(git);
  450. executeAndCheck_f1_7(git, A);
  451. }
  452. @Test
  453. public void testOnlyOption_f1_7_b() throws Exception {
  454. final Git git = new Git(db);
  455. prepare_f3(git, B);
  456. prepare_f1_7(git);
  457. executeAndCheck_f1_7(git, B);
  458. }
  459. @Test
  460. public void testOnlyOption_f1_7_c() throws Exception {
  461. final Git git = new Git(db);
  462. prepare_f3(git, C);
  463. prepare_f1_7(git);
  464. executeAndCheck_f1_7(git, C);
  465. }
  466. @Test
  467. public void testOnlyOption_f1_7_d() throws Exception {
  468. final Git git = new Git(db);
  469. prepare_f3(git, D);
  470. prepare_f1_7(git);
  471. executeAndCheck_f1_7(git, D);
  472. }
  473. @Test
  474. public void testOnlyOption_f1_7_e() throws Exception {
  475. final Git git = new Git(db);
  476. prepare_f3(git, E);
  477. prepare_f1_7(git);
  478. executeAndCheck_f1_7(git, E);
  479. }
  480. @Test
  481. public void testOnlyOption_f1_7_f2_14_a() throws Exception {
  482. final Git git = new Git(db);
  483. prepare_f3_f2_14(git, A);
  484. prepare_f1_7(git);
  485. executeAndCheck_f1_7_f2_14(git, A);
  486. }
  487. @Test
  488. public void testOnlyOption_f1_7_f2_14_b() throws Exception {
  489. final Git git = new Git(db);
  490. prepare_f3_f2_14(git, B);
  491. prepare_f1_7(git);
  492. executeAndCheck_f1_7_f2_14(git, B);
  493. }
  494. @Test
  495. public void testOnlyOption_f1_7_f2_14_c() throws Exception {
  496. final Git git = new Git(db);
  497. prepare_f3_f2_14(git, C);
  498. prepare_f1_7(git);
  499. executeAndCheck_f1_7_f2_14(git, C);
  500. }
  501. @Test
  502. public void testOnlyOption_f1_7_f2_14_d() throws Exception {
  503. final Git git = new Git(db);
  504. prepare_f3_f2_14(git, D);
  505. prepare_f1_7(git);
  506. executeAndCheck_f1_7_f2_14(git, D);
  507. }
  508. @Test
  509. public void testOnlyOption_f1_7_f2_14_e() throws Exception {
  510. final Git git = new Git(db);
  511. prepare_f3_f2_14(git, E);
  512. prepare_f1_7(git);
  513. executeAndCheck_f1_7_f2_14(git, E);
  514. }
  515. @Test
  516. public void testOnlyOption_f1_8_a() throws Exception {
  517. final Git git = new Git(db);
  518. prepare_f3(git, A);
  519. prepare_f1_8(git);
  520. executeAndCheck_f1_8(git, A);
  521. }
  522. @Test
  523. public void testOnlyOption_f1_8_b() throws Exception {
  524. final Git git = new Git(db);
  525. prepare_f3(git, B);
  526. prepare_f1_8(git);
  527. executeAndCheck_f1_8(git, B);
  528. }
  529. @Test
  530. public void testOnlyOption_f1_8_c() throws Exception {
  531. final Git git = new Git(db);
  532. prepare_f3(git, C);
  533. prepare_f1_8(git);
  534. executeAndCheck_f1_8(git, C);
  535. }
  536. @Test
  537. public void testOnlyOption_f1_8_d() throws Exception {
  538. final Git git = new Git(db);
  539. prepare_f3(git, D);
  540. prepare_f1_8(git);
  541. executeAndCheck_f1_8(git, D);
  542. }
  543. @Test
  544. public void testOnlyOption_f1_8_e() throws Exception {
  545. final Git git = new Git(db);
  546. prepare_f3(git, E);
  547. prepare_f1_8(git);
  548. executeAndCheck_f1_8(git, E);
  549. }
  550. @Test
  551. public void testOnlyOption_f1_9_a() throws Exception {
  552. final Git git = new Git(db);
  553. prepare_f3(git, A);
  554. prepare_f1_9(git);
  555. executeAndCheck_f1_9(git, A);
  556. }
  557. @Test
  558. public void testOnlyOption_f1_9_b() throws Exception {
  559. final Git git = new Git(db);
  560. prepare_f3(git, B);
  561. prepare_f1_9(git);
  562. executeAndCheck_f1_9(git, B);
  563. }
  564. @Test
  565. public void testOnlyOption_f1_9_c() throws Exception {
  566. final Git git = new Git(db);
  567. prepare_f3(git, C);
  568. prepare_f1_9(git);
  569. executeAndCheck_f1_9(git, C);
  570. }
  571. @Test
  572. public void testOnlyOption_f1_9_d() throws Exception {
  573. final Git git = new Git(db);
  574. prepare_f3(git, D);
  575. prepare_f1_9(git);
  576. executeAndCheck_f1_9(git, D);
  577. }
  578. @Test
  579. public void testOnlyOption_f1_9_e() throws Exception {
  580. final Git git = new Git(db);
  581. prepare_f3(git, E);
  582. prepare_f1_9(git);
  583. executeAndCheck_f1_9(git, E);
  584. }
  585. @Test
  586. public void testOnlyOption_f1_10_a() throws Exception {
  587. final Git git = new Git(db);
  588. prepare_f3(git, A);
  589. prepare_f1_10(git);
  590. executeAndCheck_f1_10(git, A);
  591. }
  592. @Test
  593. public void testOnlyOption_f1_10_b() throws Exception {
  594. final Git git = new Git(db);
  595. prepare_f3(git, B);
  596. prepare_f1_10(git);
  597. executeAndCheck_f1_10(git, B);
  598. }
  599. @Test
  600. public void testOnlyOption_f1_10_c() throws Exception {
  601. final Git git = new Git(db);
  602. prepare_f3(git, C);
  603. prepare_f1_10(git);
  604. executeAndCheck_f1_10(git, C);
  605. }
  606. @Test
  607. public void testOnlyOption_f1_10_d() throws Exception {
  608. final Git git = new Git(db);
  609. prepare_f3(git, D);
  610. prepare_f1_10(git);
  611. executeAndCheck_f1_10(git, D);
  612. }
  613. @Test
  614. public void testOnlyOption_f1_10_e() throws Exception {
  615. final Git git = new Git(db);
  616. prepare_f3(git, E);
  617. prepare_f1_10(git);
  618. executeAndCheck_f1_10(git, E);
  619. }
  620. @Test
  621. public void testOnlyOption_f1_11_a() throws Exception {
  622. final Git git = new Git(db);
  623. prepare_f3(git, A);
  624. prepare_f1_11(git);
  625. executeAndCheck_f1_11(git, A);
  626. }
  627. @Test
  628. public void testOnlyOption_f1_11_b() throws Exception {
  629. final Git git = new Git(db);
  630. prepare_f3(git, B);
  631. prepare_f1_11(git);
  632. executeAndCheck_f1_11(git, B);
  633. }
  634. @Test
  635. public void testOnlyOption_f1_11_c() throws Exception {
  636. final Git git = new Git(db);
  637. prepare_f3(git, C);
  638. prepare_f1_11(git);
  639. executeAndCheck_f1_11(git, C);
  640. }
  641. @Test
  642. public void testOnlyOption_f1_11_d() throws Exception {
  643. final Git git = new Git(db);
  644. prepare_f3(git, D);
  645. prepare_f1_11(git);
  646. executeAndCheck_f1_11(git, D);
  647. }
  648. @Test
  649. public void testOnlyOption_f1_11_e() throws Exception {
  650. final Git git = new Git(db);
  651. prepare_f3(git, E);
  652. prepare_f1_11(git);
  653. executeAndCheck_f1_11(git, E);
  654. }
  655. @Test
  656. public void testOnlyOption_f1_12_a() throws Exception {
  657. final Git git = new Git(db);
  658. prepare_f3(git, A);
  659. prepare_f1_12(git);
  660. executeAndCheck_f1_12(git, A);
  661. }
  662. @Test
  663. public void testOnlyOption_f1_12_b() throws Exception {
  664. final Git git = new Git(db);
  665. prepare_f3(git, B);
  666. prepare_f1_12(git);
  667. executeAndCheck_f1_12(git, B);
  668. }
  669. @Test
  670. public void testOnlyOption_f1_12_c() throws Exception {
  671. final Git git = new Git(db);
  672. prepare_f3(git, C);
  673. prepare_f1_12(git);
  674. executeAndCheck_f1_12(git, C);
  675. }
  676. @Test
  677. public void testOnlyOption_f1_12_d() throws Exception {
  678. final Git git = new Git(db);
  679. prepare_f3(git, D);
  680. prepare_f1_12(git);
  681. executeAndCheck_f1_12(git, D);
  682. }
  683. @Test
  684. public void testOnlyOption_f1_12_e() throws Exception {
  685. final Git git = new Git(db);
  686. prepare_f3(git, E);
  687. prepare_f1_12(git);
  688. executeAndCheck_f1_12(git, E);
  689. }
  690. @Test
  691. public void testOnlyOption_f1_12_f2_14_a() throws Exception {
  692. final Git git = new Git(db);
  693. prepare_f3_f2_14(git, A);
  694. prepare_f1_12(git);
  695. executeAndCheck_f1_12_f2_14(git, A);
  696. }
  697. @Test
  698. public void testOnlyOption_f1_12_f2_14_b() throws Exception {
  699. final Git git = new Git(db);
  700. prepare_f3_f2_14(git, B);
  701. prepare_f1_12(git);
  702. executeAndCheck_f1_12_f2_14(git, B);
  703. }
  704. @Test
  705. public void testOnlyOption_f1_12_f2_14_c() throws Exception {
  706. final Git git = new Git(db);
  707. prepare_f3_f2_14(git, C);
  708. prepare_f1_12(git);
  709. executeAndCheck_f1_12_f2_14(git, C);
  710. }
  711. @Test
  712. public void testOnlyOption_f1_12_f2_14_d() throws Exception {
  713. final Git git = new Git(db);
  714. prepare_f3_f2_14(git, D);
  715. prepare_f1_12(git);
  716. executeAndCheck_f1_12_f2_14(git, D);
  717. }
  718. @Test
  719. public void testOnlyOption_f1_12_f2_14_e() throws Exception {
  720. final Git git = new Git(db);
  721. prepare_f3_f2_14(git, E);
  722. prepare_f1_12(git);
  723. executeAndCheck_f1_12_f2_14(git, E);
  724. }
  725. @Test
  726. public void testOnlyOption_f1_13_a() throws Exception {
  727. final Git git = new Git(db);
  728. prepare_f3(git, A);
  729. prepare_f1_13(git);
  730. executeAndCheck_f1_13(git, A);
  731. }
  732. @Test
  733. public void testOnlyOption_f1_13_b() throws Exception {
  734. final Git git = new Git(db);
  735. prepare_f3(git, B);
  736. prepare_f1_13(git);
  737. executeAndCheck_f1_13(git, B);
  738. }
  739. @Test
  740. public void testOnlyOption_f1_13_c() throws Exception {
  741. final Git git = new Git(db);
  742. prepare_f3(git, C);
  743. prepare_f1_13(git);
  744. executeAndCheck_f1_13(git, C);
  745. }
  746. @Test
  747. public void testOnlyOption_f1_13_d() throws Exception {
  748. final Git git = new Git(db);
  749. prepare_f3(git, D);
  750. prepare_f1_13(git);
  751. executeAndCheck_f1_13(git, D);
  752. }
  753. @Test
  754. public void testOnlyOption_f1_13_e() throws Exception {
  755. final Git git = new Git(db);
  756. prepare_f3(git, E);
  757. prepare_f1_13(git);
  758. executeAndCheck_f1_13(git, E);
  759. }
  760. @Test
  761. public void testOnlyOption_f1_14_a() throws Exception {
  762. final Git git = new Git(db);
  763. prepare_f3(git, A);
  764. prepare_f1_14(git);
  765. executeAndCheck_f1_14(git, A);
  766. }
  767. @Test
  768. public void testOnlyOption_f1_14_b() throws Exception {
  769. final Git git = new Git(db);
  770. prepare_f3(git, B);
  771. prepare_f1_14(git);
  772. executeAndCheck_f1_14(git, B);
  773. }
  774. @Test
  775. public void testOnlyOption_f1_14_c() throws Exception {
  776. final Git git = new Git(db);
  777. prepare_f3(git, C);
  778. prepare_f1_14(git);
  779. executeAndCheck_f1_14(git, C);
  780. }
  781. @Test
  782. public void testOnlyOption_f1_14_d() throws Exception {
  783. final Git git = new Git(db);
  784. prepare_f3(git, D);
  785. prepare_f1_14(git);
  786. executeAndCheck_f1_14(git, D);
  787. }
  788. @Test
  789. public void testOnlyOption_f1_14_e() throws Exception {
  790. final Git git = new Git(db);
  791. prepare_f3(git, E);
  792. prepare_f1_14(git);
  793. executeAndCheck_f1_14(git, E);
  794. }
  795. @Test
  796. public void testOnlyOptionWithDirectory() throws Exception {
  797. final Git git = new Git(db);
  798. // write files
  799. final File f1 = writeTrashFile("d1/d2/f1.txt", "c1");
  800. writeTrashFile("d1/d2/f2.txt", "c2");
  801. final File f3 = writeTrashFile("d1/f3.txt", "c3");
  802. writeTrashFile("d1/f4.txt", "c4");
  803. final File f5 = writeTrashFile("d3/d4/f5.txt", "c5");
  804. writeTrashFile("d3/d4/f6.txt", "c6");
  805. final File f7 = writeTrashFile("d3/f7.txt", "c7");
  806. writeTrashFile("d3/f8.txt", "c8");
  807. final File f9 = writeTrashFile("d5/f9.txt", "c9");
  808. writeTrashFile("d5/f10.txt", "c10");
  809. final File f11 = writeTrashFile("d6/f11.txt", "c11");
  810. writeTrashFile("d6/f12.txt", "c12");
  811. // add files
  812. git.add().addFilepattern(".").call();
  813. // modify files, but do not stage changes
  814. write(f1, "c1'");
  815. write(f3, "c3'");
  816. write(f5, "c5'");
  817. write(f7, "c7'");
  818. write(f9, "c9'");
  819. write(f11, "c11'");
  820. // commit selected files only
  821. git.commit().setOnly("d1").setOnly("d3/d4/").setOnly("d5")
  822. .setOnly("d6/f11.txt").setMessage(MSG).call();
  823. assertEquals("c1'", getHead(git, "d1/d2/f1.txt"));
  824. assertEquals("c2", getHead(git, "d1/d2/f2.txt"));
  825. assertEquals("c3'", getHead(git, "d1/f3.txt"));
  826. assertEquals("c4", getHead(git, "d1/f4.txt"));
  827. assertEquals("c5'", getHead(git, "d3/d4/f5.txt"));
  828. assertEquals("c6", getHead(git, "d3/d4/f6.txt"));
  829. assertEquals("", getHead(git, "d3/f7.txt"));
  830. assertEquals("", getHead(git, "d3/f8.txt"));
  831. assertEquals("c9'", getHead(git, "d5/f9.txt"));
  832. assertEquals("c10", getHead(git, "d5/f10.txt"));
  833. assertEquals("c11'", getHead(git, "d6/f11.txt"));
  834. assertEquals("", getHead(git, "d6/f12.txt"));
  835. assertEquals("[d1/d2/f1.txt, mode:100644, content:c1']"
  836. + "[d1/d2/f2.txt, mode:100644, content:c2]"
  837. + "[d1/f3.txt, mode:100644, content:c3']"
  838. + "[d1/f4.txt, mode:100644, content:c4]"
  839. + "[d3/d4/f5.txt, mode:100644, content:c5']"
  840. + "[d3/d4/f6.txt, mode:100644, content:c6]"
  841. + "[d3/f7.txt, mode:100644, content:c7]"
  842. + "[d3/f8.txt, mode:100644, content:c8]"
  843. + "[d5/f10.txt, mode:100644, content:c10]"
  844. + "[d5/f9.txt, mode:100644, content:c9']"
  845. + "[d6/f11.txt, mode:100644, content:c11']"
  846. + "[d6/f12.txt, mode:100644, content:c12]", indexState(CONTENT));
  847. }
  848. @SuppressWarnings("unused")
  849. private File prepare_f1_1(final Git git) throws IOException {
  850. return writeTrashFile(F1, "c1");
  851. }
  852. private File prepare_f1_2(final Git git) throws Exception {
  853. final File f1 = prepare_f1_4(git);
  854. f1.delete();
  855. return f1;
  856. }
  857. private File prepare_f1_3(final Git git) throws Exception {
  858. final File f1 = prepare_f1_7(git);
  859. git.rm().addFilepattern(F1).call();
  860. return f1;
  861. }
  862. private File prepare_f1_4(final Git git) throws Exception {
  863. final File f1 = prepare_f1_1(git);
  864. git.add().addFilepattern(F1).call();
  865. return f1;
  866. }
  867. private File prepare_f1_5(final Git git) throws Exception {
  868. final File f1 = prepare_f1_7(git);
  869. f1.delete();
  870. return f1;
  871. }
  872. private File prepare_f1_6(final Git git) throws Exception {
  873. final File f1 = prepare_f1_3(git);
  874. write(f1, "c1");
  875. return f1;
  876. }
  877. private File prepare_f1_7(final Git git) throws Exception {
  878. final File f1 = prepare_f1_4(git);
  879. git.commit().setOnly(F1).setMessage(MSG).call();
  880. return f1;
  881. }
  882. private File prepare_f1_8(final Git git) throws Exception {
  883. final File f1 = prepare_f1_4(git);
  884. write(f1, "c1'");
  885. return f1;
  886. }
  887. private File prepare_f1_9(final Git git) throws Exception {
  888. final File f1 = prepare_f1_3(git);
  889. write(f1, "c1'");
  890. return f1;
  891. }
  892. private File prepare_f1_10(final Git git) throws Exception {
  893. final File f1 = prepare_f1_9(git);
  894. git.add().addFilepattern(F1).call();
  895. f1.delete();
  896. return f1;
  897. }
  898. private File prepare_f1_11(final Git git) throws Exception {
  899. final File f1 = prepare_f1_7(git);
  900. write(f1, "c1'");
  901. return f1;
  902. }
  903. private File prepare_f1_12(final Git git) throws Exception {
  904. final File f1 = prepare_f1_13(git);
  905. write(f1, "c1");
  906. return f1;
  907. }
  908. private File prepare_f1_13(final Git git) throws Exception {
  909. final File f1 = prepare_f1_11(git);
  910. git.add().addFilepattern(F1).call();
  911. return f1;
  912. }
  913. private File prepare_f1_14(final Git git) throws Exception {
  914. final File f1 = prepare_f1_13(git);
  915. write(f1, "c1''");
  916. return f1;
  917. }
  918. @SuppressWarnings("null")
  919. private void executeAndCheck_f1_1(final Git git, final int state)
  920. throws Exception {
  921. JGitInternalException exception = null;
  922. try {
  923. git.commit().setOnly(F1).setMessage(MSG).call();
  924. } catch (JGitInternalException e) {
  925. exception = e;
  926. }
  927. assertNotNull(exception);
  928. assertTrue(exception.getMessage().contains(F1));
  929. assertEquals(expected_f3_head(state), getHead(git, F3));
  930. assertEquals(expected_f3_idx(state), indexState(CONTENT));
  931. }
  932. @SuppressWarnings("null")
  933. private void executeAndCheck_f1_1_f2_f14(final Git git, final int state)
  934. throws Exception {
  935. JGitInternalException exception = null;
  936. try {
  937. git.commit().setOnly(F1).setOnly(F2).setMessage(MSG).call();
  938. } catch (JGitInternalException e) {
  939. exception = e;
  940. }
  941. assertNotNull(exception);
  942. assertTrue(exception.getMessage().contains(F1));
  943. assertEquals("c2", getHead(git, F2));
  944. assertEquals(expected_f3_head(state), getHead(git, F3));
  945. assertEquals("[f2.txt, mode:100644, content:c2']"
  946. + expected_f3_idx(state), indexState(CONTENT));
  947. }
  948. @SuppressWarnings("null")
  949. private void executeAndCheck_f1_2(final Git git, final int state)
  950. throws Exception {
  951. JGitInternalException exception = null;
  952. try {
  953. git.commit().setOnly(F1).setMessage(MSG).call();
  954. } catch (JGitInternalException e) {
  955. exception = e;
  956. }
  957. assertNotNull(exception);
  958. assertTrue(exception.getMessage().contains("No changes"));
  959. assertEquals(expected_f3_head(state), getHead(git, F3));
  960. assertEquals("[f1.txt, mode:100644, content:c1]"
  961. + expected_f3_idx(state), indexState(CONTENT));
  962. }
  963. private void executeAndCheck_f1_2_f2_f14(final Git git, final int state)
  964. throws Exception {
  965. git.commit().setOnly(F1).setOnly(F2).setMessage(MSG).call();
  966. assertEquals("", getHead(git, F1));
  967. assertEquals("c2''", getHead(git, F2));
  968. assertEquals(expected_f3_head(state), getHead(git, F3));
  969. assertEquals("[f2.txt, mode:100644, content:c2'']"
  970. + expected_f3_idx(state), indexState(CONTENT));
  971. }
  972. private void executeAndCheck_f1_3(final Git git, final int state)
  973. throws Exception {
  974. git.commit().setOnly(F1).setMessage(MSG).call();
  975. assertEquals("", getHead(git, F1));
  976. assertEquals(expected_f3_head(state), getHead(git, F3));
  977. assertEquals(expected_f3_idx(state), indexState(CONTENT));
  978. }
  979. private void executeAndCheck_f1_4(final Git git, final int state)
  980. throws Exception {
  981. git.commit().setOnly(F1).setMessage(MSG).call();
  982. assertEquals("c1", getHead(git, F1));
  983. assertEquals(expected_f3_head(state), getHead(git, F3));
  984. assertEquals("[f1.txt, mode:100644, content:c1]"
  985. + expected_f3_idx(state), indexState(CONTENT));
  986. }
  987. private void executeAndCheck_f1_5(final Git git, final int state)
  988. throws Exception {
  989. executeAndCheck_f1_3(git, state);
  990. }
  991. @SuppressWarnings("null")
  992. private void executeAndCheck_f1_6(final Git git, final int state)
  993. throws Exception {
  994. JGitInternalException exception = null;
  995. try {
  996. git.commit().setOnly(F1).setMessage(MSG).call();
  997. } catch (JGitInternalException e) {
  998. exception = e;
  999. }
  1000. assertNotNull(exception);
  1001. assertTrue(exception.getMessage().contains("No changes"));
  1002. assertEquals(expected_f3_head(state), getHead(git, F3));
  1003. assertEquals(expected_f3_idx(state), indexState(CONTENT));
  1004. }
  1005. private void executeAndCheck_f1_6_f2_14(final Git git, final int state)
  1006. throws Exception {
  1007. git.commit().setOnly(F1).setOnly(F2).setMessage(MSG).call();
  1008. assertEquals("c1", getHead(git, F1));
  1009. assertEquals("c2''", getHead(git, F2));
  1010. assertEquals(expected_f3_head(state), getHead(git, F3));
  1011. assertEquals("[f1.txt, mode:100644, content:c1]"
  1012. + "[f2.txt, mode:100644, content:c2'']"
  1013. + expected_f3_idx(state), indexState(CONTENT));
  1014. }
  1015. private void executeAndCheck_f1_7(final Git git, final int state)
  1016. throws Exception {
  1017. executeAndCheck_f1_2(git, state);
  1018. }
  1019. private void executeAndCheck_f1_7_f2_14(final Git git, final int state)
  1020. throws Exception {
  1021. executeAndCheck_f1_6_f2_14(git, state);
  1022. }
  1023. private void executeAndCheck_f1_8(final Git git, final int state)
  1024. throws Exception {
  1025. git.commit().setOnly(F1).setMessage(MSG).call();
  1026. assertEquals("c1'", getHead(git, F1));
  1027. assertEquals(expected_f3_head(state), getHead(git, F3));
  1028. assertEquals("[f1.txt, mode:100644, content:c1']"
  1029. + expected_f3_idx(state), indexState(CONTENT));
  1030. }
  1031. private void executeAndCheck_f1_9(final Git git, final int state)
  1032. throws Exception {
  1033. executeAndCheck_f1_8(git, state);
  1034. }
  1035. private void executeAndCheck_f1_10(final Git git, final int state)
  1036. throws Exception {
  1037. executeAndCheck_f1_3(git, state);
  1038. }
  1039. private void executeAndCheck_f1_11(final Git git, final int state)
  1040. throws Exception {
  1041. executeAndCheck_f1_8(git, state);
  1042. }
  1043. @SuppressWarnings("null")
  1044. private void executeAndCheck_f1_12(final Git git, final int state)
  1045. throws Exception {
  1046. JGitInternalException exception = null;
  1047. try {
  1048. git.commit().setOnly(F1).setMessage(MSG).call();
  1049. } catch (JGitInternalException e) {
  1050. exception = e;
  1051. }
  1052. assertNotNull(exception);
  1053. assertTrue(exception.getMessage().contains("No changes"));
  1054. assertEquals(expected_f3_head(state), getHead(git, F3));
  1055. assertEquals("[f1.txt, mode:100644, content:c1']"
  1056. + expected_f3_idx(state), indexState(CONTENT));
  1057. }
  1058. private void executeAndCheck_f1_12_f2_14(final Git git, final int state)
  1059. throws Exception {
  1060. executeAndCheck_f1_6_f2_14(git, state);
  1061. }
  1062. private void executeAndCheck_f1_13(final Git git, final int state)
  1063. throws Exception {
  1064. executeAndCheck_f1_8(git, state);
  1065. }
  1066. private void executeAndCheck_f1_14(final Git git, final int state)
  1067. throws Exception {
  1068. git.commit().setOnly(F1).setMessage(MSG).call();
  1069. assertEquals("c1''", getHead(git, F1));
  1070. assertEquals(expected_f3_head(state), getHead(git, F3));
  1071. assertEquals("[f1.txt, mode:100644, content:c1'']"
  1072. + expected_f3_idx(state), indexState(CONTENT));
  1073. }
  1074. private void prepare_f3(final Git git, final int state) throws Exception {
  1075. prepare_f3_f2_14(git, state, false);
  1076. }
  1077. private void prepare_f3_f2_14(final Git git, final int state)
  1078. throws Exception {
  1079. prepare_f3_f2_14(git, state, true);
  1080. }
  1081. private void prepare_f3_f2_14(final Git git, final int state,
  1082. final boolean include_f2) throws Exception {
  1083. File f2 = null;
  1084. if (include_f2) {
  1085. f2 = writeTrashFile(F2, "c2");
  1086. git.add().addFilepattern(F2).call();
  1087. git.commit().setMessage(MSG).call();
  1088. }
  1089. if (state >= 1) {
  1090. writeTrashFile(F3, "c3");
  1091. git.add().addFilepattern(F3).call();
  1092. }
  1093. if (state >= 2)
  1094. git.commit().setMessage(MSG).call();
  1095. if (state >= 3)
  1096. git.rm().addFilepattern(F3).call();
  1097. if (state == 4) {
  1098. writeTrashFile(F3, "c3'");
  1099. git.add().addFilepattern(F3).call();
  1100. }
  1101. if (include_f2) {
  1102. write(f2, "c2'");
  1103. git.add().addFilepattern(F2).call();
  1104. write(f2, "c2''");
  1105. }
  1106. }
  1107. private String expected_f3_head(final int state) {
  1108. switch (state) {
  1109. case 0:
  1110. case 1:
  1111. return "";
  1112. case 2:
  1113. case 3:
  1114. case 4:
  1115. return "c3";
  1116. }
  1117. return null;
  1118. }
  1119. private String expected_f3_idx(final int state) {
  1120. switch (state) {
  1121. case 0:
  1122. case 3:
  1123. return "";
  1124. case 1:
  1125. case 2:
  1126. return "[f3.txt, mode:100644, content:c3]";
  1127. case 4:
  1128. return "[f3.txt, mode:100644, content:c3']";
  1129. }
  1130. return null;
  1131. }
  1132. private String getHead(final Git git, final String path) throws Exception {
  1133. try {
  1134. final Repository repo = git.getRepository();
  1135. final ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
  1136. final TreeWalk tw = TreeWalk.forPath(repo, path,
  1137. new RevWalk(repo).parseTree(headId));
  1138. return new String(tw.getObjectReader().open(tw.getObjectId(0))
  1139. .getBytes());
  1140. } catch (Exception e) {
  1141. return "";
  1142. }
  1143. }
  1144. }