]> git.ipfire.org Git - thirdparty/git.git/blame - t/t4012-diff-binary.sh
revert: free msg in format_todo()
[thirdparty/git.git] / t / t4012-diff-binary.sh
CommitLineData
42d0ee83
JH
1#!/bin/sh
2#
3# Copyright (c) 2006 Junio C Hamano
4#
5
6test_description='Binary diff and apply
7'
8
9. ./test-lib.sh
10
11test_expect_success 'prepare repository' \
12 'echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d &&
5be60078 13 git update-index --add a b c d &&
42d0ee83 14 echo git >a &&
b5967f82 15 cat "$TEST_DIRECTORY"/test-binary-1.png >b &&
42d0ee83
JH
16 echo git >c &&
17 cat b b >d'
18
c7053aa8 19cat > expected <<\EOF
42d0ee83
JH
20 a | 2 +-
21 b | Bin
22 c | 2 +-
23 d | Bin
24 4 files changed, 2 insertions(+), 2 deletions(-)
c7053aa8
EW
25EOF
26test_expect_success 'diff without --binary' \
5be60078 27 'git diff | git apply --stat --summary >current &&
e7881c35 28 test_cmp expected current'
42d0ee83
JH
29
30test_expect_success 'diff with --binary' \
5be60078 31 'git diff --binary | git apply --stat --summary >current &&
e7881c35 32 test_cmp expected current'
42d0ee83
JH
33
34# apply needs to be able to skip the binary material correctly
35# in order to report the line number of a corrupt patch.
36test_expect_success 'apply detecting corrupt patch correctly' \
5be60078
JH
37 'git diff | sed -e 's/-CIT/xCIT/' >broken &&
38 if git apply --stat --summary broken 2>detected
42d0ee83
JH
39 then
40 echo unhappy - should have detected an error
41 (exit 1)
42 else
43 echo happy
44 fi &&
45 detected=`cat detected` &&
46 detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
47 detected=`sed -ne "${detected}p" broken` &&
48 test "$detected" = xCIT'
49
50test_expect_success 'apply detecting corrupt patch correctly' \
5be60078
JH
51 'git diff --binary | sed -e 's/-CIT/xCIT/' >broken &&
52 if git apply --stat --summary broken 2>detected
42d0ee83
JH
53 then
54 echo unhappy - should have detected an error
55 (exit 1)
56 else
57 echo happy
58 fi &&
59 detected=`cat detected` &&
60 detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
61 detected=`sed -ne "${detected}p" broken` &&
62 test "$detected" = xCIT'
63
3604e7c5 64test_expect_success 'initial commit' 'git commit -a -m initial'
42d0ee83
JH
65
66# Try removal (b), modification (d), and creation (e).
67test_expect_success 'diff-index with --binary' \
68 'echo AIT >a && mv b e && echo CIT >c && cat e >d &&
5be60078
JH
69 git update-index --add --remove a b c d e &&
70 tree0=`git write-tree` &&
71 git diff --cached --binary >current &&
72 git apply --stat --summary current'
42d0ee83
JH
73
74test_expect_success 'apply binary patch' \
3604e7c5 75 'git reset --hard &&
5be60078
JH
76 git apply --binary --index <current &&
77 tree1=`git write-tree` &&
42d0ee83
JH
78 test "$tree1" = "$tree0"'
79
71b989e7
LT
80test_expect_success 'diff --no-index with binary creation' '
81 echo Q | q_to_nul >binary &&
36adb4ab 82 (: hide error code from diff, which just indicates differences
71b989e7
LT
83 git diff --binary --no-index /dev/null binary >current ||
84 true
85 ) &&
86 rm binary &&
87 git apply --binary <current &&
88 echo Q >expected &&
89 nul_to_q <binary >actual &&
90 test_cmp expected actual
91'
92
42d0ee83 93test_done