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