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