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