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

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