PageRenderTime 39ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/contrib/remote-helpers/test-hg-hg-git.sh

https://gitlab.com/nmusco/git
Shell | 542 lines | 499 code | 30 blank | 13 comment | 10 complexity | b995c44f1fa46477e37395f2a329aa75 MD5 | raw file
  1. #!/bin/sh
  2. #
  3. # Copyright (c) 2012 Felipe Contreras
  4. #
  5. # Base commands from hg-git tests:
  6. # https://bitbucket.org/durin42/hg-git/src
  7. #
  8. test_description='Test remote-hg output compared to hg-git'
  9. test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
  10. . "$TEST_DIRECTORY"/test-lib.sh
  11. if ! test_have_prereq PYTHON
  12. then
  13. skip_all='skipping remote-hg tests; python not available'
  14. test_done
  15. fi
  16. if ! python -c 'import mercurial'
  17. then
  18. skip_all='skipping remote-hg tests; mercurial not available'
  19. test_done
  20. fi
  21. if ! python -c 'import hggit'
  22. then
  23. skip_all='skipping remote-hg tests; hg-git not available'
  24. test_done
  25. fi
  26. # clone to a git repo with git
  27. git_clone_git () {
  28. git clone -q "hg::$1" $2 &&
  29. (cd $2 && git checkout master && git branch -D default)
  30. }
  31. # clone to an hg repo with git
  32. hg_clone_git () {
  33. (
  34. hg init $2 &&
  35. hg -R $2 bookmark -i master &&
  36. cd $1 &&
  37. git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
  38. ) &&
  39. (cd $2 && hg -q update)
  40. }
  41. # clone to a git repo with hg
  42. git_clone_hg () {
  43. (
  44. git init -q $2 &&
  45. cd $1 &&
  46. hg bookmark -i -f -r tip master &&
  47. hg -q push -r master ../$2 || true
  48. )
  49. }
  50. # clone to an hg repo with hg
  51. hg_clone_hg () {
  52. hg -q clone $1 $2
  53. }
  54. # push an hg repo with git
  55. hg_push_git () {
  56. (
  57. cd $2
  58. git checkout -q -b tmp &&
  59. git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
  60. git branch -D default &&
  61. git checkout -q @{-1} &&
  62. git branch -q -D tmp 2>/dev/null || true
  63. )
  64. }
  65. # push an hg git repo with hg
  66. hg_push_hg () {
  67. (
  68. cd $1 &&
  69. hg -q push ../$2 || true
  70. )
  71. }
  72. hg_log () {
  73. hg -R $1 log --graph --debug >log &&
  74. grep -v 'tag: *default/' log
  75. }
  76. git_log () {
  77. git --git-dir=$1/.git fast-export --branches
  78. }
  79. setup () {
  80. (
  81. echo "[ui]"
  82. echo "username = A U Thor <author@example.com>"
  83. echo "[defaults]"
  84. echo "backout = -d \"0 0\""
  85. echo "commit = -d \"0 0\""
  86. echo "debugrawcommit = -d \"0 0\""
  87. echo "tag = -d \"0 0\""
  88. echo "[extensions]"
  89. echo "hgext.bookmarks ="
  90. echo "hggit ="
  91. echo "graphlog ="
  92. ) >>"$HOME"/.hgrc &&
  93. git config --global receive.denycurrentbranch warn
  94. git config --global remote-hg.hg-git-compat true
  95. git config --global remote-hg.track-branches false
  96. HGEDITOR=true
  97. HGMERGE=true
  98. GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
  99. GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
  100. export HGEDITOR HGMERGE GIT_AUTHOR_DATE GIT_COMMITTER_DATE
  101. }
  102. setup
  103. test_expect_success 'executable bit' '
  104. test_when_finished "rm -rf gitrepo* hgrepo*" &&
  105. (
  106. git init -q gitrepo &&
  107. cd gitrepo &&
  108. echo alpha >alpha &&
  109. chmod 0644 alpha &&
  110. git add alpha &&
  111. git commit -m "add alpha" &&
  112. chmod 0755 alpha &&
  113. git add alpha &&
  114. git commit -m "set executable bit" &&
  115. chmod 0644 alpha &&
  116. git add alpha &&
  117. git commit -m "clear executable bit"
  118. ) &&
  119. for x in hg git
  120. do
  121. (
  122. hg_clone_$x gitrepo hgrepo-$x &&
  123. cd hgrepo-$x &&
  124. hg_log . &&
  125. hg manifest -r 1 -v &&
  126. hg manifest -v
  127. ) >"output-$x" &&
  128. git_clone_$x hgrepo-$x gitrepo2-$x &&
  129. git_log gitrepo2-$x >"log-$x"
  130. done &&
  131. test_cmp output-hg output-git &&
  132. test_cmp log-hg log-git
  133. '
  134. test_expect_success 'symlink' '
  135. test_when_finished "rm -rf gitrepo* hgrepo*" &&
  136. (
  137. git init -q gitrepo &&
  138. cd gitrepo &&
  139. echo alpha >alpha &&
  140. git add alpha &&
  141. git commit -m "add alpha" &&
  142. ln -s alpha beta &&
  143. git add beta &&
  144. git commit -m "add beta"
  145. ) &&
  146. for x in hg git
  147. do
  148. (
  149. hg_clone_$x gitrepo hgrepo-$x &&
  150. cd hgrepo-$x &&
  151. hg_log . &&
  152. hg manifest -v
  153. ) >"output-$x" &&
  154. git_clone_$x hgrepo-$x gitrepo2-$x &&
  155. git_log gitrepo2-$x >"log-$x"
  156. done &&
  157. test_cmp output-hg output-git &&
  158. test_cmp log-hg log-git
  159. '
  160. test_expect_success 'merge conflict 1' '
  161. test_when_finished "rm -rf gitrepo* hgrepo*" &&
  162. (
  163. hg init hgrepo1 &&
  164. cd hgrepo1 &&
  165. echo A >afile &&
  166. hg add afile &&
  167. hg ci -m "origin" &&
  168. echo B >afile &&
  169. hg ci -m "A->B" &&
  170. hg up -r0 &&
  171. echo C >afile &&
  172. hg ci -m "A->C" &&
  173. hg merge -r1 &&
  174. echo C >afile &&
  175. hg resolve -m afile &&
  176. hg ci -m "merge to C"
  177. ) &&
  178. for x in hg git
  179. do
  180. git_clone_$x hgrepo1 gitrepo-$x &&
  181. hg_clone_$x gitrepo-$x hgrepo2-$x &&
  182. hg_log hgrepo2-$x >"hg-log-$x" &&
  183. git_log gitrepo-$x >"git-log-$x"
  184. done &&
  185. test_cmp hg-log-hg hg-log-git &&
  186. test_cmp git-log-hg git-log-git
  187. '
  188. test_expect_success 'merge conflict 2' '
  189. test_when_finished "rm -rf gitrepo* hgrepo*" &&
  190. (
  191. hg init hgrepo1 &&
  192. cd hgrepo1 &&
  193. echo A >afile &&
  194. hg add afile &&
  195. hg ci -m "origin" &&
  196. echo B >afile &&
  197. hg ci -m "A->B" &&
  198. hg up -r0 &&
  199. echo C >afile &&
  200. hg ci -m "A->C" &&
  201. hg merge -r1 || true &&
  202. echo B >afile &&
  203. hg resolve -m afile &&
  204. hg ci -m "merge to B"
  205. ) &&
  206. for x in hg git
  207. do
  208. git_clone_$x hgrepo1 gitrepo-$x &&
  209. hg_clone_$x gitrepo-$x hgrepo2-$x &&
  210. hg_log hgrepo2-$x >"hg-log-$x" &&
  211. git_log gitrepo-$x >"git-log-$x"
  212. done &&
  213. test_cmp hg-log-hg hg-log-git &&
  214. test_cmp git-log-hg git-log-git
  215. '
  216. test_expect_success 'converged merge' '
  217. test_when_finished "rm -rf gitrepo* hgrepo*" &&
  218. (
  219. hg init hgrepo1 &&
  220. cd hgrepo1 &&
  221. echo A >afile &&
  222. hg add afile &&
  223. hg ci -m "origin" &&
  224. echo B >afile &&
  225. hg ci -m "A->B" &&
  226. echo C >afile &&
  227. hg ci -m "B->C" &&
  228. hg up -r0 &&
  229. echo C >afile &&
  230. hg ci -m "A->C" &&
  231. hg merge -r2 || true &&
  232. hg ci -m "merge"
  233. ) &&
  234. for x in hg git
  235. do
  236. git_clone_$x hgrepo1 gitrepo-$x &&
  237. hg_clone_$x gitrepo-$x hgrepo2-$x &&
  238. hg_log hgrepo2-$x >"hg-log-$x" &&
  239. git_log gitrepo-$x >"git-log-$x"
  240. done &&
  241. test_cmp hg-log-hg hg-log-git &&
  242. test_cmp git-log-hg git-log-git
  243. '
  244. test_expect_success 'encoding' '
  245. test_when_finished "rm -rf gitrepo* hgrepo*" &&
  246. (
  247. git init -q gitrepo &&
  248. cd gitrepo &&
  249. echo alpha >alpha &&
  250. git add alpha &&
  251. git commit -m "add älphà" &&
  252. GIT_AUTHOR_NAME="tést èncödîng" &&
  253. export GIT_AUTHOR_NAME &&
  254. echo beta >beta &&
  255. git add beta &&
  256. git commit -m "add beta" &&
  257. echo gamma >gamma &&
  258. git add gamma &&
  259. git commit -m "add gämmâ" &&
  260. : TODO git config i18n.commitencoding latin-1 &&
  261. echo delta >delta &&
  262. git add delta &&
  263. git commit -m "add déltà"
  264. ) &&
  265. for x in hg git
  266. do
  267. hg_clone_$x gitrepo hgrepo-$x &&
  268. git_clone_$x hgrepo-$x gitrepo2-$x &&
  269. HGENCODING=utf-8 hg_log hgrepo-$x >"hg-log-$x" &&
  270. git_log gitrepo2-$x >"git-log-$x"
  271. done &&
  272. test_cmp hg-log-hg hg-log-git &&
  273. test_cmp git-log-hg git-log-git
  274. '
  275. test_expect_success 'file removal' '
  276. test_when_finished "rm -rf gitrepo* hgrepo*" &&
  277. (
  278. git init -q gitrepo &&
  279. cd gitrepo &&
  280. echo alpha >alpha &&
  281. git add alpha &&
  282. git commit -m "add alpha" &&
  283. echo beta >beta &&
  284. git add beta &&
  285. git commit -m "add beta"
  286. mkdir foo &&
  287. echo blah >foo/bar &&
  288. git add foo &&
  289. git commit -m "add foo" &&
  290. git rm alpha &&
  291. git commit -m "remove alpha" &&
  292. git rm foo/bar &&
  293. git commit -m "remove foo/bar"
  294. ) &&
  295. for x in hg git
  296. do
  297. (
  298. hg_clone_$x gitrepo hgrepo-$x &&
  299. cd hgrepo-$x &&
  300. hg_log . &&
  301. hg manifest -r 3 &&
  302. hg manifest
  303. ) >"output-$x" &&
  304. git_clone_$x hgrepo-$x gitrepo2-$x &&
  305. git_log gitrepo2-$x >"log-$x"
  306. done &&
  307. test_cmp output-hg output-git &&
  308. test_cmp log-hg log-git
  309. '
  310. test_expect_success 'git tags' '
  311. test_when_finished "rm -rf gitrepo* hgrepo*" &&
  312. (
  313. git init -q gitrepo &&
  314. cd gitrepo &&
  315. git config receive.denyCurrentBranch ignore &&
  316. echo alpha >alpha &&
  317. git add alpha &&
  318. git commit -m "add alpha" &&
  319. git tag alpha &&
  320. echo beta >beta &&
  321. git add beta &&
  322. git commit -m "add beta" &&
  323. git tag -a -m "added tag beta" beta
  324. ) &&
  325. for x in hg git
  326. do
  327. hg_clone_$x gitrepo hgrepo-$x &&
  328. hg_log hgrepo-$x >"log-$x"
  329. done &&
  330. test_cmp log-hg log-git
  331. '
  332. test_expect_success 'hg author' '
  333. test_when_finished "rm -rf gitrepo* hgrepo*" &&
  334. for x in hg git
  335. do
  336. (
  337. git init -q gitrepo-$x &&
  338. cd gitrepo-$x &&
  339. echo alpha >alpha &&
  340. git add alpha &&
  341. git commit -m "add alpha" &&
  342. git checkout -q -b not-master
  343. ) &&
  344. (
  345. hg_clone_$x gitrepo-$x hgrepo-$x &&
  346. cd hgrepo-$x &&
  347. hg co master &&
  348. echo beta >beta &&
  349. hg add beta &&
  350. hg commit -u "test" -m "add beta" &&
  351. echo gamma >>beta &&
  352. hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
  353. echo gamma >gamma &&
  354. hg add gamma &&
  355. hg commit -u "<test@example.com>" -m "add gamma" &&
  356. echo delta >delta &&
  357. hg add delta &&
  358. hg commit -u "name<test@example.com>" -m "add delta" &&
  359. echo epsilon >epsilon &&
  360. hg add epsilon &&
  361. hg commit -u "name <test@example.com" -m "add epsilon" &&
  362. echo zeta >zeta &&
  363. hg add zeta &&
  364. hg commit -u " test " -m "add zeta" &&
  365. echo eta >eta &&
  366. hg add eta &&
  367. hg commit -u "test < test@example.com >" -m "add eta" &&
  368. echo theta >theta &&
  369. hg add theta &&
  370. hg commit -u "test >test@example.com>" -m "add theta" &&
  371. echo iota >iota &&
  372. hg add iota &&
  373. hg commit -u "test <test <at> example <dot> com>" -m "add iota"
  374. ) &&
  375. hg_push_$x hgrepo-$x gitrepo-$x &&
  376. hg_clone_$x gitrepo-$x hgrepo2-$x &&
  377. hg_log hgrepo2-$x >"hg-log-$x" &&
  378. git_log gitrepo-$x >"git-log-$x"
  379. done &&
  380. test_cmp hg-log-hg hg-log-git &&
  381. test_cmp git-log-hg git-log-git
  382. '
  383. test_expect_success 'hg branch' '
  384. test_when_finished "rm -rf gitrepo* hgrepo*" &&
  385. for x in hg git
  386. do
  387. (
  388. git init -q gitrepo-$x &&
  389. cd gitrepo-$x &&
  390. echo alpha >alpha &&
  391. git add alpha &&
  392. git commit -q -m "add alpha" &&
  393. git checkout -q -b not-master
  394. ) &&
  395. (
  396. hg_clone_$x gitrepo-$x hgrepo-$x &&
  397. cd hgrepo-$x &&
  398. hg -q co master &&
  399. hg mv alpha beta &&
  400. hg -q commit -m "rename alpha to beta" &&
  401. hg branch gamma | grep -v "permanent and global" &&
  402. hg -q commit -m "started branch gamma"
  403. ) &&
  404. hg_push_$x hgrepo-$x gitrepo-$x &&
  405. hg_clone_$x gitrepo-$x hgrepo2-$x &&
  406. hg_log hgrepo2-$x >"hg-log-$x" &&
  407. git_log gitrepo-$x >"git-log-$x"
  408. done &&
  409. test_cmp hg-log-hg hg-log-git &&
  410. test_cmp git-log-hg git-log-git
  411. '
  412. test_expect_success 'hg tags' '
  413. test_when_finished "rm -rf gitrepo* hgrepo*" &&
  414. for x in hg git
  415. do
  416. (
  417. git init -q gitrepo-$x &&
  418. cd gitrepo-$x &&
  419. echo alpha >alpha &&
  420. git add alpha &&
  421. git commit -m "add alpha" &&
  422. git checkout -q -b not-master
  423. ) &&
  424. (
  425. hg_clone_$x gitrepo-$x hgrepo-$x &&
  426. cd hgrepo-$x &&
  427. hg co master &&
  428. hg tag alpha
  429. ) &&
  430. hg_push_$x hgrepo-$x gitrepo-$x &&
  431. hg_clone_$x gitrepo-$x hgrepo2-$x &&
  432. (
  433. git --git-dir=gitrepo-$x/.git tag -l &&
  434. hg_log hgrepo2-$x &&
  435. cat hgrepo2-$x/.hgtags
  436. ) >"output-$x"
  437. done &&
  438. test_cmp output-hg output-git
  439. '
  440. test_done