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