[PATCH] diff-helper: Fix R/C score parsing under -z flag.
[alt-git.git] / t / t4007-rename-3.sh
blob76ae7201f0d19b7933ca44958b7c468193ec9778
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='Rename interaction with pathspec.
9 . ./test-lib.sh
11 _x40='[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f]'
12 _x40="$_x40$_x40$_x40$_x40$_x40$_x40$_x40$_x40"
13 sanitize_diff_raw='s/ '"$_x40"' '"$_x40"' \([A-Z]\)[0-9]* / X X \1# /'
14 compare_diff_raw () {
15 # When heuristics are improved, the score numbers would change.
16 # Ignore them while comparing.
17 # Also we do not check SHA1 hash generation in this test, which
18 # is a job for t0000-basic.sh
20 sed -e "$sanitize_diff_raw" <"$1" >.tmp-1
21 sed -e "$sanitize_diff_raw" <"$2" >.tmp-2
22 diff -u .tmp-1 .tmp-2 && rm -f .tmp-1 .tmp-2
25 test_expect_success \
26 'prepare reference tree' \
27 'mkdir path0 path1 &&
28 cp ../../COPYING path0/COPYING &&
29 git-update-cache --add path0/COPYING &&
30 tree=$(git-write-tree) &&
31 echo $tree'
33 test_expect_success \
34 'prepare work tree' \
35 'cp path0/COPYING path1/COPYING &&
36 git-update-cache --add --remove path0/COPYING path1/COPYING'
38 # In the tree, there is only path0/COPYING. In the cache, path0 and
39 # path1 both have COPYING and the latter is a copy of path0/COPYING.
40 # Comparing the full tree with cache should tell us so.
42 git-diff-cache -C $tree >current
44 cat >expected <<\EOF
45 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 C100 path0/COPYING path1/COPYING
46 EOF
48 test_expect_success \
49 'validate the result (#1)' \
50 'compare_diff_raw current expected'
52 # In the tree, there is only path0/COPYING. In the cache, path0 and
53 # path1 both have COPYING and the latter is a copy of path0/COPYING.
54 # However when we say we care only about path1, we should just see
55 # path1/COPYING suddenly appearing from nowhere, not detected as
56 # a copy from path0/COPYING.
58 git-diff-cache -C $tree path1 >current
60 cat >expected <<\EOF
61 :000000 100644 0000000000000000000000000000000000000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 N path1/COPYING
62 EOF
64 test_expect_success \
65 'validate the result (#2)' \
66 'compare_diff_raw current expected'
68 test_expect_success \
69 'tweak work tree' \
70 'rm -f path0/COPYING &&
71 git-update-cache --remove path0/COPYING'
73 # In the tree, there is only path0/COPYING. In the cache, path0 does
74 # not have COPYING anymore and path1 has COPYING which is a copy of
75 # path0/COPYING. Showing the full tree with cache should tell us about
76 # the rename.
78 git-diff-cache -C $tree >current
80 cat >expected <<\EOF
81 :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 path0/COPYING path1/COPYING
82 EOF
84 test_expect_success \
85 'validate the result (#3)' \
86 'compare_diff_raw current expected'
88 # In the tree, there is only path0/COPYING. In the cache, path0 does
89 # not have COPYING anymore and path1 has COPYING which is a copy of
90 # path0/COPYING. When we say we care only about path1, we should just
91 # see path1/COPYING appearing from nowhere.
93 git-diff-cache -C $tree path1 >current
95 cat >expected <<\EOF
96 :000000 100644 0000000000000000000000000000000000000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 N path1/COPYING
97 EOF
99 test_expect_success \
100 'validate the result (#4)' \
101 'compare_diff_raw current expected'
103 test_done