contrib / remote-helpers / test-hg-bidi.shon commit remote-bzr: make bzr branches configurable per-repo (a11b0ac)
   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::$1" $2
  26}
  27
  28# clone to an hg repo
  29hg_clone () {
  30        (
  31        hg init $2 &&
  32        cd $1 &&
  33        git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
  34        ) &&
  35
  36        (cd $2 && hg -q update)
  37}
  38
  39# push an hg repo
  40hg_push () {
  41        (
  42        cd $2
  43        git checkout -q -b tmp &&
  44        git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
  45        git checkout -q @{-1} &&
  46        git branch -q -D tmp 2> /dev/null || true
  47        )
  48}
  49
  50hg_log () {
  51        hg -R $1 log --graph --debug
  52}
  53
  54setup () {
  55        (
  56        echo "[ui]"
  57        echo "username = A U Thor <author@example.com>"
  58        echo "[defaults]"
  59        echo "backout = -d \"0 0\""
  60        echo "commit = -d \"0 0\""
  61        echo "debugrawcommit = -d \"0 0\""
  62        echo "tag = -d \"0 0\""
  63        echo "[extensions]"
  64        echo "graphlog ="
  65        ) >> "$HOME"/.hgrc &&
  66        git config --global remote-hg.hg-git-compat true
  67        git config --global remote-hg.track-branches true
  68
  69        HGEDITOR=/usr/bin/true
  70        GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
  71        GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
  72        export HGEDITOR GIT_AUTHOR_DATE GIT_COMMITTER_DATE
  73}
  74
  75setup
  76
  77test_expect_success 'encoding' '
  78        test_when_finished "rm -rf gitrepo* hgrepo*" &&
  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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 116
 117        (
 118        git init -q gitrepo &&
 119        cd gitrepo &&
 120        echo alpha > alpha &&
 121        git add alpha &&
 122        git commit -m "add alpha" &&
 123        echo beta > beta &&
 124        git add beta &&
 125        git commit -m "add beta"
 126        mkdir foo &&
 127        echo blah > foo/bar &&
 128        git add foo &&
 129        git commit -m "add foo" &&
 130        git rm alpha &&
 131        git commit -m "remove alpha" &&
 132        git rm foo/bar &&
 133        git commit -m "remove foo/bar"
 134        ) &&
 135
 136        hg_clone gitrepo hgrepo &&
 137        git_clone hgrepo gitrepo2 &&
 138        hg_clone gitrepo2 hgrepo2 &&
 139
 140        hg_log hgrepo > expected &&
 141        hg_log hgrepo2 > actual &&
 142
 143        test_cmp expected actual
 144'
 145
 146test_expect_success 'git tags' '
 147        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 148
 149        (
 150        git init -q gitrepo &&
 151        cd gitrepo &&
 152        git config receive.denyCurrentBranch ignore &&
 153        echo alpha > alpha &&
 154        git add alpha &&
 155        git commit -m "add alpha" &&
 156        git tag alpha &&
 157
 158        echo beta > beta &&
 159        git add beta &&
 160        git commit -m "add beta" &&
 161        git tag -a -m "added tag beta" beta
 162        ) &&
 163
 164        hg_clone gitrepo hgrepo &&
 165        git_clone hgrepo gitrepo2 &&
 166        hg_clone gitrepo2 hgrepo2 &&
 167
 168        hg_log hgrepo > expected &&
 169        hg_log hgrepo2 > actual &&
 170
 171        test_cmp expected actual
 172'
 173
 174test_expect_success 'hg branch' '
 175        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 176
 177        (
 178        git init -q gitrepo &&
 179        cd gitrepo &&
 180
 181        echo alpha > alpha &&
 182        git add alpha &&
 183        git commit -q -m "add alpha" &&
 184        git checkout -q -b not-master
 185        ) &&
 186
 187        (
 188        hg_clone gitrepo hgrepo &&
 189
 190        cd hgrepo &&
 191        hg -q co default &&
 192        hg mv alpha beta &&
 193        hg -q commit -m "rename alpha to beta" &&
 194        hg branch gamma | grep -v "permanent and global" &&
 195        hg -q commit -m "started branch gamma"
 196        ) &&
 197
 198        hg_push hgrepo gitrepo &&
 199        hg_clone gitrepo hgrepo2 &&
 200
 201        : Back to the common revision &&
 202        (cd hgrepo && hg checkout default) &&
 203
 204        hg_log hgrepo > expected &&
 205        hg_log hgrepo2 > actual &&
 206
 207        test_cmp expected actual
 208'
 209
 210test_expect_success 'hg tags' '
 211        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 212
 213        (
 214        git init -q gitrepo &&
 215        cd gitrepo &&
 216
 217        echo alpha > alpha &&
 218        git add alpha &&
 219        git commit -m "add alpha" &&
 220        git checkout -q -b not-master
 221        ) &&
 222
 223        (
 224        hg_clone gitrepo hgrepo &&
 225
 226        cd hgrepo &&
 227        hg co default &&
 228        hg tag alpha
 229        ) &&
 230
 231        hg_push hgrepo gitrepo &&
 232        hg_clone gitrepo hgrepo2 &&
 233
 234        hg_log hgrepo > expected &&
 235        hg_log hgrepo2 > actual &&
 236
 237        test_cmp expected actual
 238'
 239
 240test_done