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