contrib / remote-helpers / test-bzr.shon commit Merge branch 'cc/starts-n-ends-with-endgame' (e3f1185)
   1#!/bin/sh
   2#
   3# Copyright (c) 2012 Felipe Contreras
   4#
   5
   6test_description='Test remote-bzr'
   7
   8test -n "$TEST_DIRECTORY" || TEST_DIRECTORY=${0%/*}/../../t
   9. "$TEST_DIRECTORY"/test-lib.sh
  10
  11if ! test_have_prereq PYTHON
  12then
  13        skip_all='skipping remote-bzr tests; python not available'
  14        test_done
  15fi
  16
  17if ! python -c 'import bzrlib'
  18then
  19        skip_all='skipping remote-bzr tests; bzr not available'
  20        test_done
  21fi
  22
  23check () {
  24        echo $3 >expected &&
  25        git --git-dir=$1/.git log --format='%s' -1 $2 >actual
  26        test_cmp expected actual
  27}
  28
  29bzr whoami "A U Thor <author@example.com>"
  30
  31test_expect_success 'cloning' '
  32        (
  33        bzr init bzrrepo &&
  34        cd bzrrepo &&
  35        echo one >content &&
  36        bzr add content &&
  37        bzr commit -m one
  38        ) &&
  39
  40        git clone "bzr::bzrrepo" gitrepo &&
  41        check gitrepo HEAD one
  42'
  43
  44test_expect_success 'pulling' '
  45        (
  46        cd bzrrepo &&
  47        echo two >content &&
  48        bzr commit -m two
  49        ) &&
  50
  51        (cd gitrepo && git pull) &&
  52
  53        check gitrepo HEAD two
  54'
  55
  56test_expect_success 'pushing' '
  57        (
  58        cd gitrepo &&
  59        echo three >content &&
  60        git commit -a -m three &&
  61        git push
  62        ) &&
  63
  64        echo three >expected &&
  65        cat bzrrepo/content >actual &&
  66        test_cmp expected actual
  67'
  68
  69test_expect_success 'roundtrip' '
  70        (
  71        cd gitrepo &&
  72        git pull &&
  73        git log --format="%s" -1 origin/master >actual
  74        ) &&
  75        echo three >expected &&
  76        test_cmp expected actual &&
  77
  78        (cd gitrepo && git push && git pull) &&
  79
  80        (
  81        cd bzrrepo &&
  82        echo four >content &&
  83        bzr commit -m four
  84        ) &&
  85
  86        (cd gitrepo && git pull && git push) &&
  87
  88        check gitrepo HEAD four &&
  89
  90        (
  91        cd gitrepo &&
  92        echo five >content &&
  93        git commit -a -m five &&
  94        git push && git pull
  95        ) &&
  96
  97        (cd bzrrepo && bzr revert) &&
  98
  99        echo five >expected &&
 100        cat bzrrepo/content >actual &&
 101        test_cmp expected actual
 102'
 103
 104cat >expected <<\EOF
 105100644 blob 54f9d6da5c91d556e6b54340b1327573073030af    content
 106100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb    executable
 107120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea    link
 108EOF
 109
 110test_expect_success 'special modes' '
 111        (
 112        cd bzrrepo &&
 113        echo exec >executable
 114        chmod +x executable &&
 115        bzr add executable
 116        bzr commit -m exec &&
 117        ln -s content link
 118        bzr add link
 119        bzr commit -m link &&
 120        mkdir dir &&
 121        bzr add dir &&
 122        bzr commit -m dir
 123        ) &&
 124
 125        (
 126        cd gitrepo &&
 127        git pull
 128        git ls-tree HEAD >../actual
 129        ) &&
 130
 131        test_cmp expected actual &&
 132
 133        (
 134        cd gitrepo &&
 135        git cat-file -p HEAD:link >../actual
 136        ) &&
 137
 138        printf content >expected &&
 139        test_cmp expected actual
 140'
 141
 142cat >expected <<\EOF
 143100644 blob 54f9d6da5c91d556e6b54340b1327573073030af    content
 144100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb    executable
 145120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea    link
 146040000 tree 35c0caa46693cef62247ac89a680f0c5ce32b37b    movedir-new
 147EOF
 148
 149test_expect_success 'moving directory' '
 150        (
 151        cd bzrrepo &&
 152        mkdir movedir &&
 153        echo one >movedir/one &&
 154        echo two >movedir/two &&
 155        bzr add movedir &&
 156        bzr commit -m movedir &&
 157        bzr mv movedir movedir-new &&
 158        bzr commit -m movedir-new
 159        ) &&
 160
 161        (
 162        cd gitrepo &&
 163        git pull &&
 164        git ls-tree HEAD >../actual
 165        ) &&
 166
 167        test_cmp expected actual
 168'
 169
 170test_expect_success 'different authors' '
 171        (
 172        cd bzrrepo &&
 173        echo john >>content &&
 174        bzr commit -m john \
 175          --author "Jane Rey <jrey@example.com>" \
 176          --author "John Doe <jdoe@example.com>"
 177        ) &&
 178
 179        (
 180        cd gitrepo &&
 181        git pull &&
 182        git show --format="%an <%ae>, %cn <%ce>" --quiet >../actual
 183        ) &&
 184
 185        echo "Jane Rey <jrey@example.com>, A U Thor <author@example.com>" >expected &&
 186        test_cmp expected actual
 187'
 188
 189# cleanup previous stuff
 190rm -rf bzrrepo gitrepo
 191
 192test_expect_success 'fetch utf-8 filenames' '
 193        test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
 194
 195        LC_ALL=en_US.UTF-8
 196        export LC_ALL
 197
 198        (
 199        bzr init bzrrepo &&
 200        cd bzrrepo &&
 201
 202        echo test >>"ærø" &&
 203        bzr add "ærø" &&
 204        echo test >>"ø~?" &&
 205        bzr add "ø~?" &&
 206        bzr commit -m add-utf-8 &&
 207        echo test >>"ærø" &&
 208        bzr commit -m test-utf-8 &&
 209        bzr rm "ø~?" &&
 210        bzr mv "ærø" "ø~?" &&
 211        bzr commit -m bzr-mv-utf-8
 212        ) &&
 213
 214        (
 215        git clone "bzr::bzrrepo" gitrepo &&
 216        cd gitrepo &&
 217        git -c core.quotepath=false ls-files >../actual
 218        ) &&
 219        echo "ø~?" >expected &&
 220        test_cmp expected actual
 221'
 222
 223test_expect_success 'push utf-8 filenames' '
 224        test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
 225
 226        mkdir -p tmp && cd tmp &&
 227
 228        LC_ALL=en_US.UTF-8
 229        export LC_ALL
 230
 231        (
 232        bzr init bzrrepo &&
 233        cd bzrrepo &&
 234
 235        echo one >>content &&
 236        bzr add content &&
 237        bzr commit -m one
 238        ) &&
 239
 240        (
 241        git clone "bzr::bzrrepo" gitrepo &&
 242        cd gitrepo &&
 243
 244        echo test >>"ærø" &&
 245        git add "ærø" &&
 246        git commit -m utf-8 &&
 247
 248        git push
 249        ) &&
 250
 251        (cd bzrrepo && bzr ls >../actual) &&
 252        printf "content\nærø\n" >expected &&
 253        test_cmp expected actual
 254'
 255
 256test_expect_success 'pushing a merge' '
 257        test_when_finished "rm -rf bzrrepo gitrepo" &&
 258
 259        (
 260        bzr init bzrrepo &&
 261        cd bzrrepo &&
 262        echo one >content &&
 263        bzr add content &&
 264        bzr commit -m one
 265        ) &&
 266
 267        git clone "bzr::bzrrepo" gitrepo &&
 268
 269        (
 270        cd bzrrepo &&
 271        echo two >content &&
 272        bzr commit -m two
 273        ) &&
 274
 275        (
 276        cd gitrepo &&
 277        echo three >content &&
 278        git commit -a -m three &&
 279        git fetch &&
 280        git merge origin/master || true &&
 281        echo three >content &&
 282        git commit -a --no-edit &&
 283        git push
 284        ) &&
 285
 286        echo three >expected &&
 287        cat bzrrepo/content >actual &&
 288        test_cmp expected actual
 289'
 290
 291cat >expected <<\EOF
 292origin/HEAD
 293origin/branch
 294origin/trunk
 295EOF
 296
 297test_expect_success 'proper bzr repo' '
 298        test_when_finished "rm -rf bzrrepo gitrepo" &&
 299
 300        bzr init-repo bzrrepo &&
 301
 302        (
 303        bzr init bzrrepo/trunk &&
 304        cd bzrrepo/trunk &&
 305        echo one >>content &&
 306        bzr add content &&
 307        bzr commit -m one
 308        ) &&
 309
 310        (
 311        bzr branch bzrrepo/trunk bzrrepo/branch &&
 312        cd bzrrepo/branch &&
 313        echo two >>content &&
 314        bzr commit -m one
 315        ) &&
 316
 317        (
 318        git clone "bzr::bzrrepo" gitrepo &&
 319        cd gitrepo &&
 320        git for-each-ref --format "%(refname:short)" refs/remotes/origin >../actual
 321        ) &&
 322
 323        test_cmp expected actual
 324'
 325
 326test_expect_success 'strip' '
 327        test_when_finished "rm -rf bzrrepo gitrepo" &&
 328
 329        (
 330        bzr init bzrrepo &&
 331        cd bzrrepo &&
 332
 333        echo one >>content &&
 334        bzr add content &&
 335        bzr commit -m one &&
 336
 337        echo two >>content &&
 338        bzr commit -m two
 339        ) &&
 340
 341        git clone "bzr::bzrrepo" gitrepo &&
 342
 343        (
 344        cd bzrrepo &&
 345        bzr uncommit --force &&
 346
 347        echo three >>content &&
 348        bzr commit -m three &&
 349
 350        echo four >>content &&
 351        bzr commit -m four &&
 352        bzr log --line | sed -e "s/^[0-9][0-9]*: //" >../expected
 353        ) &&
 354
 355        (
 356        cd gitrepo &&
 357        git fetch &&
 358        git log --format="%an %ad %s" --date=short origin/master >../actual
 359        ) &&
 360
 361        test_cmp expected actual
 362'
 363
 364test_expect_success 'export utf-8 authors' '
 365        test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C && unset GIT_COMMITTER_NAME" &&
 366
 367        LC_ALL=en_US.UTF-8
 368        export LC_ALL
 369
 370        GIT_COMMITTER_NAME="Grégoire"
 371        export GIT_COMMITTER_NAME
 372
 373        bzr init bzrrepo &&
 374
 375        (
 376        git init gitrepo &&
 377        cd gitrepo &&
 378        echo greg >>content &&
 379        git add content &&
 380        git commit -m one &&
 381        git remote add bzr "bzr::../bzrrepo" &&
 382        git push bzr master
 383        ) &&
 384
 385        (
 386        cd bzrrepo &&
 387        bzr log | grep "^committer: " >../actual
 388        ) &&
 389
 390        echo "committer: Grégoire <committer@example.com>" >expected &&
 391        test_cmp expected actual
 392'
 393
 394test_done