fetch.c: do not call process_tree() from process_tree().
[git/git.git] / t / t4012-diff-binary.sh
1 #!/bin/sh
2 #
3 # Copyright (c) 2006 Junio C Hamano
4 #
5
6 test_description='Binary diff and apply
7 '
8
9 . ./test-lib.sh
10
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 ../test4012.png >b &&
16 echo git >c &&
17 cat b b >d'
18
19 test_expect_success 'diff without --binary' \
20 'git-diff | git-apply --stat --summary >current &&
21 cmp current - <<\EOF
22 a | 2 +-
23 b | Bin
24 c | 2 +-
25 d | Bin
26 4 files changed, 2 insertions(+), 2 deletions(-)
27 EOF'
28
29 test_expect_success 'diff with --binary' \
30 'git-diff --binary | git-apply --stat --summary >current &&
31 cmp current - <<\EOF
32 a | 2 +-
33 b | Bin
34 c | 2 +-
35 d | Bin
36 4 files changed, 2 insertions(+), 2 deletions(-)
37 EOF'
38
39 # apply needs to be able to skip the binary material correctly
40 # in order to report the line number of a corrupt patch.
41 test_expect_success 'apply detecting corrupt patch correctly' \
42 'git-diff | sed -e 's/-CIT/xCIT/' >broken &&
43 if git-apply --stat --summary broken 2>detected
44 then
45 echo unhappy - should have detected an error
46 (exit 1)
47 else
48 echo happy
49 fi &&
50 detected=`cat detected` &&
51 detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
52 detected=`sed -ne "${detected}p" broken` &&
53 test "$detected" = xCIT'
54
55 test_expect_success 'apply detecting corrupt patch correctly' \
56 'git-diff --binary | sed -e 's/-CIT/xCIT/' >broken &&
57 if git-apply --stat --summary broken 2>detected
58 then
59 echo unhappy - should have detected an error
60 (exit 1)
61 else
62 echo happy
63 fi &&
64 detected=`cat detected` &&
65 detected=`expr "$detected" : "fatal.*at line \\([0-9]*\\)\$"` &&
66 detected=`sed -ne "${detected}p" broken` &&
67 test "$detected" = xCIT'
68
69 test_expect_success 'initial commit' 'git-commit -a -m initial'
70
71 # Try removal (b), modification (d), and creation (e).
72 test_expect_success 'diff-index with --binary' \
73 'echo AIT >a && mv b e && echo CIT >c && cat e >d &&
74 git-update-index --add --remove a b c d e &&
75 tree0=`git-write-tree` &&
76 git-diff --cached --binary >current &&
77 git-apply --stat --summary current'
78
79 test_expect_success 'apply binary patch' \
80 'git-reset --hard &&
81 git-apply --binary --index <current &&
82 tree1=`git-write-tree` &&
83 test "$tree1" = "$tree0"'
84
85 test_done