contrib / remote-helpers / test-hg-hg-git.shon commit remote-hg: trivial cleanups (34d75e7)
   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 -c 'import mercurial'; then
  19        skip_all='skipping remote-hg tests; mercurial not available'
  20        test_done
  21fi
  22
  23if ! python -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::$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::../$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        git checkout -q -b tmp &&
  65        git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
  66        git checkout -q @{-1} &&
  67        git branch -q -D tmp 2> /dev/null || true
  68        )
  69}
  70
  71# push an hg git repo with hg
  72hg_push_hg () {
  73        (
  74        cd $1 &&
  75        hg -q push ../$2 || true
  76        )
  77}
  78
  79hg_log () {
  80        hg -R $1 log --graph --debug >log &&
  81        grep -v 'tag: *default/' log
  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        echo "graphlog ="
 101        ) >> "$HOME"/.hgrc &&
 102        git config --global receive.denycurrentbranch warn
 103        git config --global remote-hg.hg-git-compat true
 104        git config --global remote-hg.track-branches false
 105
 106        HGEDITOR=true
 107        HGMERGE=true
 108
 109        GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
 110        GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
 111        export HGEDITOR HGMERGE GIT_AUTHOR_DATE GIT_COMMITTER_DATE
 112}
 113
 114setup
 115
 116test_expect_success 'executable bit' '
 117        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 153
 154        (
 155        git init -q gitrepo &&
 156        cd gitrepo &&
 157        echo alpha > alpha &&
 158        git add alpha &&
 159        git commit -m "add alpha" &&
 160        ln -s alpha beta &&
 161        git add beta &&
 162        git commit -m "add beta"
 163        ) &&
 164
 165        for x in hg git; do
 166                (
 167                hg_clone_$x gitrepo hgrepo-$x &&
 168                cd hgrepo-$x &&
 169                hg_log . &&
 170                hg manifest -v
 171                ) > output-$x &&
 172
 173                git_clone_$x hgrepo-$x gitrepo2-$x &&
 174                git_log gitrepo2-$x > log-$x
 175        done &&
 176
 177        test_cmp output-hg output-git &&
 178        test_cmp log-hg log-git
 179'
 180
 181test_expect_success 'merge conflict 1' '
 182        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 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 &&
 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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 251
 252        (
 253        hg init hgrepo1 &&
 254        cd hgrepo1 &&
 255        echo A > afile &&
 256        hg add afile &&
 257        hg ci -m "origin" &&
 258
 259        echo B > afile &&
 260        hg ci -m "A->B" &&
 261
 262        echo C > afile &&
 263        hg ci -m "B->C" &&
 264
 265        hg up -r0 &&
 266        echo C > afile &&
 267        hg ci -m "A->C" &&
 268
 269        hg merge -r2 || true &&
 270        hg ci -m "merge"
 271        ) &&
 272
 273        for x in hg git; do
 274                git_clone_$x hgrepo1 gitrepo-$x &&
 275                hg_clone_$x gitrepo-$x hgrepo2-$x &&
 276                hg_log hgrepo2-$x > hg-log-$x &&
 277                git_log gitrepo-$x > git-log-$x
 278        done &&
 279
 280        test_cmp hg-log-hg hg-log-git &&
 281        test_cmp git-log-hg git-log-git
 282'
 283
 284test_expect_success 'encoding' '
 285        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 286
 287        (
 288        git init -q gitrepo &&
 289        cd gitrepo &&
 290
 291        echo alpha > alpha &&
 292        git add alpha &&
 293        git commit -m "add älphà" &&
 294
 295        GIT_AUTHOR_NAME="tést èncödîng" &&
 296        export GIT_AUTHOR_NAME &&
 297        echo beta > beta &&
 298        git add beta &&
 299        git commit -m "add beta" &&
 300
 301        echo gamma > gamma &&
 302        git add gamma &&
 303        git commit -m "add gämmâ" &&
 304
 305        : TODO git config i18n.commitencoding latin-1 &&
 306        echo delta > delta &&
 307        git add delta &&
 308        git commit -m "add déltà"
 309        ) &&
 310
 311        for x in hg git; do
 312                hg_clone_$x gitrepo hgrepo-$x &&
 313                git_clone_$x hgrepo-$x gitrepo2-$x &&
 314
 315                HGENCODING=utf-8 hg_log hgrepo-$x > hg-log-$x &&
 316                git_log gitrepo2-$x > git-log-$x
 317        done &&
 318
 319        test_cmp hg-log-hg hg-log-git &&
 320        test_cmp git-log-hg git-log-git
 321'
 322
 323test_expect_success 'file removal' '
 324        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 325
 326        (
 327        git init -q gitrepo &&
 328        cd gitrepo &&
 329        echo alpha > alpha &&
 330        git add alpha &&
 331        git commit -m "add alpha" &&
 332        echo beta > beta &&
 333        git add beta &&
 334        git commit -m "add beta"
 335        mkdir foo &&
 336        echo blah > foo/bar &&
 337        git add foo &&
 338        git commit -m "add foo" &&
 339        git rm alpha &&
 340        git commit -m "remove alpha" &&
 341        git rm foo/bar &&
 342        git commit -m "remove foo/bar"
 343        ) &&
 344
 345        for x in hg git; do
 346                (
 347                hg_clone_$x gitrepo hgrepo-$x &&
 348                cd hgrepo-$x &&
 349                hg_log . &&
 350                hg manifest -r 3 &&
 351                hg manifest
 352                ) > output-$x &&
 353
 354                git_clone_$x hgrepo-$x gitrepo2-$x &&
 355                git_log gitrepo2-$x > log-$x
 356        done &&
 357
 358        test_cmp output-hg output-git &&
 359        test_cmp log-hg log-git
 360'
 361
 362test_expect_success 'git tags' '
 363        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 364
 365        (
 366        git init -q gitrepo &&
 367        cd gitrepo &&
 368        git config receive.denyCurrentBranch ignore &&
 369        echo alpha > alpha &&
 370        git add alpha &&
 371        git commit -m "add alpha" &&
 372        git tag alpha &&
 373
 374        echo beta > beta &&
 375        git add beta &&
 376        git commit -m "add beta" &&
 377        git tag -a -m "added tag beta" beta
 378        ) &&
 379
 380        for x in hg git; do
 381                hg_clone_$x gitrepo hgrepo-$x &&
 382                hg_log hgrepo-$x > log-$x
 383        done &&
 384
 385        test_cmp log-hg log-git
 386'
 387
 388test_expect_success 'hg author' '
 389        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 390
 391        for x in hg git; do
 392                (
 393                git init -q gitrepo-$x &&
 394                cd gitrepo-$x &&
 395
 396                echo alpha > alpha &&
 397                git add alpha &&
 398                git commit -m "add alpha" &&
 399                git checkout -q -b not-master
 400                ) &&
 401
 402                (
 403                hg_clone_$x gitrepo-$x hgrepo-$x &&
 404                cd hgrepo-$x &&
 405
 406                hg co master &&
 407                echo beta > beta &&
 408                hg add beta &&
 409                hg commit -u "test" -m "add beta" &&
 410
 411                echo gamma >> beta &&
 412                hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
 413
 414                echo gamma > gamma &&
 415                hg add gamma &&
 416                hg commit -u "<test@example.com>" -m "add gamma" &&
 417
 418                echo delta > delta &&
 419                hg add delta &&
 420                hg commit -u "name<test@example.com>" -m "add delta" &&
 421
 422                echo epsilon > epsilon &&
 423                hg add epsilon &&
 424                hg commit -u "name <test@example.com" -m "add epsilon" &&
 425
 426                echo zeta > zeta &&
 427                hg add zeta &&
 428                hg commit -u " test " -m "add zeta" &&
 429
 430                echo eta > eta &&
 431                hg add eta &&
 432                hg commit -u "test < test@example.com >" -m "add eta" &&
 433
 434                echo theta > theta &&
 435                hg add theta &&
 436                hg commit -u "test >test@example.com>" -m "add theta" &&
 437
 438                echo iota > iota &&
 439                hg add iota &&
 440                hg commit -u "test <test <at> example <dot> com>" -m "add iota"
 441                ) &&
 442
 443                hg_push_$x hgrepo-$x gitrepo-$x &&
 444                hg_clone_$x gitrepo-$x hgrepo2-$x &&
 445
 446                hg_log hgrepo2-$x > hg-log-$x &&
 447                git_log gitrepo-$x > git-log-$x
 448        done &&
 449
 450        test_cmp hg-log-hg hg-log-git &&
 451        test_cmp git-log-hg git-log-git
 452'
 453
 454test_expect_success 'hg branch' '
 455        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 456
 457        for x in hg git; do
 458                (
 459                git init -q gitrepo-$x &&
 460                cd gitrepo-$x &&
 461
 462                echo alpha > alpha &&
 463                git add alpha &&
 464                git commit -q -m "add alpha" &&
 465                git checkout -q -b not-master
 466                ) &&
 467
 468                (
 469                hg_clone_$x gitrepo-$x hgrepo-$x &&
 470
 471                cd hgrepo-$x &&
 472                hg -q co master &&
 473                hg mv alpha beta &&
 474                hg -q commit -m "rename alpha to beta" &&
 475                hg branch gamma | grep -v "permanent and global" &&
 476                hg -q commit -m "started branch gamma"
 477                ) &&
 478
 479                hg_push_$x hgrepo-$x gitrepo-$x &&
 480                hg_clone_$x gitrepo-$x hgrepo2-$x &&
 481
 482                hg_log hgrepo2-$x > hg-log-$x &&
 483                git_log gitrepo-$x > git-log-$x
 484        done &&
 485
 486        test_cmp hg-log-hg hg-log-git &&
 487        test_cmp git-log-hg git-log-git
 488'
 489
 490test_expect_success 'hg tags' '
 491        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 492
 493        for x in hg git; do
 494                (
 495                git init -q gitrepo-$x &&
 496                cd gitrepo-$x &&
 497
 498                echo alpha > alpha &&
 499                git add alpha &&
 500                git commit -m "add alpha" &&
 501                git checkout -q -b not-master
 502                ) &&
 503
 504                (
 505                hg_clone_$x gitrepo-$x hgrepo-$x &&
 506
 507                cd hgrepo-$x &&
 508                hg co master &&
 509                hg tag alpha
 510                ) &&
 511
 512                hg_push_$x hgrepo-$x gitrepo-$x &&
 513                hg_clone_$x gitrepo-$x hgrepo2-$x &&
 514
 515                (
 516                git --git-dir=gitrepo-$x/.git tag -l &&
 517                hg_log hgrepo2-$x &&
 518                cat hgrepo2-$x/.hgtags
 519                ) > output-$x
 520        done &&
 521
 522        test_cmp output-hg output-git
 523'
 524
 525test_done