contrib / remote-helpers / test-hg.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'
  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        (
  25        cd $1 &&
  26        git log --format='%s' -1 &&
  27        git symbolic-ref HEAD
  28        ) > actual &&
  29        (
  30        echo $2 &&
  31        echo "refs/heads/$3"
  32        ) > expected &&
  33        test_cmp expected actual
  34}
  35
  36setup () {
  37        (
  38        echo "[ui]"
  39        echo "username = H G Wells <wells@example.com>"
  40        echo "[extensions]"
  41        echo "mq ="
  42        ) >> "$HOME"/.hgrc
  43}
  44
  45setup
  46
  47test_expect_success 'cloning' '
  48        test_when_finished "rm -rf gitrepo*" &&
  49
  50        (
  51        hg init hgrepo &&
  52        cd hgrepo &&
  53        echo zero > content &&
  54        hg add content &&
  55        hg commit -m zero
  56        ) &&
  57
  58        git clone "hg::hgrepo" gitrepo &&
  59        check gitrepo zero master
  60'
  61
  62test_expect_success 'cloning with branches' '
  63        test_when_finished "rm -rf gitrepo*" &&
  64
  65        (
  66        cd hgrepo &&
  67        hg branch next &&
  68        echo next > content &&
  69        hg commit -m next
  70        ) &&
  71
  72        git clone "hg::hgrepo" gitrepo &&
  73        check gitrepo next next &&
  74
  75        (cd hgrepo && hg checkout default) &&
  76
  77        git clone "hg::hgrepo" gitrepo2 &&
  78        check gitrepo2 zero master
  79'
  80
  81test_expect_success 'cloning with bookmarks' '
  82        test_when_finished "rm -rf gitrepo*" &&
  83
  84        (
  85        cd hgrepo &&
  86        hg bookmark feature-a &&
  87        echo feature-a > content &&
  88        hg commit -m feature-a
  89        ) &&
  90
  91        git clone "hg::hgrepo" gitrepo &&
  92        check gitrepo feature-a feature-a
  93'
  94
  95test_expect_success 'cloning with detached head' '
  96        test_when_finished "rm -rf gitrepo*" &&
  97
  98        (
  99        cd hgrepo &&
 100        hg update -r 0
 101        ) &&
 102
 103        git clone "hg::hgrepo" gitrepo &&
 104        check gitrepo zero master
 105'
 106
 107test_expect_success 'update bookmark' '
 108        test_when_finished "rm -rf gitrepo*" &&
 109
 110        (
 111        cd hgrepo &&
 112        hg bookmark devel
 113        ) &&
 114
 115        (
 116        git clone "hg::hgrepo" gitrepo &&
 117        cd gitrepo &&
 118        git checkout --quiet devel &&
 119        echo devel > content &&
 120        git commit -a -m devel &&
 121        git push --quiet
 122        ) &&
 123
 124        hg -R hgrepo bookmarks | egrep "devel[   ]+3:"
 125'
 126
 127# cleanup previous stuff
 128rm -rf hgrepo
 129
 130author_test () {
 131        echo $1 >> content &&
 132        hg commit -u "$2" -m "add $1" &&
 133        echo "$3" >> ../expected
 134}
 135
 136test_expect_success 'authors' '
 137        test_when_finished "rm -rf hgrepo gitrepo" &&
 138
 139        (
 140        hg init hgrepo &&
 141        cd hgrepo &&
 142
 143        touch content &&
 144        hg add content &&
 145
 146        > ../expected &&
 147        author_test alpha "" "H G Wells <wells@example.com>" &&
 148        author_test beta "test" "test <unknown>" &&
 149        author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
 150        author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
 151        author_test delta "name<test@example.com>" "name <test@example.com>" &&
 152        author_test epsilon "name <test@example.com" "name <test@example.com>" &&
 153        author_test zeta " test " "test <unknown>" &&
 154        author_test eta "test < test@example.com >" "test <test@example.com>" &&
 155        author_test theta "test >test@example.com>" "test <test@example.com>" &&
 156        author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
 157        author_test kappa "test@example.com" "Unknown <test@example.com>"
 158        ) &&
 159
 160        git clone "hg::hgrepo" gitrepo &&
 161        git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
 162
 163        test_cmp expected actual
 164'
 165
 166test_expect_success 'strip' '
 167        test_when_finished "rm -rf hgrepo gitrepo" &&
 168
 169        (
 170        hg init hgrepo &&
 171        cd hgrepo &&
 172
 173        echo one >> content &&
 174        hg add content &&
 175        hg commit -m one &&
 176
 177        echo two >> content &&
 178        hg commit -m two
 179        ) &&
 180
 181        git clone "hg::hgrepo" gitrepo &&
 182
 183        (
 184        cd hgrepo &&
 185        hg strip 1 &&
 186
 187        echo three >> content &&
 188        hg commit -m three &&
 189
 190        echo four >> content &&
 191        hg commit -m four
 192        ) &&
 193
 194        (
 195        cd gitrepo &&
 196        git fetch &&
 197        git log --format="%s" origin/master > ../actual
 198        ) &&
 199
 200        hg -R hgrepo log --template "{desc}\n" > expected &&
 201        test_cmp actual expected
 202'
 203
 204test_done