1#!/bin/sh
   2#
   3# Copyright (c) 2005 Junio C Hamano
   4#
   5test_description='git apply handling binary patches
   7'
   9. ./test-lib.sh
  10# setup
  12cat >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
  22git update-index --add --remove file1 file2 file4
  24git commit -m 'Initial Version' 2>/dev/null
  25git checkout -b binary
  27perl -pe 'y/x/\000/' <file1 >file3
  28cat file3 >file4
  29git add file2
  30perl -pe 'y/\000/v/' <file3 >file1
  31rm -f file2
  32git update-index --add --remove file1 file2 file3 file4
  33git commit -m 'Second Version'
  34git diff-tree -p master binary >B.diff
  36git diff-tree -p -C master binary >C.diff
  37git diff-tree -p --binary master binary >BF.diff
  39git diff-tree -p --binary -C master binary >CF.diff
  40test_expect_success 'stat binary diff -- should not fail.' \
  42        'git checkout master
  43         git apply --stat --summary B.diff'
  44test_expect_success 'stat binary diff (copy) -- should not fail.' \
  46        'git checkout master
  47         git apply --stat --summary C.diff'
  48test_expect_success 'check binary diff -- should fail.' \
  50        'git checkout master &&
  51         test_must_fail git apply --check B.diff'
  52test_expect_success 'check binary diff (copy) -- should fail.' \
  54        'git checkout master &&
  55         test_must_fail git apply --check C.diff'
  56test_expect_success \
  58        'check incomplete binary diff with replacement -- should fail.' '
  59        git checkout master &&
  60        test_must_fail git apply --check --allow-binary-replacement B.diff
  61'
  62test_expect_success \
  64    'check incomplete binary diff with replacement (copy) -- should fail.' '
  65         git checkout master &&
  66         test_must_fail git apply --check --allow-binary-replacement C.diff
  67'
  68test_expect_success 'check binary diff with replacement.' \
  70        'git checkout master
  71         git apply --check --allow-binary-replacement BF.diff'
  72test_expect_success 'check binary diff with replacement (copy).' \
  74        'git checkout master
  75         git apply --check --allow-binary-replacement CF.diff'
  76# Now we start applying them.
  78do_reset () {
  80        rm -f file? &&
  81        git reset --hard &&
  82        git checkout -f master
  83}
  84test_expect_success 'apply binary diff -- should fail.' \
  86        'do_reset &&
  87         test_must_fail git apply B.diff'
  88test_expect_success 'apply binary diff -- should fail.' \
  90        'do_reset &&
  91         test_must_fail git apply --index B.diff'
  92test_expect_success 'apply binary diff (copy) -- should fail.' \
  94        'do_reset &&
  95         test_must_fail git apply C.diff'
  96test_expect_success 'apply binary diff (copy) -- should fail.' \
  98        'do_reset &&
  99         test_must_fail git apply --index C.diff'
 100test_expect_success 'apply binary diff without replacement.' \
 102        'do_reset &&
 103         git apply BF.diff'
 104test_expect_success 'apply binary diff without replacement (copy).' \
 106        'do_reset &&
 107         git apply CF.diff'
 108test_expect_success 'apply binary diff.' \
 110        'do_reset &&
 111         git apply --allow-binary-replacement --index BF.diff &&
 112         test -z "$(git diff --name-status binary)"'
 113test_expect_success 'apply binary diff (copy).' \
 115        'do_reset &&
 116         git apply --allow-binary-replacement --index CF.diff &&
 117         test -z "$(git diff --name-status binary)"'
 118test_done