Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | # |
| 3 | # Copyright (c) 2006 Eric Wong |
| 4 | # |
| 5 | |
Junio C Hamano | 5be6007 | 2007-07-02 22:52:14 -0700 | [diff] [blame] | 6 | test_description='git apply should not get confused with type changes. |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 7 | |
| 8 | ' |
| 9 | |
Ævar Arnfjörð Bjarmason | 3e3b932 | 2022-07-28 01:13:41 +0200 | [diff] [blame] | 10 | TEST_PASSES_SANITIZE_LEAK=true |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 11 | . ./test-lib.sh |
| 12 | |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 13 | test_expect_success 'setup repository and commits' ' |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 14 | echo "hello world" > foo && |
| 15 | echo "hi planet" > bar && |
| 16 | git update-index --add foo bar && |
| 17 | git commit -m initial && |
| 18 | git branch initial && |
| 19 | rm -f foo && |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 20 | test_ln_s_add bar foo && |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 21 | git commit -m "foo symlinked to bar" && |
| 22 | git branch foo-symlinked-to-bar && |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 23 | git rm -f foo && |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 24 | echo "how far is the sun?" > foo && |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 25 | git update-index --add foo && |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 26 | git commit -m "foo back to file" && |
| 27 | git branch foo-back-to-file && |
Junio C Hamano | b67b961 | 2009-01-26 00:08:24 -0800 | [diff] [blame] | 28 | printf "\0" > foo && |
| 29 | git update-index foo && |
| 30 | git commit -m "foo becomes binary" && |
| 31 | git branch foo-becomes-binary && |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 32 | rm -f foo && |
| 33 | git update-index --remove foo && |
| 34 | mkdir foo && |
| 35 | echo "if only I knew" > foo/baz && |
| 36 | git update-index --add foo/baz && |
| 37 | git commit -m "foo becomes a directory" && |
| 38 | git branch "foo-becomes-a-directory" && |
| 39 | echo "hello world" > foo/baz && |
| 40 | git update-index foo/baz && |
| 41 | git commit -m "foo/baz is the original foo" && |
| 42 | git branch foo-baz-renamed-from-foo |
| 43 | ' |
| 44 | |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 45 | test_expect_success 'file renamed from foo to foo/baz' ' |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 46 | git checkout -f initial && |
| 47 | git diff-tree -M -p HEAD foo-baz-renamed-from-foo > patch && |
| 48 | git apply --index < patch |
| 49 | ' |
| 50 | test_debug 'cat patch' |
| 51 | |
| 52 | |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 53 | test_expect_success 'file renamed from foo/baz to foo' ' |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 54 | git checkout -f foo-baz-renamed-from-foo && |
| 55 | git diff-tree -M -p HEAD initial > patch && |
| 56 | git apply --index < patch |
| 57 | ' |
| 58 | test_debug 'cat patch' |
| 59 | |
| 60 | |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 61 | test_expect_success 'directory becomes file' ' |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 62 | git checkout -f foo-becomes-a-directory && |
| 63 | git diff-tree -p HEAD initial > patch && |
| 64 | git apply --index < patch |
| 65 | ' |
| 66 | test_debug 'cat patch' |
| 67 | |
| 68 | |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 69 | test_expect_success 'file becomes directory' ' |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 70 | git checkout -f initial && |
| 71 | git diff-tree -p HEAD foo-becomes-a-directory > patch && |
| 72 | git apply --index < patch |
| 73 | ' |
| 74 | test_debug 'cat patch' |
| 75 | |
| 76 | |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 77 | test_expect_success 'file becomes symlink' ' |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 78 | git checkout -f initial && |
| 79 | git diff-tree -p HEAD foo-symlinked-to-bar > patch && |
| 80 | git apply --index < patch |
| 81 | ' |
| 82 | test_debug 'cat patch' |
| 83 | |
| 84 | |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 85 | test_expect_success 'symlink becomes file' ' |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 86 | git checkout -f foo-symlinked-to-bar && |
| 87 | git diff-tree -p HEAD foo-back-to-file > patch && |
| 88 | git apply --index < patch |
| 89 | ' |
| 90 | test_debug 'cat patch' |
| 91 | |
Jonathan Tan | b0f266d | 2020-10-20 15:04:52 -0700 | [diff] [blame] | 92 | test_expect_success 'symlink becomes file, in reverse' ' |
| 93 | git checkout -f foo-symlinked-to-bar && |
| 94 | git diff-tree -p HEAD foo-back-to-file > patch && |
| 95 | git checkout foo-back-to-file && |
| 96 | git apply -R --index < patch |
| 97 | ' |
| 98 | |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 99 | test_expect_success 'binary file becomes symlink' ' |
Junio C Hamano | b67b961 | 2009-01-26 00:08:24 -0800 | [diff] [blame] | 100 | git checkout -f foo-becomes-binary && |
| 101 | git diff-tree -p --binary HEAD foo-symlinked-to-bar > patch && |
| 102 | git apply --index < patch |
| 103 | ' |
| 104 | test_debug 'cat patch' |
| 105 | |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 106 | test_expect_success 'symlink becomes binary file' ' |
Junio C Hamano | b67b961 | 2009-01-26 00:08:24 -0800 | [diff] [blame] | 107 | git checkout -f foo-symlinked-to-bar && |
| 108 | git diff-tree -p --binary HEAD foo-becomes-binary > patch && |
| 109 | git apply --index < patch |
| 110 | ' |
| 111 | test_debug 'cat patch' |
| 112 | |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 113 | |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 114 | test_expect_success 'symlink becomes directory' ' |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 115 | git checkout -f foo-symlinked-to-bar && |
| 116 | git diff-tree -p HEAD foo-becomes-a-directory > patch && |
| 117 | git apply --index < patch |
| 118 | ' |
| 119 | test_debug 'cat patch' |
| 120 | |
| 121 | |
Johannes Sixt | 622f98e | 2013-06-07 22:53:32 +0200 | [diff] [blame] | 122 | test_expect_success 'directory becomes symlink' ' |
Eric Wong | 8641fb2 | 2006-07-16 03:38:40 -0700 | [diff] [blame] | 123 | git checkout -f foo-becomes-a-directory && |
| 124 | git diff-tree -p HEAD foo-symlinked-to-bar > patch && |
| 125 | git apply --index < patch |
| 126 | ' |
| 127 | test_debug 'cat patch' |
| 128 | |
| 129 | |
| 130 | test_done |