contrib / remote-helpers / test-hg-bidi.shon commit Merge branch 'fc/untracked-zsh-prompt' into maint (1a475c4)
   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 bidirectionality of 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
  23# clone to a git repo
  24git_clone () {
  25        hg -R $1 bookmark -f -r tip master &&
  26        git clone -q "hg::$PWD/$1" $2
  27}
  28
  29# clone to an hg repo
  30hg_clone () {
  31        (
  32        hg init $2 &&
  33        cd $1 &&
  34        git push -q "hg::$PWD/../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
  35        ) &&
  36
  37        (cd $2 && hg -q update)
  38}
  39
  40# push an hg repo
  41hg_push () {
  42        (
  43        cd $2
  44        old=$(git symbolic-ref --short HEAD)
  45        git checkout -q -b tmp &&
  46        git fetch -q "hg::$PWD/../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
  47        git checkout -q $old &&
  48        git branch -q -D tmp 2> /dev/null || true
  49        )
  50}
  51
  52hg_log () {
  53        hg -R $1 log --graph --debug | grep -v 'tag: *default/'
  54}
  55
  56setup () {
  57        (
  58        echo "[ui]"
  59        echo "username = A U Thor <author@example.com>"
  60        echo "[defaults]"
  61        echo "backout = -d \"0 0\""
  62        echo "commit = -d \"0 0\""
  63        echo "debugrawcommit = -d \"0 0\""
  64        echo "tag = -d \"0 0\""
  65        ) >> "$HOME"/.hgrc &&
  66        git config --global remote-hg.hg-git-compat true
  67
  68        HGEDITOR=/usr/bin/true
  69        GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
  70        GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
  71        export HGEDITOR GIT_AUTHOR_DATE GIT_COMMITTER_DATE
  72}
  73
  74setup
  75
  76test_expect_success 'encoding' '
  77        mkdir -p tmp && cd tmp &&
  78        test_when_finished "cd .. && rm -rf tmp" &&
  79
  80        (
  81        git init -q gitrepo &&
  82        cd gitrepo &&
  83
  84        echo alpha > alpha &&
  85        git add alpha &&
  86        git commit -m "add älphà" &&
  87
  88        GIT_AUTHOR_NAME="tést èncödîng" &&
  89        export GIT_AUTHOR_NAME &&
  90        echo beta > beta &&
  91        git add beta &&
  92        git commit -m "add beta" &&
  93
  94        echo gamma > gamma &&
  95        git add gamma &&
  96        git commit -m "add gämmâ" &&
  97
  98        : TODO git config i18n.commitencoding latin-1 &&
  99        echo delta > delta &&
 100        git add delta &&
 101        git commit -m "add déltà"
 102        ) &&
 103
 104        hg_clone gitrepo hgrepo &&
 105        git_clone hgrepo gitrepo2 &&
 106        hg_clone gitrepo2 hgrepo2 &&
 107
 108        HGENCODING=utf-8 hg_log hgrepo > expected &&
 109        HGENCODING=utf-8 hg_log hgrepo2 > actual &&
 110
 111        test_cmp expected actual
 112'
 113
 114test_expect_success 'file removal' '
 115        mkdir -p tmp && cd tmp &&
 116        test_when_finished "cd .. && rm -rf tmp" &&
 117
 118        (
 119        git init -q gitrepo &&
 120        cd gitrepo &&
 121        echo alpha > alpha &&
 122        git add alpha &&
 123        git commit -m "add alpha" &&
 124        echo beta > beta &&
 125        git add beta &&
 126        git commit -m "add beta"
 127        mkdir foo &&
 128        echo blah > foo/bar &&
 129        git add foo &&
 130        git commit -m "add foo" &&
 131        git rm alpha &&
 132        git commit -m "remove alpha" &&
 133        git rm foo/bar &&
 134        git commit -m "remove foo/bar"
 135        ) &&
 136
 137        hg_clone gitrepo hgrepo &&
 138        git_clone hgrepo gitrepo2 &&
 139        hg_clone gitrepo2 hgrepo2 &&
 140
 141        hg_log hgrepo > expected &&
 142        hg_log hgrepo2 > actual &&
 143
 144        test_cmp expected actual
 145'
 146
 147test_expect_success 'git tags' '
 148        mkdir -p tmp && cd tmp &&
 149        test_when_finished "cd .. && rm -rf tmp" &&
 150
 151        (
 152        git init -q gitrepo &&
 153        cd gitrepo &&
 154        git config receive.denyCurrentBranch ignore &&
 155        echo alpha > alpha &&
 156        git add alpha &&
 157        git commit -m "add alpha" &&
 158        git tag alpha &&
 159
 160        echo beta > beta &&
 161        git add beta &&
 162        git commit -m "add beta" &&
 163        git tag -a -m "added tag beta" beta
 164        ) &&
 165
 166        hg_clone gitrepo hgrepo &&
 167        git_clone hgrepo gitrepo2 &&
 168        hg_clone gitrepo2 hgrepo2 &&
 169
 170        hg_log hgrepo > expected &&
 171        hg_log hgrepo2 > actual &&
 172
 173        test_cmp expected actual
 174'
 175
 176test_expect_success 'hg branch' '
 177        mkdir -p tmp && cd tmp &&
 178        test_when_finished "cd .. && rm -rf tmp" &&
 179
 180        (
 181        git init -q gitrepo &&
 182        cd gitrepo &&
 183
 184        echo alpha > alpha &&
 185        git add alpha &&
 186        git commit -q -m "add alpha" &&
 187        git checkout -q -b not-master
 188        ) &&
 189
 190        (
 191        hg_clone gitrepo hgrepo &&
 192
 193        cd hgrepo &&
 194        hg -q co master &&
 195        hg mv alpha beta &&
 196        hg -q commit -m "rename alpha to beta" &&
 197        hg branch gamma | grep -v "permanent and global" &&
 198        hg -q commit -m "started branch gamma"
 199        ) &&
 200
 201        hg_push hgrepo gitrepo &&
 202        hg_clone gitrepo hgrepo2 &&
 203
 204        : TODO, avoid "master" bookmark &&
 205        (cd hgrepo2 && hg checkout gamma) &&
 206
 207        hg_log hgrepo > expected &&
 208        hg_log hgrepo2 > actual &&
 209
 210        test_cmp expected actual
 211'
 212
 213test_expect_success 'hg tags' '
 214        mkdir -p tmp && cd tmp &&
 215        test_when_finished "cd .. && rm -rf tmp" &&
 216
 217        (
 218        git init -q gitrepo &&
 219        cd gitrepo &&
 220
 221        echo alpha > alpha &&
 222        git add alpha &&
 223        git commit -m "add alpha" &&
 224        git checkout -q -b not-master
 225        ) &&
 226
 227        (
 228        hg_clone gitrepo hgrepo &&
 229
 230        cd hgrepo &&
 231        hg co master &&
 232        hg tag alpha
 233        ) &&
 234
 235        hg_push hgrepo gitrepo &&
 236        hg_clone gitrepo hgrepo2 &&
 237
 238        hg_log hgrepo > expected &&
 239        hg_log hgrepo2 > actual &&
 240
 241        test_cmp expected actual
 242'
 243
 244test_done