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