Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2005 Junio C Hamano |
| 4 | # |
| 5 | |
| 6 | test_description='Break and then rename |
| 7 | |
| 8 | We have two very different files, file0 and file1, registered in a tree. |
| 9 | |
| 10 | We update file1 so drastically that it is more similar to file0, and |
| 11 | then remove file0. With -B, changes to file1 should be broken into |
| 12 | separate delete and create, resulting in removal of file0, removal of |
| 13 | original file1 and creation of completely rewritten file1. |
| 14 | |
| 15 | Further, with -B and -M together, these three modifications should |
| 16 | turn into rename-edit of file0 into file1. |
| 17 | |
| 18 | Starting from the same two files in the tree, we swap file0 and file1. |
| 19 | With -B, this should be detected as two complete rewrites, resulting in |
| 20 | four changes in total. |
| 21 | |
| 22 | Further, with -B and -M together, these should turn into two renames. |
| 23 | ' |
| 24 | . ./test-lib.sh |
Junio C Hamano | edb0c72 | 2005-05-31 14:47:25 -0700 | [diff] [blame] | 25 | . ../diff-lib.sh ;# test-lib chdir's into trash |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 26 | |
| 27 | test_expect_success \ |
| 28 | setup \ |
| 29 | 'cat ../../README >file0 && |
| 30 | cat ../../COPYING >file1 && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 31 | git update-index --add file0 file1 && |
| 32 | tree=$(git write-tree) && |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 33 | echo "$tree"' |
| 34 | |
| 35 | test_expect_success \ |
| 36 | 'change file1 with copy-edit of file0 and remove file0' \ |
| 37 | 'sed -e "s/git/GIT/" file0 >file1 && |
| 38 | rm -f file0 && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 39 | git update-index --remove file0 file1' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 40 | |
| 41 | test_expect_success \ |
| 42 | 'run diff with -B' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 43 | 'git diff-index -B --cached "$tree" >current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 44 | |
| 45 | cat >expected <<\EOF |
| 46 | :100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 0000000000000000000000000000000000000000 D file0 |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 47 | :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 11e331465a89c394dc25c780de230043750c1ec8 M100 file1 |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 48 | EOF |
| 49 | |
| 50 | test_expect_success \ |
| 51 | 'validate result of -B (#1)' \ |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 52 | 'compare_diff_raw expected current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 53 | |
| 54 | test_expect_success \ |
| 55 | 'run diff with -B and -M' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 56 | 'git diff-index -B -M "$tree" >current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 57 | |
| 58 | cat >expected <<\EOF |
| 59 | :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 08bb2fb671deff4c03a4d4a0a1315dff98d5732c R100 file0 file1 |
| 60 | EOF |
| 61 | |
| 62 | test_expect_success \ |
| 63 | 'validate result of -B -M (#2)' \ |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 64 | 'compare_diff_raw expected current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 65 | |
| 66 | test_expect_success \ |
| 67 | 'swap file0 and file1' \ |
| 68 | 'rm -f file0 file1 && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 69 | git read-tree -m $tree && |
| 70 | git checkout-index -f -u -a && |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 71 | mv file0 tmp && |
| 72 | mv file1 file0 && |
| 73 | mv tmp file1 && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 74 | git update-index file0 file1' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 75 | |
| 76 | test_expect_success \ |
| 77 | 'run diff with -B' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 78 | 'git diff-index -B "$tree" >current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 79 | |
| 80 | cat >expected <<\EOF |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 81 | :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 6ff87c4664981e4397625791c8ea3bbb5f2279a3 M100 file0 |
| 82 | :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M100 file1 |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 83 | EOF |
| 84 | |
| 85 | test_expect_success \ |
| 86 | 'validate result of -B (#3)' \ |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 87 | 'compare_diff_raw expected current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 88 | |
| 89 | test_expect_success \ |
| 90 | 'run diff with -B and -M' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 91 | 'git diff-index -B -M "$tree" >current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 92 | |
| 93 | cat >expected <<\EOF |
| 94 | :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 6ff87c4664981e4397625791c8ea3bbb5f2279a3 R100 file1 file0 |
| 95 | :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 R100 file0 file1 |
| 96 | EOF |
| 97 | |
| 98 | test_expect_success \ |
| 99 | 'validate result of -B -M (#4)' \ |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 100 | 'compare_diff_raw expected current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 101 | |
| 102 | test_expect_success \ |
| 103 | 'make file0 into something completely different' \ |
| 104 | 'rm -f file0 && |
| 105 | ln -s frotz file0 && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 106 | git update-index file0 file1' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 107 | |
| 108 | test_expect_success \ |
| 109 | 'run diff with -B' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 110 | 'git diff-index -B "$tree" >current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 111 | |
| 112 | cat >expected <<\EOF |
| 113 | :100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 67be421f88824578857624f7b3dc75e99a8a1481 T file0 |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 114 | :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M100 file1 |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 115 | EOF |
| 116 | |
| 117 | test_expect_success \ |
| 118 | 'validate result of -B (#5)' \ |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 119 | 'compare_diff_raw expected current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 120 | |
| 121 | test_expect_success \ |
| 122 | 'run diff with -B' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 123 | 'git diff-index -B -M "$tree" >current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 124 | |
| 125 | # This should not mistake file0 as the copy source of new file1 |
| 126 | # due to type differences. |
| 127 | cat >expected <<\EOF |
| 128 | :100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 67be421f88824578857624f7b3dc75e99a8a1481 T file0 |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 129 | :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M100 file1 |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 130 | EOF |
| 131 | |
| 132 | test_expect_success \ |
| 133 | 'validate result of -B -M (#6)' \ |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 134 | 'compare_diff_raw expected current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 135 | |
| 136 | test_expect_success \ |
| 137 | 'run diff with -M' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 138 | 'git diff-index -M "$tree" >current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 139 | |
| 140 | # This should not mistake file0 as the copy source of new file1 |
| 141 | # due to type differences. |
| 142 | cat >expected <<\EOF |
| 143 | :100644 120000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 67be421f88824578857624f7b3dc75e99a8a1481 T file0 |
| 144 | :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 M file1 |
| 145 | EOF |
| 146 | |
| 147 | test_expect_success \ |
| 148 | 'validate result of -M (#7)' \ |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 149 | 'compare_diff_raw expected current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 150 | |
| 151 | test_expect_success \ |
| 152 | 'file1 edited to look like file0 and file0 rename-edited to file2' \ |
| 153 | 'rm -f file0 file1 && |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 154 | git read-tree -m $tree && |
| 155 | git checkout-index -f -u -a && |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 156 | sed -e "s/git/GIT/" file0 >file1 && |
| 157 | sed -e "s/git/GET/" file0 >file2 && |
| 158 | rm -f file0 |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 159 | git update-index --add --remove file0 file1 file2' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 160 | |
| 161 | test_expect_success \ |
| 162 | 'run diff with -B' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 163 | 'git diff-index -B "$tree" >current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 164 | |
| 165 | cat >expected <<\EOF |
| 166 | :100644 000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 0000000000000000000000000000000000000000 D file0 |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 167 | :100644 100644 6ff87c4664981e4397625791c8ea3bbb5f2279a3 08bb2fb671deff4c03a4d4a0a1315dff98d5732c M100 file1 |
Junio C Hamano | 2bbcdde | 2005-07-26 00:22:43 -0700 | [diff] [blame] | 168 | :000000 100644 0000000000000000000000000000000000000000 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 A file2 |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 169 | EOF |
| 170 | |
| 171 | test_expect_success \ |
| 172 | 'validate result of -B (#8)' \ |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 173 | 'compare_diff_raw expected current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 174 | |
| 175 | test_expect_success \ |
| 176 | 'run diff with -B -M' \ |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 177 | 'git diff-index -B -M "$tree" >current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 178 | |
| 179 | cat >expected <<\EOF |
| 180 | :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 08bb2fb671deff4c03a4d4a0a1315dff98d5732c C095 file0 file1 |
| 181 | :100644 100644 f5deac7be59e7eeab8657fd9ae706fd6a57daed2 59f832e5c8b3f7e486be15ad0cd3e95ba9af8998 R095 file0 file2 |
| 182 | EOF |
| 183 | |
| 184 | test_expect_success \ |
| 185 | 'validate result of -B -M (#9)' \ |
Junio C Hamano | 366175e | 2005-06-19 13:17:50 -0700 | [diff] [blame] | 186 | 'compare_diff_raw expected current' |
Junio C Hamano | f345b0a | 2005-05-30 00:08:37 -0700 | [diff] [blame] | 187 | |
| 188 | test_done |