contrib / remote-helpers / test-bzr.shon commit Merge branch 'jk/detect-push-typo-early' (9befb34)
   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 'forced pushing' '
  70        (
  71        cd gitrepo &&
  72        echo three-new >content &&
  73        git commit -a --amend -m three-new &&
  74        git push -f
  75        ) &&
  76
  77        (
  78        cd bzrrepo &&
  79        # the forced update overwrites the bzr branch but not the bzr
  80        # working directory (it tries to merge instead)
  81        bzr revert
  82        ) &&
  83
  84        echo three-new >expected &&
  85        cat bzrrepo/content >actual &&
  86        test_cmp expected actual
  87'
  88
  89test_expect_success 'roundtrip' '
  90        (
  91        cd gitrepo &&
  92        git pull &&
  93        git log --format="%s" -1 origin/master >actual
  94        ) &&
  95        echo three-new >expected &&
  96        test_cmp expected actual &&
  97
  98        (cd gitrepo && git push && git pull) &&
  99
 100        (
 101        cd bzrrepo &&
 102        echo four >content &&
 103        bzr commit -m four
 104        ) &&
 105
 106        (cd gitrepo && git pull && git push) &&
 107
 108        check gitrepo HEAD four &&
 109
 110        (
 111        cd gitrepo &&
 112        echo five >content &&
 113        git commit -a -m five &&
 114        git push && git pull
 115        ) &&
 116
 117        (cd bzrrepo && bzr revert) &&
 118
 119        echo five >expected &&
 120        cat bzrrepo/content >actual &&
 121        test_cmp expected actual
 122'
 123
 124cat >expected <<\EOF
 125100644 blob 54f9d6da5c91d556e6b54340b1327573073030af    content
 126100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb    executable
 127120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea    link
 128EOF
 129
 130test_expect_success 'special modes' '
 131        (
 132        cd bzrrepo &&
 133        echo exec >executable
 134        chmod +x executable &&
 135        bzr add executable
 136        bzr commit -m exec &&
 137        ln -s content link
 138        bzr add link
 139        bzr commit -m link &&
 140        mkdir dir &&
 141        bzr add dir &&
 142        bzr commit -m dir
 143        ) &&
 144
 145        (
 146        cd gitrepo &&
 147        git pull
 148        git ls-tree HEAD >../actual
 149        ) &&
 150
 151        test_cmp expected actual &&
 152
 153        (
 154        cd gitrepo &&
 155        git cat-file -p HEAD:link >../actual
 156        ) &&
 157
 158        printf content >expected &&
 159        test_cmp expected actual
 160'
 161
 162cat >expected <<\EOF
 163100644 blob 54f9d6da5c91d556e6b54340b1327573073030af    content
 164100755 blob 68769579c3eaadbe555379b9c3538e6628bae1eb    executable
 165120000 blob 6b584e8ece562ebffc15d38808cd6b98fc3d97ea    link
 166040000 tree 35c0caa46693cef62247ac89a680f0c5ce32b37b    movedir-new
 167EOF
 168
 169test_expect_success 'moving directory' '
 170        (
 171        cd bzrrepo &&
 172        mkdir movedir &&
 173        echo one >movedir/one &&
 174        echo two >movedir/two &&
 175        bzr add movedir &&
 176        bzr commit -m movedir &&
 177        bzr mv movedir movedir-new &&
 178        bzr commit -m movedir-new
 179        ) &&
 180
 181        (
 182        cd gitrepo &&
 183        git pull &&
 184        git ls-tree HEAD >../actual
 185        ) &&
 186
 187        test_cmp expected actual
 188'
 189
 190test_expect_success 'different authors' '
 191        (
 192        cd bzrrepo &&
 193        echo john >>content &&
 194        bzr commit -m john \
 195          --author "Jane Rey <jrey@example.com>" \
 196          --author "John Doe <jdoe@example.com>"
 197        ) &&
 198
 199        (
 200        cd gitrepo &&
 201        git pull &&
 202        git show --format="%an <%ae>, %cn <%ce>" --quiet >../actual
 203        ) &&
 204
 205        echo "Jane Rey <jrey@example.com>, A U Thor <author@example.com>" >expected &&
 206        test_cmp expected actual
 207'
 208
 209# cleanup previous stuff
 210rm -rf bzrrepo gitrepo
 211
 212test_expect_success 'fetch utf-8 filenames' '
 213        test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
 214
 215        LC_ALL=en_US.UTF-8
 216        export LC_ALL
 217
 218        (
 219        bzr init bzrrepo &&
 220        cd bzrrepo &&
 221
 222        echo test >>"ærø" &&
 223        bzr add "ærø" &&
 224        echo test >>"ø~?" &&
 225        bzr add "ø~?" &&
 226        bzr commit -m add-utf-8 &&
 227        echo test >>"ærø" &&
 228        bzr commit -m test-utf-8 &&
 229        bzr rm "ø~?" &&
 230        bzr mv "ærø" "ø~?" &&
 231        bzr commit -m bzr-mv-utf-8
 232        ) &&
 233
 234        (
 235        git clone "bzr::bzrrepo" gitrepo &&
 236        cd gitrepo &&
 237        git -c core.quotepath=false ls-files >../actual
 238        ) &&
 239        echo "ø~?" >expected &&
 240        test_cmp expected actual
 241'
 242
 243test_expect_success 'push utf-8 filenames' '
 244        test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C" &&
 245
 246        mkdir -p tmp && cd tmp &&
 247
 248        LC_ALL=en_US.UTF-8
 249        export LC_ALL
 250
 251        (
 252        bzr init bzrrepo &&
 253        cd bzrrepo &&
 254
 255        echo one >>content &&
 256        bzr add content &&
 257        bzr commit -m one
 258        ) &&
 259
 260        (
 261        git clone "bzr::bzrrepo" gitrepo &&
 262        cd gitrepo &&
 263
 264        echo test >>"ærø" &&
 265        git add "ærø" &&
 266        git commit -m utf-8 &&
 267
 268        git push
 269        ) &&
 270
 271        (cd bzrrepo && bzr ls >../actual) &&
 272        printf "content\nærø\n" >expected &&
 273        test_cmp expected actual
 274'
 275
 276test_expect_success 'pushing a merge' '
 277        test_when_finished "rm -rf bzrrepo gitrepo" &&
 278
 279        (
 280        bzr init bzrrepo &&
 281        cd bzrrepo &&
 282        echo one >content &&
 283        bzr add content &&
 284        bzr commit -m one
 285        ) &&
 286
 287        git clone "bzr::bzrrepo" gitrepo &&
 288
 289        (
 290        cd bzrrepo &&
 291        echo two >content &&
 292        bzr commit -m two
 293        ) &&
 294
 295        (
 296        cd gitrepo &&
 297        echo three >content &&
 298        git commit -a -m three &&
 299        git fetch &&
 300        git merge origin/master || true &&
 301        echo three >content &&
 302        git commit -a --no-edit &&
 303        git push
 304        ) &&
 305
 306        echo three >expected &&
 307        cat bzrrepo/content >actual &&
 308        test_cmp expected actual
 309'
 310
 311cat >expected <<\EOF
 312origin/HEAD
 313origin/branch
 314origin/trunk
 315EOF
 316
 317test_expect_success 'proper bzr repo' '
 318        test_when_finished "rm -rf bzrrepo gitrepo" &&
 319
 320        bzr init-repo bzrrepo &&
 321
 322        (
 323        bzr init bzrrepo/trunk &&
 324        cd bzrrepo/trunk &&
 325        echo one >>content &&
 326        bzr add content &&
 327        bzr commit -m one
 328        ) &&
 329
 330        (
 331        bzr branch bzrrepo/trunk bzrrepo/branch &&
 332        cd bzrrepo/branch &&
 333        echo two >>content &&
 334        bzr commit -m one
 335        ) &&
 336
 337        (
 338        git clone "bzr::bzrrepo" gitrepo &&
 339        cd gitrepo &&
 340        git for-each-ref --format "%(refname:short)" refs/remotes/origin >../actual
 341        ) &&
 342
 343        test_cmp expected actual
 344'
 345
 346test_expect_success 'strip' '
 347        test_when_finished "rm -rf bzrrepo gitrepo" &&
 348
 349        (
 350        bzr init bzrrepo &&
 351        cd bzrrepo &&
 352
 353        echo one >>content &&
 354        bzr add content &&
 355        bzr commit -m one &&
 356
 357        echo two >>content &&
 358        bzr commit -m two
 359        ) &&
 360
 361        git clone "bzr::bzrrepo" gitrepo &&
 362
 363        (
 364        cd bzrrepo &&
 365        bzr uncommit --force &&
 366
 367        echo three >>content &&
 368        bzr commit -m three &&
 369
 370        echo four >>content &&
 371        bzr commit -m four &&
 372        bzr log --line | sed -e "s/^[0-9][0-9]*: //" >../expected
 373        ) &&
 374
 375        (
 376        cd gitrepo &&
 377        git fetch &&
 378        git log --format="%an %ad %s" --date=short origin/master >../actual
 379        ) &&
 380
 381        test_cmp expected actual
 382'
 383
 384test_expect_success 'export utf-8 authors' '
 385        test_when_finished "rm -rf bzrrepo gitrepo && LC_ALL=C && unset GIT_COMMITTER_NAME" &&
 386
 387        LC_ALL=en_US.UTF-8
 388        export LC_ALL
 389
 390        GIT_COMMITTER_NAME="Grégoire"
 391        export GIT_COMMITTER_NAME
 392
 393        bzr init bzrrepo &&
 394
 395        (
 396        git init gitrepo &&
 397        cd gitrepo &&
 398        echo greg >>content &&
 399        git add content &&
 400        git commit -m one &&
 401        git remote add bzr "bzr::../bzrrepo" &&
 402        git push bzr master
 403        ) &&
 404
 405        (
 406        cd bzrrepo &&
 407        bzr log | grep "^committer: " >../actual
 408        ) &&
 409
 410        echo "committer: Grégoire <committer@example.com>" >expected &&
 411        test_cmp expected actual
 412'
 413
 414test_done