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