t / t4103-apply-binary.shon commit t7610-mergetool: use test_cmp instead of test $(cat file) = $txt (e10dffd)
   1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5
   6test_description='git apply handling binary patches
   7
   8'
   9. ./test-lib.sh
  10
  11test_expect_success 'setup' '
  12        cat >file1 <<-\EOF &&
  13        A quick brown fox jumps over the lazy dog.
  14        A tiny little penguin runs around in circles.
  15        There is a flag with Linux written on it.
  16        A slow black-and-white panda just sits there,
  17        munching on his bamboo.
  18        EOF
  19        cat file1 >file2 &&
  20        cat file1 >file4 &&
  21
  22        git update-index --add --remove file1 file2 file4 &&
  23        git commit -m "Initial Version" 2>/dev/null &&
  24
  25        git checkout -b binary &&
  26        perl -pe "y/x/\000/" <file1 >file3 &&
  27        cat file3 >file4 &&
  28        git add file2 &&
  29        perl -pe "y/\000/v/" <file3 >file1 &&
  30        rm -f file2 &&
  31        git update-index --add --remove file1 file2 file3 file4 &&
  32        git commit -m "Second Version" &&
  33
  34        git diff-tree -p master binary >B.diff &&
  35        git diff-tree -p -C master binary >C.diff &&
  36
  37        git diff-tree -p --binary master binary >BF.diff &&
  38        git diff-tree -p --binary -C master binary >CF.diff &&
  39
  40        git diff-tree -p --full-index master binary >B-index.diff &&
  41        git diff-tree -p -C --full-index master binary >C-index.diff &&
  42
  43        git diff-tree -p --binary --no-prefix master binary -- file3 >B0.diff &&
  44
  45        git init other-repo &&
  46        (
  47                cd other-repo &&
  48                git fetch .. master &&
  49                git reset --hard FETCH_HEAD
  50        )
  51'
  52
  53test_expect_success 'stat binary diff -- should not fail.' \
  54        'git checkout master &&
  55         git apply --stat --summary B.diff'
  56
  57test_expect_success 'stat binary -p0 diff -- should not fail.' '
  58         git checkout master &&
  59         git apply --stat -p0 B0.diff
  60'
  61
  62test_expect_success 'stat binary diff (copy) -- should not fail.' \
  63        'git checkout master &&
  64         git apply --stat --summary C.diff'
  65
  66test_expect_success 'check binary diff -- should fail.' \
  67        'git checkout master &&
  68         test_must_fail git apply --check B.diff'
  69
  70test_expect_success 'check binary diff (copy) -- should fail.' \
  71        'git checkout master &&
  72         test_must_fail git apply --check C.diff'
  73
  74test_expect_success \
  75        'check incomplete binary diff with replacement -- should fail.' '
  76        git checkout master &&
  77        test_must_fail git apply --check --allow-binary-replacement B.diff
  78'
  79
  80test_expect_success \
  81    'check incomplete binary diff with replacement (copy) -- should fail.' '
  82         git checkout master &&
  83         test_must_fail git apply --check --allow-binary-replacement C.diff
  84'
  85
  86test_expect_success 'check binary diff with replacement.' \
  87        'git checkout master &&
  88         git apply --check --allow-binary-replacement BF.diff'
  89
  90test_expect_success 'check binary diff with replacement (copy).' \
  91        'git checkout master &&
  92         git apply --check --allow-binary-replacement CF.diff'
  93
  94# Now we start applying them.
  95
  96do_reset () {
  97        rm -f file? &&
  98        git reset --hard &&
  99        git checkout -f master
 100}
 101
 102test_expect_success 'apply binary diff -- should fail.' \
 103        'do_reset &&
 104         test_must_fail git apply B.diff'
 105
 106test_expect_success 'apply binary diff -- should fail.' \
 107        'do_reset &&
 108         test_must_fail git apply --index B.diff'
 109
 110test_expect_success 'apply binary diff (copy) -- should fail.' \
 111        'do_reset &&
 112         test_must_fail git apply C.diff'
 113
 114test_expect_success 'apply binary diff (copy) -- should fail.' \
 115        'do_reset &&
 116         test_must_fail git apply --index C.diff'
 117
 118test_expect_success 'apply binary diff with full-index' '
 119        do_reset &&
 120        git apply B-index.diff
 121'
 122
 123test_expect_success 'apply binary diff with full-index (copy)' '
 124        do_reset &&
 125        git apply C-index.diff
 126'
 127
 128test_expect_success 'apply full-index binary diff in new repo' '
 129        (cd other-repo &&
 130         do_reset &&
 131         test_must_fail git apply ../B-index.diff)
 132'
 133
 134test_expect_success 'apply binary diff without replacement.' \
 135        'do_reset &&
 136         git apply BF.diff'
 137
 138test_expect_success 'apply binary diff without replacement (copy).' \
 139        'do_reset &&
 140         git apply CF.diff'
 141
 142test_expect_success 'apply binary diff.' \
 143        'do_reset &&
 144         git apply --allow-binary-replacement --index BF.diff &&
 145         test -z "$(git diff --name-status binary)"'
 146
 147test_expect_success 'apply binary diff (copy).' \
 148        'do_reset &&
 149         git apply --allow-binary-replacement --index CF.diff &&
 150         test -z "$(git diff --name-status binary)"'
 151
 152test_expect_success 'apply binary -p0 diff' '
 153        do_reset &&
 154        git apply -p0 --index B0.diff &&
 155        test -z "$(git diff --name-status binary -- file3)"
 156'
 157
 158test_done