contrib / remote-helpers / test-hg-bidi.shon commit Sync with maint (d30acb7)
   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
  11test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
  12. "$TEST_DIRECTORY"/test-lib.sh
  13
  14if ! test_have_prereq PYTHON
  15then
  16        skip_all='skipping remote-hg tests; python not available'
  17        test_done
  18fi
  19
  20if ! python -c 'import mercurial'
  21then
  22        skip_all='skipping remote-hg tests; mercurial not available'
  23        test_done
  24fi
  25
  26# clone to a git repo
  27git_clone () {
  28        git clone -q "hg::$1" $2
  29}
  30
  31# clone to an hg repo
  32hg_clone () {
  33        (
  34        hg init $2 &&
  35        cd $1 &&
  36        git push -q "hg::../$2" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*'
  37        ) &&
  38
  39        (cd $2 && hg -q update)
  40}
  41
  42# push an hg repo
  43hg_push () {
  44        (
  45        cd $2
  46        git checkout -q -b tmp &&
  47        git fetch -q "hg::../$1" 'refs/tags/*:refs/tags/*' 'refs/heads/*:refs/heads/*' &&
  48        git checkout -q @{-1} &&
  49        git branch -q -D tmp 2>/dev/null || true
  50        )
  51}
  52
  53hg_log () {
  54        hg -R $1 log --graph --debug
  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        git config --global remote-hg.track-branches true
  71
  72        HGEDITOR=/usr/bin/true
  73        GIT_AUTHOR_DATE="2007-01-01 00:00:00 +0230"
  74        GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE"
  75        export HGEDITOR GIT_AUTHOR_DATE GIT_COMMITTER_DATE
  76}
  77
  78setup
  79
  80test_expect_success 'encoding' '
  81        test_when_finished "rm -rf gitrepo* hgrepo*" &&
  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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 119
 120        (
 121        git init -q gitrepo &&
 122        cd gitrepo &&
 123        echo alpha >alpha &&
 124        git add alpha &&
 125        git commit -m "add alpha" &&
 126        echo beta >beta &&
 127        git add beta &&
 128        git commit -m "add beta"
 129        mkdir foo &&
 130        echo blah >foo/bar &&
 131        git add foo &&
 132        git commit -m "add foo" &&
 133        git rm alpha &&
 134        git commit -m "remove alpha" &&
 135        git rm foo/bar &&
 136        git commit -m "remove foo/bar"
 137        ) &&
 138
 139        hg_clone gitrepo hgrepo &&
 140        git_clone hgrepo gitrepo2 &&
 141        hg_clone gitrepo2 hgrepo2 &&
 142
 143        hg_log hgrepo >expected &&
 144        hg_log hgrepo2 >actual &&
 145
 146        test_cmp expected actual
 147'
 148
 149test_expect_success 'git tags' '
 150        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 151
 152        (
 153        git init -q gitrepo &&
 154        cd gitrepo &&
 155        git config receive.denyCurrentBranch ignore &&
 156        echo alpha >alpha &&
 157        git add alpha &&
 158        git commit -m "add alpha" &&
 159        git tag alpha &&
 160
 161        echo beta >beta &&
 162        git add beta &&
 163        git commit -m "add beta" &&
 164        git tag -a -m "added tag beta" beta
 165        ) &&
 166
 167        hg_clone gitrepo hgrepo &&
 168        git_clone hgrepo gitrepo2 &&
 169        hg_clone gitrepo2 hgrepo2 &&
 170
 171        hg_log hgrepo >expected &&
 172        hg_log hgrepo2 >actual &&
 173
 174        test_cmp expected actual
 175'
 176
 177test_expect_success 'hg branch' '
 178        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 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 default &&
 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        : Back to the common revision &&
 205        (cd hgrepo && hg checkout default) &&
 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        test_when_finished "rm -rf gitrepo* hgrepo*" &&
 215
 216        (
 217        git init -q gitrepo &&
 218        cd gitrepo &&
 219
 220        echo alpha >alpha &&
 221        git add alpha &&
 222        git commit -m "add alpha" &&
 223        git checkout -q -b not-master
 224        ) &&
 225
 226        (
 227        hg_clone gitrepo hgrepo &&
 228
 229        cd hgrepo &&
 230        hg co default &&
 231        hg tag alpha
 232        ) &&
 233
 234        hg_push hgrepo gitrepo &&
 235        hg_clone gitrepo hgrepo2 &&
 236
 237        hg_log hgrepo >expected &&
 238        hg_log hgrepo2 >actual &&
 239
 240        test_cmp expected actual
 241'
 242
 243test_done