1#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Same rename detection as t4003 but testing diff-raw -z.
7
8'
9. ./test-lib.sh
10. "$TEST_DIRECTORY"/lib-diff.sh ;# test-lib chdir's into trash
11
12test_expect_success \
13    'prepare reference tree' \
14    'COPYING_test_data >COPYING &&
15     echo frotz >rezrov &&
16    git update-index --add COPYING rezrov &&
17    orig=$(git hash-object COPYING) &&
18    tree=$(git write-tree) &&
19    echo $tree'
20
21test_expect_success \
22    'prepare work tree' \
23    'sed -e 's/HOWEVER/However/' <COPYING >COPYING.1 &&
24    sed -e 's/GPL/G.P.L/g' <COPYING >COPYING.2 &&
25    rm -f COPYING &&
26    c1=$(git hash-object COPYING.1) &&
27    c2=$(git hash-object COPYING.2) &&
28    git update-index --add --remove COPYING COPYING.?'
29
30# tree has COPYING and rezrov.  work tree has COPYING.1 and COPYING.2,
31# both are slightly edited, and unchanged rezrov.  We say COPYING.1
32# and COPYING.2 are based on COPYING, and do not say anything about
33# rezrov.
34
35git diff-index -z -C $tree >current
36
37cat >expected <<EOF
38:100644 100644 $orig $c1 C1234
39COPYING
40COPYING.1
41:100644 100644 $orig $c2 R1234
42COPYING
43COPYING.2
44EOF
45
46test_expect_success \
47    'validate output from rename/copy detection (#1)' \
48    'compare_diff_raw_z current expected'
49
50################################################################
51
52test_expect_success \
53    'prepare work tree again' \
54    'mv COPYING.2 COPYING &&
55     git update-index --add --remove COPYING COPYING.1 COPYING.2'
56
57# tree has COPYING and rezrov.  work tree has COPYING and COPYING.1,
58# both are slightly edited, and unchanged rezrov.  We say COPYING.1
59# is based on COPYING and COPYING is still there, and do not say anything
60# about rezrov.
61
62git diff-index -z -C $tree >current
63cat >expected <<EOF
64:100644 100644 $orig $c2 M
65COPYING
66:100644 100644 $orig $c1 C1234
67COPYING
68COPYING.1
69EOF
70
71test_expect_success \
72    'validate output from rename/copy detection (#2)' \
73    'compare_diff_raw_z current expected'
74
75################################################################
76
77# tree has COPYING and rezrov.  work tree has the same COPYING and
78# copy-edited COPYING.1, and unchanged rezrov.  We should not say
79# anything about rezrov or COPYING, since the revised again diff-raw
80# nows how to say Copy.
81
82test_expect_success \
83    'prepare work tree once again' \
84    'COPYING_test_data >COPYING &&
85     git update-index --add --remove COPYING COPYING.1'
86
87git diff-index -z -C --find-copies-harder $tree >current
88cat >expected <<EOF
89:100644 100644 $orig $c1 C1234
90COPYING
91COPYING.1
92EOF
93
94test_expect_success \
95    'validate output from rename/copy detection (#3)' \
96    'compare_diff_raw_z current expected'
97
98test_done
99