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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305
  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.junit.RepositoryTestCase;
  52. import org.eclipse.jgit.lib.Constants;
  53. import org.eclipse.jgit.lib.ObjectId;
  54. import org.eclipse.jgit.lib.Repository;
  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. private void executeAndCheck_f1_1(final Git git, final int state)
  919. throws Exception {
  920. JGitInternalException exception = null;
  921. try {
  922. git.commit().setOnly(F1).setMessage(MSG).call();
  923. } catch (JGitInternalException e) {
  924. exception = e;
  925. }
  926. assertNotNull(exception);
  927. assertTrue(exception.getMessage().contains(F1));
  928. assertEquals(expected_f3_head(state), getHead(git, F3));
  929. assertEquals(expected_f3_idx(state), indexState(CONTENT));
  930. }
  931. private void executeAndCheck_f1_1_f2_f14(final Git git, final int state)
  932. throws Exception {
  933. JGitInternalException exception = null;
  934. try {
  935. git.commit().setOnly(F1).setOnly(F2).setMessage(MSG).call();
  936. } catch (JGitInternalException e) {
  937. exception = e;
  938. }
  939. assertNotNull(exception);
  940. assertTrue(exception.getMessage().contains(F1));
  941. assertEquals("c2", getHead(git, F2));
  942. assertEquals(expected_f3_head(state), getHead(git, F3));
  943. assertEquals("[f2.txt, mode:100644, content:c2']"
  944. + expected_f3_idx(state), indexState(CONTENT));
  945. }
  946. private void executeAndCheck_f1_2(final Git git, final int state)
  947. throws Exception {
  948. JGitInternalException exception = null;
  949. try {
  950. git.commit().setOnly(F1).setMessage(MSG).call();
  951. } catch (JGitInternalException e) {
  952. exception = e;
  953. }
  954. assertNotNull(exception);
  955. assertTrue(exception.getMessage().contains("No changes"));
  956. assertEquals(expected_f3_head(state), getHead(git, F3));
  957. assertEquals("[f1.txt, mode:100644, content:c1]"
  958. + expected_f3_idx(state), indexState(CONTENT));
  959. }
  960. private void executeAndCheck_f1_2_f2_f14(final Git git, final int state)
  961. throws Exception {
  962. git.commit().setOnly(F1).setOnly(F2).setMessage(MSG).call();
  963. assertEquals("", getHead(git, F1));
  964. assertEquals("c2''", getHead(git, F2));
  965. assertEquals(expected_f3_head(state), getHead(git, F3));
  966. assertEquals("[f2.txt, mode:100644, content:c2'']"
  967. + expected_f3_idx(state), indexState(CONTENT));
  968. }
  969. private void executeAndCheck_f1_3(final Git git, final int state)
  970. throws Exception {
  971. git.commit().setOnly(F1).setMessage(MSG).call();
  972. assertEquals("", getHead(git, F1));
  973. assertEquals(expected_f3_head(state), getHead(git, F3));
  974. assertEquals(expected_f3_idx(state), indexState(CONTENT));
  975. }
  976. private void executeAndCheck_f1_4(final Git git, final int state)
  977. throws Exception {
  978. git.commit().setOnly(F1).setMessage(MSG).call();
  979. assertEquals("c1", getHead(git, F1));
  980. assertEquals(expected_f3_head(state), getHead(git, F3));
  981. assertEquals("[f1.txt, mode:100644, content:c1]"
  982. + expected_f3_idx(state), indexState(CONTENT));
  983. }
  984. private void executeAndCheck_f1_5(final Git git, final int state)
  985. throws Exception {
  986. executeAndCheck_f1_3(git, state);
  987. }
  988. private void executeAndCheck_f1_6(final Git git, final int state)
  989. throws Exception {
  990. JGitInternalException exception = null;
  991. try {
  992. git.commit().setOnly(F1).setMessage(MSG).call();
  993. } catch (JGitInternalException e) {
  994. exception = e;
  995. }
  996. assertNotNull(exception);
  997. assertTrue(exception.getMessage().contains("No changes"));
  998. assertEquals(expected_f3_head(state), getHead(git, F3));
  999. assertEquals(expected_f3_idx(state), indexState(CONTENT));
  1000. }
  1001. private void executeAndCheck_f1_6_f2_14(final Git git, final int state)
  1002. throws Exception {
  1003. git.commit().setOnly(F1).setOnly(F2).setMessage(MSG).call();
  1004. assertEquals("c1", getHead(git, F1));
  1005. assertEquals("c2''", getHead(git, F2));
  1006. assertEquals(expected_f3_head(state), getHead(git, F3));
  1007. assertEquals("[f1.txt, mode:100644, content:c1]"
  1008. + "[f2.txt, mode:100644, content:c2'']"
  1009. + expected_f3_idx(state), indexState(CONTENT));
  1010. }
  1011. private void executeAndCheck_f1_7(final Git git, final int state)
  1012. throws Exception {
  1013. executeAndCheck_f1_2(git, state);
  1014. }
  1015. private void executeAndCheck_f1_7_f2_14(final Git git, final int state)
  1016. throws Exception {
  1017. executeAndCheck_f1_6_f2_14(git, state);
  1018. }
  1019. private void executeAndCheck_f1_8(final Git git, final int state)
  1020. throws Exception {
  1021. git.commit().setOnly(F1).setMessage(MSG).call();
  1022. assertEquals("c1'", getHead(git, F1));
  1023. assertEquals(expected_f3_head(state), getHead(git, F3));
  1024. assertEquals("[f1.txt, mode:100644, content:c1']"
  1025. + expected_f3_idx(state), indexState(CONTENT));
  1026. }
  1027. private void executeAndCheck_f1_9(final Git git, final int state)
  1028. throws Exception {
  1029. executeAndCheck_f1_8(git, state);
  1030. }
  1031. private void executeAndCheck_f1_10(final Git git, final int state)
  1032. throws Exception {
  1033. executeAndCheck_f1_3(git, state);
  1034. }
  1035. private void executeAndCheck_f1_11(final Git git, final int state)
  1036. throws Exception {
  1037. executeAndCheck_f1_8(git, state);
  1038. }
  1039. private void executeAndCheck_f1_12(final Git git, final int state)
  1040. throws Exception {
  1041. JGitInternalException exception = null;
  1042. try {
  1043. git.commit().setOnly(F1).setMessage(MSG).call();
  1044. } catch (JGitInternalException e) {
  1045. exception = e;
  1046. }
  1047. assertNotNull(exception);
  1048. assertTrue(exception.getMessage().contains("No changes"));
  1049. assertEquals(expected_f3_head(state), getHead(git, F3));
  1050. assertEquals("[f1.txt, mode:100644, content:c1']"
  1051. + expected_f3_idx(state), indexState(CONTENT));
  1052. }
  1053. private void executeAndCheck_f1_12_f2_14(final Git git, final int state)
  1054. throws Exception {
  1055. executeAndCheck_f1_6_f2_14(git, state);
  1056. }
  1057. private void executeAndCheck_f1_13(final Git git, final int state)
  1058. throws Exception {
  1059. executeAndCheck_f1_8(git, state);
  1060. }
  1061. private void executeAndCheck_f1_14(final Git git, final int state)
  1062. throws Exception {
  1063. git.commit().setOnly(F1).setMessage(MSG).call();
  1064. assertEquals("c1''", getHead(git, F1));
  1065. assertEquals(expected_f3_head(state), getHead(git, F3));
  1066. assertEquals("[f1.txt, mode:100644, content:c1'']"
  1067. + expected_f3_idx(state), indexState(CONTENT));
  1068. }
  1069. private void prepare_f3(final Git git, final int state) throws Exception {
  1070. prepare_f3_f2_14(git, state, false);
  1071. }
  1072. private void prepare_f3_f2_14(final Git git, final int state)
  1073. throws Exception {
  1074. prepare_f3_f2_14(git, state, true);
  1075. }
  1076. private void prepare_f3_f2_14(final Git git, final int state,
  1077. final boolean include_f2) throws Exception {
  1078. File f2 = null;
  1079. if (include_f2) {
  1080. f2 = writeTrashFile(F2, "c2");
  1081. git.add().addFilepattern(F2).call();
  1082. git.commit().setMessage(MSG).call();
  1083. }
  1084. if (state >= 1) {
  1085. writeTrashFile(F3, "c3");
  1086. git.add().addFilepattern(F3).call();
  1087. }
  1088. if (state >= 2)
  1089. git.commit().setMessage(MSG).call();
  1090. if (state >= 3)
  1091. git.rm().addFilepattern(F3).call();
  1092. if (state == 4) {
  1093. writeTrashFile(F3, "c3'");
  1094. git.add().addFilepattern(F3).call();
  1095. }
  1096. if (include_f2) {
  1097. write(f2, "c2'");
  1098. git.add().addFilepattern(F2).call();
  1099. write(f2, "c2''");
  1100. }
  1101. }
  1102. private static String expected_f3_head(final int state) {
  1103. switch (state) {
  1104. case 0:
  1105. case 1:
  1106. return "";
  1107. case 2:
  1108. case 3:
  1109. case 4:
  1110. return "c3";
  1111. }
  1112. return null;
  1113. }
  1114. private static String expected_f3_idx(final int state) {
  1115. switch (state) {
  1116. case 0:
  1117. case 3:
  1118. return "";
  1119. case 1:
  1120. case 2:
  1121. return "[f3.txt, mode:100644, content:c3]";
  1122. case 4:
  1123. return "[f3.txt, mode:100644, content:c3']";
  1124. }
  1125. return null;
  1126. }
  1127. static private String getHead(final Git git, final String path)
  1128. throws Exception {
  1129. try {
  1130. final Repository repo = git.getRepository();
  1131. final ObjectId headId = repo.resolve(Constants.HEAD + "^{commit}");
  1132. final TreeWalk tw = TreeWalk.forPath(repo, path,
  1133. new RevWalk(repo).parseTree(headId));
  1134. return new String(tw.getObjectReader().open(tw.getObjectId(0))
  1135. .getBytes());
  1136. } catch (Exception e) {
  1137. return "";
  1138. }
  1139. }
  1140. }