contrib / remote-helpers / test-hg.shon commit remote-helpers: test: cleanup style (dde67d7)
   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        ) >> "$HOME"/.hgrc
  41}
  42
  43setup
  44
  45test_expect_success 'cloning' '
  46        test_when_finished "rm -rf gitrepo*" &&
  47
  48        (
  49        hg init hgrepo &&
  50        cd hgrepo &&
  51        echo zero > content &&
  52        hg add content &&
  53        hg commit -m zero
  54        ) &&
  55
  56        git clone "hg::$PWD/hgrepo" gitrepo &&
  57        check gitrepo zero master
  58'
  59
  60test_expect_success 'cloning with branches' '
  61        test_when_finished "rm -rf gitrepo*" &&
  62
  63        (
  64        cd hgrepo &&
  65        hg branch next &&
  66        echo next > content &&
  67        hg commit -m next
  68        ) &&
  69
  70        git clone "hg::$PWD/hgrepo" gitrepo &&
  71        check gitrepo next next &&
  72
  73        (cd hgrepo && hg checkout default) &&
  74
  75        git clone "hg::$PWD/hgrepo" gitrepo2 &&
  76        check gitrepo2 zero master
  77'
  78
  79test_expect_success 'cloning with bookmarks' '
  80        test_when_finished "rm -rf gitrepo*" &&
  81
  82        (
  83        cd hgrepo &&
  84        hg bookmark feature-a &&
  85        echo feature-a > content &&
  86        hg commit -m feature-a
  87        ) &&
  88
  89        git clone "hg::$PWD/hgrepo" gitrepo &&
  90        check gitrepo feature-a feature-a
  91'
  92
  93test_expect_success 'cloning with detached head' '
  94        test_when_finished "rm -rf gitrepo*" &&
  95
  96        (
  97        cd hgrepo &&
  98        hg update -r 0
  99        ) &&
 100
 101        git clone "hg::$PWD/hgrepo" gitrepo &&
 102        check gitrepo zero master
 103'
 104
 105test_expect_success 'update bookmark' '
 106        test_when_finished "rm -rf gitrepo*" &&
 107
 108        (
 109        cd hgrepo &&
 110        hg bookmark devel
 111        ) &&
 112
 113        (
 114        git clone "hg::$PWD/hgrepo" gitrepo &&
 115        cd gitrepo &&
 116        git checkout --quiet devel &&
 117        echo devel > content &&
 118        git commit -a -m devel &&
 119        git push --quiet
 120        ) &&
 121
 122        hg -R hgrepo bookmarks | egrep "devel[   ]+3:"
 123'
 124
 125author_test () {
 126        echo $1 >> content &&
 127        hg commit -u "$2" -m "add $1" &&
 128        echo "$3" >> ../expected
 129}
 130
 131test_expect_success 'authors' '
 132        mkdir -p tmp && cd tmp &&
 133        test_when_finished "cd .. && rm -rf tmp" &&
 134
 135        (
 136        hg init hgrepo &&
 137        cd hgrepo &&
 138
 139        touch content &&
 140        hg add content &&
 141
 142        author_test alpha "" "H G Wells <wells@example.com>" &&
 143        author_test beta "test" "test <unknown>" &&
 144        author_test beta "test <test@example.com> (comment)" "test <test@example.com>" &&
 145        author_test gamma "<test@example.com>" "Unknown <test@example.com>" &&
 146        author_test delta "name<test@example.com>" "name <test@example.com>" &&
 147        author_test epsilon "name <test@example.com" "name <test@example.com>" &&
 148        author_test zeta " test " "test <unknown>" &&
 149        author_test eta "test < test@example.com >" "test <test@example.com>" &&
 150        author_test theta "test >test@example.com>" "test <test@example.com>" &&
 151        author_test iota "test < test <at> example <dot> com>" "test <unknown>" &&
 152        author_test kappa "test@example.com" "Unknown <test@example.com>"
 153        ) &&
 154
 155        git clone "hg::$PWD/hgrepo" gitrepo &&
 156        git --git-dir=gitrepo/.git log --reverse --format="%an <%ae>" > actual &&
 157
 158        test_cmp expected actual
 159'
 160
 161test_done