676b1ab47820b29f6596429de0616bfb305f6c9c
   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 -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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
  81
  82        (
  83        git init -q gitrepo &&
  84        cd gitrepo &&
  85
  86        echo alpha > alpha &&
  87        git add alpha &&
  88        git commit -m "add älphà" &&
  89
  90        GIT_AUTHOR_NAME="tést èncödîng" &&
  91        export GIT_AUTHOR_NAME &&
  92        echo beta > beta &&
  93        git add beta &&
  94        git commit -m "add beta" &&
  95
  96        echo gamma > gamma &&
  97        git add gamma &&
  98        git commit -m "add gämmâ" &&
  99
 100        : TODO git config i18n.commitencoding latin-1 &&
 101        echo delta > delta &&
 102        git add delta &&
 103        git commit -m "add déltà"
 104        ) &&
 105
 106        hg_clone gitrepo hgrepo &&
 107        git_clone hgrepo gitrepo2 &&
 108        hg_clone gitrepo2 hgrepo2 &&
 109
 110        HGENCODING=utf-8 hg_log hgrepo > expected &&
 111        HGENCODING=utf-8 hg_log hgrepo2 > actual &&
 112
 113        test_cmp expected actual
 114'
 115
 116test_expect_success 'file removal' '
 117        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 118
 119        (
 120        git init -q gitrepo &&
 121        cd gitrepo &&
 122        echo alpha > alpha &&
 123        git add alpha &&
 124        git commit -m "add alpha" &&
 125        echo beta > beta &&
 126        git add beta &&
 127        git commit -m "add beta"
 128        mkdir foo &&
 129        echo blah > foo/bar &&
 130        git add foo &&
 131        git commit -m "add foo" &&
 132        git rm alpha &&
 133        git commit -m "remove alpha" &&
 134        git rm foo/bar &&
 135        git commit -m "remove foo/bar"
 136        ) &&
 137
 138        hg_clone gitrepo hgrepo &&
 139        git_clone hgrepo gitrepo2 &&
 140        hg_clone gitrepo2 hgrepo2 &&
 141
 142        hg_log hgrepo > expected &&
 143        hg_log hgrepo2 > actual &&
 144
 145        test_cmp expected actual
 146'
 147
 148test_expect_success 'git tags' '
 149        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 178
 179        (
 180        git init -q gitrepo &&
 181        cd gitrepo &&
 182
 183        echo alpha > alpha &&
 184        git add alpha &&
 185        git commit -q -m "add alpha" &&
 186        git checkout -q -b not-master
 187        ) &&
 188
 189        (
 190        hg_clone gitrepo hgrepo &&
 191
 192        cd hgrepo &&
 193        hg -q co master &&
 194        hg mv alpha beta &&
 195        hg -q commit -m "rename alpha to beta" &&
 196        hg branch gamma | grep -v "permanent and global" &&
 197        hg -q commit -m "started branch gamma"
 198        ) &&
 199
 200        hg_push hgrepo gitrepo &&
 201        hg_clone gitrepo hgrepo2 &&
 202
 203        : Back to the common revision &&
 204        (cd hgrepo && hg checkout default) &&
 205
 206        hg_log hgrepo > expected &&
 207        hg_log hgrepo2 > actual &&
 208
 209        test_cmp expected actual
 210'
 211
 212test_expect_success 'hg tags' '
 213        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 214
 215        (
 216        git init -q gitrepo &&
 217        cd gitrepo &&
 218
 219        echo alpha > alpha &&
 220        git add alpha &&
 221        git commit -m "add alpha" &&
 222        git checkout -q -b not-master
 223        ) &&
 224
 225        (
 226        hg_clone gitrepo hgrepo &&
 227
 228        cd hgrepo &&
 229        hg co master &&
 230        hg tag alpha
 231        ) &&
 232
 233        hg_push hgrepo gitrepo &&
 234        hg_clone gitrepo hgrepo2 &&
 235
 236        hg_log hgrepo > expected &&
 237        hg_log hgrepo2 > actual &&
 238
 239        test_cmp expected actual
 240'
 241
 242test_done