PageRenderTime 50ms CodeModel.GetById 25ms RepoModel.GetById 1ms app.codeStats 0ms

/git-source/t/t3030-merge-recursive.sh

https://bitbucket.org/jrencz/git-kata-registration
Shell | 596 lines | 560 code | 35 blank | 1 comment | 1 complexity | 370f1b86546ba1113173789b2bd67035 MD5 | raw file
  1. #!/bin/sh
  2. test_description='merge-recursive backend test'
  3. . ./test-lib.sh
  4. test_expect_success 'setup 1' '
  5. echo hello >a &&
  6. o0=$(git hash-object a) &&
  7. cp a b &&
  8. cp a c &&
  9. mkdir d &&
  10. cp a d/e &&
  11. test_tick &&
  12. git add a b c d/e &&
  13. git commit -m initial &&
  14. c0=$(git rev-parse --verify HEAD) &&
  15. git branch side &&
  16. git branch df-1 &&
  17. git branch df-2 &&
  18. git branch df-3 &&
  19. git branch remove &&
  20. git branch submod &&
  21. git branch copy &&
  22. git branch rename &&
  23. if test_have_prereq SYMLINKS
  24. then
  25. git branch rename-ln
  26. fi &&
  27. echo hello >>a &&
  28. cp a d/e &&
  29. o1=$(git hash-object a) &&
  30. git add a d/e &&
  31. test_tick &&
  32. git commit -m "master modifies a and d/e" &&
  33. c1=$(git rev-parse --verify HEAD) &&
  34. ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  35. (
  36. echo "100644 blob $o1 a"
  37. echo "100644 blob $o0 b"
  38. echo "100644 blob $o0 c"
  39. echo "100644 blob $o1 d/e"
  40. echo "100644 $o1 0 a"
  41. echo "100644 $o0 0 b"
  42. echo "100644 $o0 0 c"
  43. echo "100644 $o1 0 d/e"
  44. ) >expected &&
  45. test_cmp expected actual
  46. '
  47. test_expect_success 'setup 2' '
  48. rm -rf [abcd] &&
  49. git checkout side &&
  50. ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  51. (
  52. echo "100644 blob $o0 a"
  53. echo "100644 blob $o0 b"
  54. echo "100644 blob $o0 c"
  55. echo "100644 blob $o0 d/e"
  56. echo "100644 $o0 0 a"
  57. echo "100644 $o0 0 b"
  58. echo "100644 $o0 0 c"
  59. echo "100644 $o0 0 d/e"
  60. ) >expected &&
  61. test_cmp expected actual &&
  62. echo goodbye >>a &&
  63. o2=$(git hash-object a) &&
  64. git add a &&
  65. test_tick &&
  66. git commit -m "side modifies a" &&
  67. c2=$(git rev-parse --verify HEAD) &&
  68. ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  69. (
  70. echo "100644 blob $o2 a"
  71. echo "100644 blob $o0 b"
  72. echo "100644 blob $o0 c"
  73. echo "100644 blob $o0 d/e"
  74. echo "100644 $o2 0 a"
  75. echo "100644 $o0 0 b"
  76. echo "100644 $o0 0 c"
  77. echo "100644 $o0 0 d/e"
  78. ) >expected &&
  79. test_cmp expected actual
  80. '
  81. test_expect_success 'setup 3' '
  82. rm -rf [abcd] &&
  83. git checkout df-1 &&
  84. ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  85. (
  86. echo "100644 blob $o0 a"
  87. echo "100644 blob $o0 b"
  88. echo "100644 blob $o0 c"
  89. echo "100644 blob $o0 d/e"
  90. echo "100644 $o0 0 a"
  91. echo "100644 $o0 0 b"
  92. echo "100644 $o0 0 c"
  93. echo "100644 $o0 0 d/e"
  94. ) >expected &&
  95. test_cmp expected actual &&
  96. rm -f b && mkdir b && echo df-1 >b/c && git add b/c &&
  97. o3=$(git hash-object b/c) &&
  98. test_tick &&
  99. git commit -m "df-1 makes b/c" &&
  100. c3=$(git rev-parse --verify HEAD) &&
  101. ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  102. (
  103. echo "100644 blob $o0 a"
  104. echo "100644 blob $o3 b/c"
  105. echo "100644 blob $o0 c"
  106. echo "100644 blob $o0 d/e"
  107. echo "100644 $o0 0 a"
  108. echo "100644 $o3 0 b/c"
  109. echo "100644 $o0 0 c"
  110. echo "100644 $o0 0 d/e"
  111. ) >expected &&
  112. test_cmp expected actual
  113. '
  114. test_expect_success 'setup 4' '
  115. rm -rf [abcd] &&
  116. git checkout df-2 &&
  117. ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  118. (
  119. echo "100644 blob $o0 a"
  120. echo "100644 blob $o0 b"
  121. echo "100644 blob $o0 c"
  122. echo "100644 blob $o0 d/e"
  123. echo "100644 $o0 0 a"
  124. echo "100644 $o0 0 b"
  125. echo "100644 $o0 0 c"
  126. echo "100644 $o0 0 d/e"
  127. ) >expected &&
  128. test_cmp expected actual &&
  129. rm -f a && mkdir a && echo df-2 >a/c && git add a/c &&
  130. o4=$(git hash-object a/c) &&
  131. test_tick &&
  132. git commit -m "df-2 makes a/c" &&
  133. c4=$(git rev-parse --verify HEAD) &&
  134. ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  135. (
  136. echo "100644 blob $o4 a/c"
  137. echo "100644 blob $o0 b"
  138. echo "100644 blob $o0 c"
  139. echo "100644 blob $o0 d/e"
  140. echo "100644 $o4 0 a/c"
  141. echo "100644 $o0 0 b"
  142. echo "100644 $o0 0 c"
  143. echo "100644 $o0 0 d/e"
  144. ) >expected &&
  145. test_cmp expected actual
  146. '
  147. test_expect_success 'setup 5' '
  148. rm -rf [abcd] &&
  149. git checkout remove &&
  150. ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  151. (
  152. echo "100644 blob $o0 a"
  153. echo "100644 blob $o0 b"
  154. echo "100644 blob $o0 c"
  155. echo "100644 blob $o0 d/e"
  156. echo "100644 $o0 0 a"
  157. echo "100644 $o0 0 b"
  158. echo "100644 $o0 0 c"
  159. echo "100644 $o0 0 d/e"
  160. ) >expected &&
  161. test_cmp expected actual &&
  162. rm -f b &&
  163. echo remove-conflict >a &&
  164. git add a &&
  165. git rm b &&
  166. o5=$(git hash-object a) &&
  167. test_tick &&
  168. git commit -m "remove removes b and modifies a" &&
  169. c5=$(git rev-parse --verify HEAD) &&
  170. ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  171. (
  172. echo "100644 blob $o5 a"
  173. echo "100644 blob $o0 c"
  174. echo "100644 blob $o0 d/e"
  175. echo "100644 $o5 0 a"
  176. echo "100644 $o0 0 c"
  177. echo "100644 $o0 0 d/e"
  178. ) >expected &&
  179. test_cmp expected actual
  180. '
  181. test_expect_success 'setup 6' '
  182. rm -rf [abcd] &&
  183. git checkout df-3 &&
  184. ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  185. (
  186. echo "100644 blob $o0 a"
  187. echo "100644 blob $o0 b"
  188. echo "100644 blob $o0 c"
  189. echo "100644 blob $o0 d/e"
  190. echo "100644 $o0 0 a"
  191. echo "100644 $o0 0 b"
  192. echo "100644 $o0 0 c"
  193. echo "100644 $o0 0 d/e"
  194. ) >expected &&
  195. test_cmp expected actual &&
  196. rm -fr d && echo df-3 >d && git add d &&
  197. o6=$(git hash-object d) &&
  198. test_tick &&
  199. git commit -m "df-3 makes d" &&
  200. c6=$(git rev-parse --verify HEAD) &&
  201. ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  202. (
  203. echo "100644 blob $o0 a"
  204. echo "100644 blob $o0 b"
  205. echo "100644 blob $o0 c"
  206. echo "100644 blob $o6 d"
  207. echo "100644 $o0 0 a"
  208. echo "100644 $o0 0 b"
  209. echo "100644 $o0 0 c"
  210. echo "100644 $o6 0 d"
  211. ) >expected &&
  212. test_cmp expected actual
  213. '
  214. test_expect_success 'setup 7' '
  215. git checkout submod &&
  216. git rm d/e &&
  217. test_tick &&
  218. git commit -m "remove d/e" &&
  219. git update-index --add --cacheinfo 160000 $c1 d &&
  220. test_tick &&
  221. git commit -m "make d/ a submodule"
  222. '
  223. test_expect_success 'setup 8' '
  224. git checkout rename &&
  225. git mv a e &&
  226. git add e &&
  227. test_tick &&
  228. git commit -m "rename a->e" &&
  229. if test_have_prereq SYMLINKS
  230. then
  231. git checkout rename-ln &&
  232. git mv a e &&
  233. ln -s e a &&
  234. git add a e &&
  235. test_tick &&
  236. git commit -m "rename a->e, symlink a->e" &&
  237. oln=`printf e | git hash-object --stdin`
  238. fi
  239. '
  240. test_expect_success 'setup 9' '
  241. git checkout copy &&
  242. cp a e &&
  243. git add e &&
  244. test_tick &&
  245. git commit -m "copy a->e"
  246. '
  247. test_expect_success 'merge-recursive simple' '
  248. rm -fr [abcd] &&
  249. git checkout -f "$c2" &&
  250. test_expect_code 1 git merge-recursive "$c0" -- "$c2" "$c1"
  251. '
  252. test_expect_success 'merge-recursive result' '
  253. git ls-files -s >actual &&
  254. (
  255. echo "100644 $o0 1 a"
  256. echo "100644 $o2 2 a"
  257. echo "100644 $o1 3 a"
  258. echo "100644 $o0 0 b"
  259. echo "100644 $o0 0 c"
  260. echo "100644 $o1 0 d/e"
  261. ) >expected &&
  262. test_cmp expected actual
  263. '
  264. test_expect_success 'fail if the index has unresolved entries' '
  265. rm -fr [abcd] &&
  266. git checkout -f "$c1" &&
  267. test_must_fail git merge "$c5" &&
  268. test_must_fail git merge "$c5" 2> out &&
  269. test_i18ngrep "not possible because you have unmerged files" out &&
  270. git add -u &&
  271. test_must_fail git merge "$c5" 2> out &&
  272. test_i18ngrep "You have not concluded your merge" out &&
  273. rm -f .git/MERGE_HEAD &&
  274. test_must_fail git merge "$c5" 2> out &&
  275. test_i18ngrep "Your local changes to the following files would be overwritten by merge:" out
  276. '
  277. test_expect_success 'merge-recursive remove conflict' '
  278. rm -fr [abcd] &&
  279. git checkout -f "$c1" &&
  280. test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c5"
  281. '
  282. test_expect_success 'merge-recursive remove conflict' '
  283. git ls-files -s >actual &&
  284. (
  285. echo "100644 $o0 1 a"
  286. echo "100644 $o1 2 a"
  287. echo "100644 $o5 3 a"
  288. echo "100644 $o0 0 c"
  289. echo "100644 $o1 0 d/e"
  290. ) >expected &&
  291. test_cmp expected actual
  292. '
  293. test_expect_success 'merge-recursive d/f simple' '
  294. rm -fr [abcd] &&
  295. git reset --hard &&
  296. git checkout -f "$c1" &&
  297. git merge-recursive "$c0" -- "$c1" "$c3"
  298. '
  299. test_expect_success 'merge-recursive result' '
  300. git ls-files -s >actual &&
  301. (
  302. echo "100644 $o1 0 a"
  303. echo "100644 $o3 0 b/c"
  304. echo "100644 $o0 0 c"
  305. echo "100644 $o1 0 d/e"
  306. ) >expected &&
  307. test_cmp expected actual
  308. '
  309. test_expect_success 'merge-recursive d/f conflict' '
  310. rm -fr [abcd] &&
  311. git reset --hard &&
  312. git checkout -f "$c1" &&
  313. test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c4"
  314. '
  315. test_expect_success 'merge-recursive d/f conflict result' '
  316. git ls-files -s >actual &&
  317. (
  318. echo "100644 $o0 1 a"
  319. echo "100644 $o1 2 a"
  320. echo "100644 $o4 0 a/c"
  321. echo "100644 $o0 0 b"
  322. echo "100644 $o0 0 c"
  323. echo "100644 $o1 0 d/e"
  324. ) >expected &&
  325. test_cmp expected actual
  326. '
  327. test_expect_success 'merge-recursive d/f conflict the other way' '
  328. rm -fr [abcd] &&
  329. git reset --hard &&
  330. git checkout -f "$c4" &&
  331. test_expect_code 1 git merge-recursive "$c0" -- "$c4" "$c1"
  332. '
  333. test_expect_success 'merge-recursive d/f conflict result the other way' '
  334. git ls-files -s >actual &&
  335. (
  336. echo "100644 $o0 1 a"
  337. echo "100644 $o1 3 a"
  338. echo "100644 $o4 0 a/c"
  339. echo "100644 $o0 0 b"
  340. echo "100644 $o0 0 c"
  341. echo "100644 $o1 0 d/e"
  342. ) >expected &&
  343. test_cmp expected actual
  344. '
  345. test_expect_success 'merge-recursive d/f conflict' '
  346. rm -fr [abcd] &&
  347. git reset --hard &&
  348. git checkout -f "$c1" &&
  349. test_expect_code 1 git merge-recursive "$c0" -- "$c1" "$c6"
  350. '
  351. test_expect_success 'merge-recursive d/f conflict result' '
  352. git ls-files -s >actual &&
  353. (
  354. echo "100644 $o1 0 a"
  355. echo "100644 $o0 0 b"
  356. echo "100644 $o0 0 c"
  357. echo "100644 $o6 3 d"
  358. echo "100644 $o0 1 d/e"
  359. echo "100644 $o1 2 d/e"
  360. ) >expected &&
  361. test_cmp expected actual
  362. '
  363. test_expect_success 'merge-recursive d/f conflict' '
  364. rm -fr [abcd] &&
  365. git reset --hard &&
  366. git checkout -f "$c6" &&
  367. test_expect_code 1 git merge-recursive "$c0" -- "$c6" "$c1"
  368. '
  369. test_expect_success 'merge-recursive d/f conflict result' '
  370. git ls-files -s >actual &&
  371. (
  372. echo "100644 $o1 0 a"
  373. echo "100644 $o0 0 b"
  374. echo "100644 $o0 0 c"
  375. echo "100644 $o6 2 d"
  376. echo "100644 $o0 1 d/e"
  377. echo "100644 $o1 3 d/e"
  378. ) >expected &&
  379. test_cmp expected actual
  380. '
  381. test_expect_success 'reset and 3-way merge' '
  382. git reset --hard "$c2" &&
  383. git read-tree -m "$c0" "$c2" "$c1"
  384. '
  385. test_expect_success 'reset and bind merge' '
  386. git reset --hard master &&
  387. git read-tree --prefix=M/ master &&
  388. git ls-files -s >actual &&
  389. (
  390. echo "100644 $o1 0 M/a"
  391. echo "100644 $o0 0 M/b"
  392. echo "100644 $o0 0 M/c"
  393. echo "100644 $o1 0 M/d/e"
  394. echo "100644 $o1 0 a"
  395. echo "100644 $o0 0 b"
  396. echo "100644 $o0 0 c"
  397. echo "100644 $o1 0 d/e"
  398. ) >expected &&
  399. test_cmp expected actual &&
  400. git read-tree --prefix=a1/ master &&
  401. git ls-files -s >actual &&
  402. (
  403. echo "100644 $o1 0 M/a"
  404. echo "100644 $o0 0 M/b"
  405. echo "100644 $o0 0 M/c"
  406. echo "100644 $o1 0 M/d/e"
  407. echo "100644 $o1 0 a"
  408. echo "100644 $o1 0 a1/a"
  409. echo "100644 $o0 0 a1/b"
  410. echo "100644 $o0 0 a1/c"
  411. echo "100644 $o1 0 a1/d/e"
  412. echo "100644 $o0 0 b"
  413. echo "100644 $o0 0 c"
  414. echo "100644 $o1 0 d/e"
  415. ) >expected &&
  416. test_cmp expected actual &&
  417. git read-tree --prefix=z/ master &&
  418. git ls-files -s >actual &&
  419. (
  420. echo "100644 $o1 0 M/a"
  421. echo "100644 $o0 0 M/b"
  422. echo "100644 $o0 0 M/c"
  423. echo "100644 $o1 0 M/d/e"
  424. echo "100644 $o1 0 a"
  425. echo "100644 $o1 0 a1/a"
  426. echo "100644 $o0 0 a1/b"
  427. echo "100644 $o0 0 a1/c"
  428. echo "100644 $o1 0 a1/d/e"
  429. echo "100644 $o0 0 b"
  430. echo "100644 $o0 0 c"
  431. echo "100644 $o1 0 d/e"
  432. echo "100644 $o1 0 z/a"
  433. echo "100644 $o0 0 z/b"
  434. echo "100644 $o0 0 z/c"
  435. echo "100644 $o1 0 z/d/e"
  436. ) >expected &&
  437. test_cmp expected actual
  438. '
  439. test_expect_success 'merge removes empty directories' '
  440. git reset --hard master &&
  441. git checkout -b rm &&
  442. git rm d/e &&
  443. git commit -mremoved-d/e &&
  444. git checkout master &&
  445. git merge -s recursive rm &&
  446. test_must_fail test -d d
  447. '
  448. test_expect_failure 'merge-recursive simple w/submodule' '
  449. git checkout submod &&
  450. git merge remove
  451. '
  452. test_expect_failure 'merge-recursive simple w/submodule result' '
  453. git ls-files -s >actual &&
  454. (
  455. echo "100644 $o5 0 a"
  456. echo "100644 $o0 0 c"
  457. echo "160000 $c1 0 d"
  458. ) >expected &&
  459. test_cmp expected actual
  460. '
  461. test_expect_success 'merge-recursive copy vs. rename' '
  462. git checkout -f copy &&
  463. git merge rename &&
  464. ( git ls-tree -r HEAD && git ls-files -s ) >actual &&
  465. (
  466. echo "100644 blob $o0 b"
  467. echo "100644 blob $o0 c"
  468. echo "100644 blob $o0 d/e"
  469. echo "100644 blob $o0 e"
  470. echo "100644 $o0 0 b"
  471. echo "100644 $o0 0 c"
  472. echo "100644 $o0 0 d/e"
  473. echo "100644 $o0 0 e"
  474. ) >expected &&
  475. test_cmp expected actual
  476. '
  477. if test_have_prereq SYMLINKS
  478. then
  479. test_expect_failure 'merge-recursive rename vs. rename/symlink' '
  480. git checkout -f rename &&
  481. git merge rename-ln &&
  482. ( git ls-tree -r HEAD ; git ls-files -s ) >actual &&
  483. (
  484. echo "120000 blob $oln a"
  485. echo "100644 blob $o0 b"
  486. echo "100644 blob $o0 c"
  487. echo "100644 blob $o0 d/e"
  488. echo "100644 blob $o0 e"
  489. echo "120000 $oln 0 a"
  490. echo "100644 $o0 0 b"
  491. echo "100644 $o0 0 c"
  492. echo "100644 $o0 0 d/e"
  493. echo "100644 $o0 0 e"
  494. ) >expected &&
  495. test_cmp expected actual
  496. '
  497. fi
  498. test_done