blob: bb6ba69258237ed40e736a0a7e218d621164998a [file] [log] [blame]
Junio C Hamano15d061b2005-05-27 15:55:55 -07001#!/bin/sh
2#
3# Copyright (c) 2005 Junio C Hamano
4#
5
6test_description='Rename interaction with pathspec.
7
8'
9. ./test-lib.sh
Junio C Hamanoedb0c722005-05-31 14:47:25 -070010. ../diff-lib.sh ;# test-lib chdir's into trash
Junio C Hamano15d061b2005-05-27 15:55:55 -070011
12test_expect_success \
13 'prepare reference tree' \
14 'mkdir path0 path1 &&
15 cp ../../COPYING path0/COPYING &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -070016 git-update-index --add path0/COPYING &&
Junio C Hamano15d061b2005-05-27 15:55:55 -070017 tree=$(git-write-tree) &&
18 echo $tree'
19
20test_expect_success \
21 'prepare work tree' \
22 'cp path0/COPYING path1/COPYING &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -070023 git-update-index --add --remove path0/COPYING path1/COPYING'
Junio C Hamano15d061b2005-05-27 15:55:55 -070024
25# In the tree, there is only path0/COPYING. In the cache, path0 and
26# path1 both have COPYING and the latter is a copy of path0/COPYING.
27# Comparing the full tree with cache should tell us so.
28
Junio C Hamano215a7ad2005-09-07 17:26:23 -070029git-diff-index -C --find-copies-harder $tree >current
Junio C Hamano15d061b2005-05-27 15:55:55 -070030
31cat >expected <<\EOF
32:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 C100 path0/COPYING path1/COPYING
33EOF
34
35test_expect_success \
Junio C Hamano6145ee82005-05-27 15:56:17 -070036 'validate the result (#1)' \
Junio C Hamano15d061b2005-05-27 15:55:55 -070037 'compare_diff_raw current expected'
38
39# In the tree, there is only path0/COPYING. In the cache, path0 and
40# path1 both have COPYING and the latter is a copy of path0/COPYING.
Junio C Hamano6145ee82005-05-27 15:56:17 -070041# However when we say we care only about path1, we should just see
42# path1/COPYING suddenly appearing from nowhere, not detected as
43# a copy from path0/COPYING.
Junio C Hamano15d061b2005-05-27 15:55:55 -070044
Junio C Hamano215a7ad2005-09-07 17:26:23 -070045git-diff-index -C $tree path1 >current
Junio C Hamano15d061b2005-05-27 15:55:55 -070046
47cat >expected <<\EOF
Junio C Hamano2bbcdde2005-07-26 00:22:43 -070048:000000 100644 0000000000000000000000000000000000000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 A path1/COPYING
Junio C Hamano15d061b2005-05-27 15:55:55 -070049EOF
50
51test_expect_success \
Junio C Hamano6145ee82005-05-27 15:56:17 -070052 'validate the result (#2)' \
Junio C Hamano15d061b2005-05-27 15:55:55 -070053 'compare_diff_raw current expected'
54
55test_expect_success \
56 'tweak work tree' \
57 'rm -f path0/COPYING &&
Junio C Hamano215a7ad2005-09-07 17:26:23 -070058 git-update-index --remove path0/COPYING'
Junio C Hamano15d061b2005-05-27 15:55:55 -070059
60# In the tree, there is only path0/COPYING. In the cache, path0 does
61# not have COPYING anymore and path1 has COPYING which is a copy of
62# path0/COPYING. Showing the full tree with cache should tell us about
63# the rename.
64
Junio C Hamano215a7ad2005-09-07 17:26:23 -070065git-diff-index -C $tree >current
Junio C Hamano15d061b2005-05-27 15:55:55 -070066
67cat >expected <<\EOF
68:100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 path0/COPYING path1/COPYING
69EOF
70
71test_expect_success \
Junio C Hamano6145ee82005-05-27 15:56:17 -070072 'validate the result (#3)' \
Junio C Hamano15d061b2005-05-27 15:55:55 -070073 'compare_diff_raw current expected'
74
75# In the tree, there is only path0/COPYING. In the cache, path0 does
76# not have COPYING anymore and path1 has COPYING which is a copy of
Junio C Hamano6145ee82005-05-27 15:56:17 -070077# path0/COPYING. When we say we care only about path1, we should just
78# see path1/COPYING appearing from nowhere.
Junio C Hamano15d061b2005-05-27 15:55:55 -070079
Junio C Hamano215a7ad2005-09-07 17:26:23 -070080git-diff-index -C $tree path1 >current
Junio C Hamano15d061b2005-05-27 15:55:55 -070081
82cat >expected <<\EOF
Junio C Hamano2bbcdde2005-07-26 00:22:43 -070083:000000 100644 0000000000000000000000000000000000000000 6ff87c4664981e4397625791c8ea3bbb5f2279a3 A path1/COPYING
Junio C Hamano15d061b2005-05-27 15:55:55 -070084EOF
85
86test_expect_success \
Junio C Hamano6145ee82005-05-27 15:56:17 -070087 'validate the result (#4)' \
Junio C Hamano15d061b2005-05-27 15:55:55 -070088 'compare_diff_raw current expected'
89
90test_done