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