contrib / remote-helpers / test-hg-hg-git.shon commit remote-helpers: tests: general improvements (531594e)
   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::$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=true
 108        HGMERGE=true
 109
 110        GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
 111        GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
 112        export HGEDITOR HGMERGE GIT_AUTHOR_DATE GIT_COMMITTER_DATE
 113}
 114
 115setup
 116
 117test_expect_success 'executable bit' '
 118        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 184
 185        (
 186        hg init hgrepo1 &&
 187        cd hgrepo1 &&
 188        echo A > afile &&
 189        hg add afile &&
 190        hg ci -m "origin" &&
 191
 192        echo B > afile &&
 193        hg ci -m "A->B" &&
 194
 195        hg up -r0 &&
 196        echo C > afile &&
 197        hg ci -m "A->C" &&
 198
 199        hg merge -r1 &&
 200        echo C > afile &&
 201        hg resolve -m afile &&
 202        hg ci -m "merge to C"
 203        ) &&
 204
 205        for x in hg git; do
 206                git_clone_$x hgrepo1 gitrepo-$x &&
 207                hg_clone_$x gitrepo-$x hgrepo2-$x &&
 208                hg_log hgrepo2-$x > hg-log-$x &&
 209                git_log gitrepo-$x > git-log-$x
 210        done &&
 211
 212        test_cmp hg-log-hg hg-log-git &&
 213        test_cmp git-log-hg git-log-git
 214'
 215
 216test_expect_success 'merge conflict 2' '
 217        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 287
 288        (
 289        git init -q gitrepo &&
 290        cd gitrepo &&
 291
 292        echo alpha > alpha &&
 293        git add alpha &&
 294        git commit -m "add älphà" &&
 295
 296        GIT_AUTHOR_NAME="tést èncödîng" &&
 297        export GIT_AUTHOR_NAME &&
 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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 326
 327        (
 328        git init -q gitrepo &&
 329        cd gitrepo &&
 330        echo alpha > alpha &&
 331        git add alpha &&
 332        git commit -m "add alpha" &&
 333        echo beta > beta &&
 334        git add beta &&
 335        git commit -m "add beta"
 336        mkdir foo &&
 337        echo blah > foo/bar &&
 338        git add foo &&
 339        git commit -m "add foo" &&
 340        git rm alpha &&
 341        git commit -m "remove alpha" &&
 342        git rm foo/bar &&
 343        git commit -m "remove foo/bar"
 344        ) &&
 345
 346        for x in hg git; do
 347                (
 348                hg_clone_$x gitrepo hgrepo-$x &&
 349                cd hgrepo-$x &&
 350                hg_log . &&
 351                hg manifest -r 3 &&
 352                hg manifest
 353                ) > output-$x &&
 354
 355                git_clone_$x hgrepo-$x gitrepo2-$x &&
 356                git_log gitrepo2-$x > log-$x
 357        done &&
 358
 359        test_cmp output-hg output-git &&
 360        test_cmp log-hg log-git
 361'
 362
 363test_expect_success 'git tags' '
 364        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 365
 366        (
 367        git init -q gitrepo &&
 368        cd gitrepo &&
 369        git config receive.denyCurrentBranch ignore &&
 370        echo alpha > alpha &&
 371        git add alpha &&
 372        git commit -m "add alpha" &&
 373        git tag alpha &&
 374
 375        echo beta > beta &&
 376        git add beta &&
 377        git commit -m "add beta" &&
 378        git tag -a -m "added tag beta" beta
 379        ) &&
 380
 381        for x in hg git; do
 382                hg_clone_$x gitrepo hgrepo-$x &&
 383                hg_log hgrepo-$x > log-$x
 384        done &&
 385
 386        test_cmp log-hg log-git
 387'
 388
 389test_expect_success 'hg author' '
 390        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 391
 392        for x in hg git; do
 393                (
 394                git init -q gitrepo-$x &&
 395                cd gitrepo-$x &&
 396
 397                echo alpha > alpha &&
 398                git add alpha &&
 399                git commit -m "add alpha" &&
 400                git checkout -q -b not-master
 401                ) &&
 402
 403                (
 404                hg_clone_$x gitrepo-$x hgrepo-$x &&
 405                cd hgrepo-$x &&
 406
 407                hg co master &&
 408                echo beta > beta &&
 409                hg add beta &&
 410                hg commit -u "test" -m "add beta" &&
 411
 412                echo gamma >> beta &&
 413                hg commit -u "test <test@example.com> (comment)" -m "modify beta" &&
 414
 415                echo gamma > gamma &&
 416                hg add gamma &&
 417                hg commit -u "<test@example.com>" -m "add gamma" &&
 418
 419                echo delta > delta &&
 420                hg add delta &&
 421                hg commit -u "name<test@example.com>" -m "add delta" &&
 422
 423                echo epsilon > epsilon &&
 424                hg add epsilon &&
 425                hg commit -u "name <test@example.com" -m "add epsilon" &&
 426
 427                echo zeta > zeta &&
 428                hg add zeta &&
 429                hg commit -u " test " -m "add zeta" &&
 430
 431                echo eta > eta &&
 432                hg add eta &&
 433                hg commit -u "test < test@example.com >" -m "add eta" &&
 434
 435                echo theta > theta &&
 436                hg add theta &&
 437                hg commit -u "test >test@example.com>" -m "add theta" &&
 438
 439                echo iota > iota &&
 440                hg add iota &&
 441                hg commit -u "test <test <at> example <dot> com>" -m "add iota"
 442                ) &&
 443
 444                hg_push_$x hgrepo-$x gitrepo-$x &&
 445                hg_clone_$x gitrepo-$x hgrepo2-$x &&
 446
 447                hg_log hgrepo2-$x > hg-log-$x &&
 448                git_log gitrepo-$x > git-log-$x
 449        done &&
 450
 451        test_cmp hg-log-hg hg-log-git &&
 452        test_cmp git-log-hg git-log-git
 453'
 454
 455test_expect_success 'hg branch' '
 456        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 457
 458        for x in hg git; do
 459                (
 460                git init -q gitrepo-$x &&
 461                cd gitrepo-$x &&
 462
 463                echo alpha > alpha &&
 464                git add alpha &&
 465                git commit -q -m "add alpha" &&
 466                git checkout -q -b not-master
 467                ) &&
 468
 469                (
 470                hg_clone_$x gitrepo-$x hgrepo-$x &&
 471
 472                cd hgrepo-$x &&
 473                hg -q co master &&
 474                hg mv alpha beta &&
 475                hg -q commit -m "rename alpha to beta" &&
 476                hg branch gamma | grep -v "permanent and global" &&
 477                hg -q commit -m "started branch gamma"
 478                ) &&
 479
 480                hg_push_$x hgrepo-$x gitrepo-$x &&
 481                hg_clone_$x gitrepo-$x hgrepo2-$x &&
 482
 483                hg_log hgrepo2-$x > hg-log-$x &&
 484                git_log gitrepo-$x > git-log-$x
 485        done &&
 486
 487        test_cmp hg-log-hg hg-log-git &&
 488        test_cmp git-log-hg git-log-git
 489'
 490
 491test_expect_success 'hg tags' '
 492        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 493
 494        for x in hg git; do
 495                (
 496                git init -q gitrepo-$x &&
 497                cd gitrepo-$x &&
 498
 499                echo alpha > alpha &&
 500                git add alpha &&
 501                git commit -m "add alpha" &&
 502                git checkout -q -b not-master
 503                ) &&
 504
 505                (
 506                hg_clone_$x gitrepo-$x hgrepo-$x &&
 507
 508                cd hgrepo-$x &&
 509                hg co master &&
 510                hg tag alpha
 511                ) &&
 512
 513                hg_push_$x hgrepo-$x gitrepo-$x &&
 514                hg_clone_$x gitrepo-$x hgrepo2-$x &&
 515
 516                (
 517                git --git-dir=gitrepo-$x/.git tag -l &&
 518                hg_log hgrepo2-$x &&
 519                cat hgrepo2-$x/.hgtags
 520                ) > output-$x
 521        done &&
 522
 523        test_cmp output-hg output-git
 524'
 525
 526test_done