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