| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git apply handling criss-cross rename patch.' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | create_file() { |
| 8 | cnt=0 |
| 9 | while test $cnt -le 100 |
| 10 | do |
| 11 | cnt=$(($cnt + 1)) |
| 12 | echo "$2" >> "$1" |
| 13 | done |
| 14 | } |
| 15 | |
| 16 | test_expect_success 'setup' ' |
| 17 | # Ensure that file sizes are different, because on Windows |
| 18 | # lstat() does not discover inode numbers, and we need |
| 19 | # other properties to discover swapped files |
| 20 | # (mtime is not always different, either). |
| 21 | create_file file1 "some content" && |
| 22 | create_file file2 "some other content" && |
| 23 | create_file file3 "again something else" && |
| 24 | git add file1 file2 file3 && |
| 25 | git commit -m 1 |
| 26 | ' |
| 27 | |
| 28 | test_expect_success 'criss-cross rename' ' |
| 29 | mv file1 tmp && |
| 30 | mv file2 file1 && |
| 31 | mv tmp file2 && |
| 32 | cp file1 file1-swapped && |
| 33 | cp file2 file2-swapped |
| 34 | ' |
| 35 | |
| 36 | test_expect_success 'diff -M -B' ' |
| 37 | git diff -M -B > diff && |
| 38 | git reset --hard |
| 39 | |
| 40 | ' |
| 41 | |
| 42 | test_expect_success 'apply' ' |
| 43 | git apply diff && |
| 44 | test_cmp file1 file1-swapped && |
| 45 | test_cmp file2 file2-swapped |
| 46 | ' |
| 47 | |
| 48 | test_expect_success 'criss-cross rename' ' |
| 49 | git reset --hard && |
| 50 | mv file1 tmp && |
| 51 | mv file2 file1 && |
| 52 | mv file3 file2 && |
| 53 | mv tmp file3 && |
| 54 | cp file1 file1-swapped && |
| 55 | cp file2 file2-swapped && |
| 56 | cp file3 file3-swapped |
| 57 | ' |
| 58 | |
| 59 | test_expect_success 'diff -M -B' ' |
| 60 | git diff -M -B > diff && |
| 61 | git reset --hard |
| 62 | ' |
| 63 | |
| 64 | test_expect_success 'apply' ' |
| 65 | git apply diff && |
| 66 | test_cmp file1 file1-swapped && |
| 67 | test_cmp file2 file2-swapped && |
| 68 | test_cmp file3 file3-swapped |
| 69 | ' |
| 70 | |
| 71 | test_done |