c36b729770ecf95309feb1de7fc4029acdd9d9c5
   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'
  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
  23check () {
  24        echo $3 > expected &&
  25        git --git-dir=$1/.git log --format='%s' -1 $2 > actual
  26        test_cmp expected actual
  27}
  28
  29check_branch () {
  30        echo $3 > expected &&
  31        hg -R $1 log -r $2 --template '{desc}\n' > actual &&
  32        test_cmp expected actual
  33}
  34
  35check_bookmark () {
  36        echo $3 > expected &&
  37        hg -R $1 log -r "bookmark('$2')" --template '{desc}\n' > actual &&
  38        test_cmp expected actual
  39}
  40
  41setup () {
  42        (
  43        echo "[ui]"
  44        echo "username = H G Wells <wells@example.com>"
  45        echo "[extensions]"
  46        echo "mq ="
  47        ) >> "$HOME"/.hgrc &&
  48
  49        GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230" &&
  50        GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" &&
  51        export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
  52}
  53
  54setup
  55
  56test_expect_success 'cloning' '
  57        test_when_finished "rm -rf gitrepo*" &&
  58
  59        (
  60        hg init hgrepo &&
  61        cd hgrepo &&
  62        echo zero > content &&
  63        hg add content &&
  64        hg commit -m zero
  65        ) &&
  66
  67        git clone "hg::hgrepo" gitrepo &&
  68        check gitrepo HEAD zero
  69'
  70
  71test_expect_success 'cloning with branches' '
  72        test_when_finished "rm -rf gitrepo*" &&
  73
  74        (
  75        cd hgrepo &&
  76        hg branch next &&
  77        echo next > content &&
  78        hg commit -m next
  79        ) &&
  80
  81        git clone "hg::hgrepo" gitrepo &&
  82        check gitrepo origin/branches/next next
  83'
  84
  85test_expect_success 'cloning with bookmarks' '
  86        test_when_finished "rm -rf gitrepo*" &&
  87
  88        (
  89        cd hgrepo &&
  90        hg checkout default &&
  91        hg bookmark feature-a &&
  92        echo feature-a > content &&
  93        hg commit -m feature-a
  94        ) &&
  95
  96        git clone "hg::hgrepo" gitrepo &&
  97        check gitrepo origin/feature-a feature-a
  98'
  99
 100test_expect_success 'update bookmark' '
 101        test_when_finished "rm -rf gitrepo*" &&
 102
 103        (
 104        cd hgrepo &&
 105        hg bookmark devel
 106        ) &&
 107
 108        (
 109        git clone "hg::hgrepo" gitrepo &&
 110        cd gitrepo &&
 111        git checkout --quiet devel &&
 112        echo devel > content &&
 113        git commit -a -m devel &&
 114        git push --quiet
 115        ) &&
 116
 117        check_bookmark hgrepo devel devel
 118'
 119
 120# cleanup previous stuff
 121rm -rf hgrepo
 122
 123author_test () {
 124        echo $1 >> content &&
 125        hg commit -u "$2" -m "add $1" &&
 126        echo "$3" >> ../expected
 127}
 128
 129test_expect_success 'authors' '
 130        test_when_finished "rm -rf hgrepo gitrepo" &&
 131
 132        (
 133        hg init hgrepo &&
 134        cd hgrepo &&
 135
 136        touch content &&
 137        hg add content &&
 138
 139        > ../expected &&
 140        author_test alpha "" "H G Wells <wells@example.com>" &&
 141        author_test beta "test" "test <unknown>" &&
 142        author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
 143        author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
 144        author_test delta "name<test@example.com>" "name <test@example.com>" &&
 145        author_test epsilon "name <test@example.com" "name <test@example.com>" &&
 146        author_test zeta " test " "test <unknown>" &&
 147        author_test eta "test < test@example.com >" "test <test@example.com>" &&
 148        author_test theta "test >test@example.com>" "test <test@example.com>" &&
 149        author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
 150        author_test kappa "test@example.com" "Unknown <test@example.com>"
 151        ) &&
 152
 153        git clone "hg::hgrepo" gitrepo &&
 154        git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
 155
 156        test_cmp expected actual
 157'
 158
 159test_expect_success 'strip' '
 160        test_when_finished "rm -rf hgrepo gitrepo" &&
 161
 162        (
 163        hg init hgrepo &&
 164        cd hgrepo &&
 165
 166        echo one >> content &&
 167        hg add content &&
 168        hg commit -m one &&
 169
 170        echo two >> content &&
 171        hg commit -m two
 172        ) &&
 173
 174        git clone "hg::hgrepo" gitrepo &&
 175
 176        (
 177        cd hgrepo &&
 178        hg strip 1 &&
 179
 180        echo three >> content &&
 181        hg commit -m three &&
 182
 183        echo four >> content &&
 184        hg commit -m four
 185        ) &&
 186
 187        (
 188        cd gitrepo &&
 189        git fetch &&
 190        git log --format="%s" origin/master > ../actual
 191        ) &&
 192
 193        hg -R hgrepo log --template "{desc}\n" > expected &&
 194        test_cmp actual expected
 195'
 196
 197test_expect_success 'remote push with master bookmark' '
 198        test_when_finished "rm -rf hgrepo gitrepo*" &&
 199
 200        (
 201        hg init hgrepo &&
 202        cd hgrepo &&
 203        echo zero > content &&
 204        hg add content &&
 205        hg commit -m zero &&
 206        hg bookmark master &&
 207        echo one > content &&
 208        hg commit -m one
 209        ) &&
 210
 211        (
 212        git clone "hg::hgrepo" gitrepo &&
 213        cd gitrepo &&
 214        echo two > content &&
 215        git commit -a -m two &&
 216        git push
 217        ) &&
 218
 219        check_branch hgrepo default two
 220'
 221
 222cat > expected <<EOF
 223changeset:   0:6e2126489d3d
 224tag:         tip
 225user:        A U Thor <author@example.com>
 226date:        Mon Jan 01 00:00:00 2007 +0230
 227summary:     one
 228
 229EOF
 230
 231test_expect_success 'remote push from master branch' '
 232        test_when_finished "rm -rf hgrepo gitrepo*" &&
 233
 234        hg init hgrepo &&
 235
 236        (
 237        git init gitrepo &&
 238        cd gitrepo &&
 239        git remote add origin "hg::../hgrepo" &&
 240        echo one > content &&
 241        git add content &&
 242        git commit -a -m one &&
 243        git push origin master
 244        ) &&
 245
 246        hg -R hgrepo log > actual &&
 247        cat actual &&
 248        test_cmp expected actual &&
 249
 250        check_branch hgrepo default one
 251'
 252
 253GIT_REMOTE_HG_TEST_REMOTE=1
 254export GIT_REMOTE_HG_TEST_REMOTE
 255
 256test_expect_success 'remote cloning' '
 257        test_when_finished "rm -rf gitrepo*" &&
 258
 259        (
 260        hg init hgrepo &&
 261        cd hgrepo &&
 262        echo zero > content &&
 263        hg add content &&
 264        hg commit -m zero
 265        ) &&
 266
 267        git clone "hg::hgrepo" gitrepo &&
 268        check gitrepo HEAD zero
 269'
 270
 271test_expect_success 'remote update bookmark' '
 272        test_when_finished "rm -rf gitrepo*" &&
 273
 274        (
 275        cd hgrepo &&
 276        hg bookmark devel
 277        ) &&
 278
 279        (
 280        git clone "hg::hgrepo" gitrepo &&
 281        cd gitrepo &&
 282        git checkout --quiet devel &&
 283        echo devel > content &&
 284        git commit -a -m devel &&
 285        git push --quiet
 286        ) &&
 287
 288        check_bookmark hgrepo devel devel
 289'
 290
 291test_done