Merge branch 'seq-builtin-dev' into mymaster
[git/sbeyer.git] / t / t4012-diff-binary.sh
blobf64aa48d24f2f5704d07b9285c94ba983f7d92ac
1 #!/bin/sh
3 # Copyright (c) 2006 Junio C Hamano
6 test_description='Binary diff and apply
9 . ./test-lib.sh
11 test_expect_success 'prepare repository' \
12 'echo AIT >a && echo BIT >b && echo CIT >c && echo DIT >d &&
13 git update-index --add a b c d &&
14 echo git >a &&
15 cat "$TEST_DIRECTORY"/test4012.png >b &&
16 echo git >c &&
17 cat b b >d'
19 cat > expected <<\EOF
20 a | 2 +-
21 b | Bin
22 c | 2 +-
23 d | Bin
24 4 files changed, 2 insertions(+), 2 deletions(-)
25 EOF
26 test_expect_success 'diff without --binary' \
27 'git diff | git apply --stat --summary >current &&
28 test_cmp expected current'
30 test_expect_success 'diff with --binary' \
31 'git diff --binary | git apply --stat --summary >current &&
32 test_cmp expected current'
34 # apply needs to be able to skip the binary material correctly
35 # in order to report the line number of a corrupt patch.
36 test_expect_success 'apply detecting corrupt patch correctly' \
37 'git diff | sed -e 's/-CIT/xCIT/' >broken &&
38 if git apply --stat --summary broken 2>detected
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'
50 test_expect_success 'apply detecting corrupt patch correctly' \
51 'git diff --binary | sed -e 's/-CIT/xCIT/' >broken &&
52 if git apply --stat --summary broken 2>detected
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'
64 test_expect_success 'initial commit' 'git commit -a -m initial'
66 # Try removal (b), modification (d), and creation (e).
67 test_expect_success 'diff-index with --binary' \
68 'echo AIT >a && mv b e && echo CIT >c && cat e >d &&
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'
74 test_expect_success 'apply binary patch' \
75 'git reset --hard &&
76 git apply --binary --index <current &&
77 tree1=`git write-tree` &&
78 test "$tree1" = "$tree0"'
80 q_to_nul() {
81 perl -pe 'y/Q/\000/'
84 nul_to_q() {
85 perl -pe 'y/\000/Q/'
88 test_expect_success 'diff --no-index with binary creation' '
89 echo Q | q_to_nul >binary &&
90 (: hide error code from diff, which just indicates differences
91 git diff --binary --no-index /dev/null binary >current ||
92 true
93 ) &&
94 rm binary &&
95 git apply --binary <current &&
96 echo Q >expected &&
97 nul_to_q <binary >actual &&
98 test_cmp expected actual
101 test_done