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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307
  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. try (RevWalk rw = new RevWalk(repo)) {
  1133. final TreeWalk tw = TreeWalk.forPath(repo, path,
  1134. rw.parseTree(headId));
  1135. return new String(tw.getObjectReader().open(tw.getObjectId(0))
  1136. .getBytes());
  1137. }
  1138. } catch (Exception e) {
  1139. return "";
  1140. }
  1141. }
  1142. }