blob: ebadbc347fc4fd9d435a366e46e3e1cebba81b83 [file] [log] [blame]
Eric Wong8641fb22006-07-16 03:38:40 -07001#!/bin/sh
2#
3# Copyright (c) 2006 Eric Wong
4#
5
Junio C Hamano5be60072007-07-02 22:52:14 -07006test_description='git apply should not get confused with type changes.
Eric Wong8641fb22006-07-16 03:38:40 -07007
8'
9
10. ./test-lib.sh
11
Johannes Sixt622f98e2013-06-07 22:53:32 +020012test_expect_success 'setup repository and commits' '
Eric Wong8641fb22006-07-16 03:38:40 -070013 echo "hello world" > foo &&
14 echo "hi planet" > bar &&
15 git update-index --add foo bar &&
16 git commit -m initial &&
17 git branch initial &&
18 rm -f foo &&
Johannes Sixt622f98e2013-06-07 22:53:32 +020019 test_ln_s_add bar foo &&
Eric Wong8641fb22006-07-16 03:38:40 -070020 git commit -m "foo symlinked to bar" &&
21 git branch foo-symlinked-to-bar &&
Johannes Sixt622f98e2013-06-07 22:53:32 +020022 git rm -f foo &&
Eric Wong8641fb22006-07-16 03:38:40 -070023 echo "how far is the sun?" > foo &&
Johannes Sixt622f98e2013-06-07 22:53:32 +020024 git update-index --add foo &&
Eric Wong8641fb22006-07-16 03:38:40 -070025 git commit -m "foo back to file" &&
26 git branch foo-back-to-file &&
Junio C Hamanob67b9612009-01-26 00:08:24 -080027 printf "\0" > foo &&
28 git update-index foo &&
29 git commit -m "foo becomes binary" &&
30 git branch foo-becomes-binary &&
Eric Wong8641fb22006-07-16 03:38:40 -070031 rm -f foo &&
32 git update-index --remove foo &&
33 mkdir foo &&
34 echo "if only I knew" > foo/baz &&
35 git update-index --add foo/baz &&
36 git commit -m "foo becomes a directory" &&
37 git branch "foo-becomes-a-directory" &&
38 echo "hello world" > foo/baz &&
39 git update-index foo/baz &&
40 git commit -m "foo/baz is the original foo" &&
41 git branch foo-baz-renamed-from-foo
42 '
43
Johannes Sixt622f98e2013-06-07 22:53:32 +020044test_expect_success 'file renamed from foo to foo/baz' '
Eric Wong8641fb22006-07-16 03:38:40 -070045 git checkout -f initial &&
46 git diff-tree -M -p HEAD foo-baz-renamed-from-foo > patch &&
47 git apply --index < patch
48 '
49test_debug 'cat patch'
50
51
Johannes Sixt622f98e2013-06-07 22:53:32 +020052test_expect_success 'file renamed from foo/baz to foo' '
Eric Wong8641fb22006-07-16 03:38:40 -070053 git checkout -f foo-baz-renamed-from-foo &&
54 git diff-tree -M -p HEAD initial > patch &&
55 git apply --index < patch
56 '
57test_debug 'cat patch'
58
59
Johannes Sixt622f98e2013-06-07 22:53:32 +020060test_expect_success 'directory becomes file' '
Eric Wong8641fb22006-07-16 03:38:40 -070061 git checkout -f foo-becomes-a-directory &&
62 git diff-tree -p HEAD initial > patch &&
63 git apply --index < patch
64 '
65test_debug 'cat patch'
66
67
Johannes Sixt622f98e2013-06-07 22:53:32 +020068test_expect_success 'file becomes directory' '
Eric Wong8641fb22006-07-16 03:38:40 -070069 git checkout -f initial &&
70 git diff-tree -p HEAD foo-becomes-a-directory > patch &&
71 git apply --index < patch
72 '
73test_debug 'cat patch'
74
75
Johannes Sixt622f98e2013-06-07 22:53:32 +020076test_expect_success 'file becomes symlink' '
Eric Wong8641fb22006-07-16 03:38:40 -070077 git checkout -f initial &&
78 git diff-tree -p HEAD foo-symlinked-to-bar > patch &&
79 git apply --index < patch
80 '
81test_debug 'cat patch'
82
83
Johannes Sixt622f98e2013-06-07 22:53:32 +020084test_expect_success 'symlink becomes file' '
Eric Wong8641fb22006-07-16 03:38:40 -070085 git checkout -f foo-symlinked-to-bar &&
86 git diff-tree -p HEAD foo-back-to-file > patch &&
87 git apply --index < patch
88 '
89test_debug 'cat patch'
90
Johannes Sixt622f98e2013-06-07 22:53:32 +020091test_expect_success 'binary file becomes symlink' '
Junio C Hamanob67b9612009-01-26 00:08:24 -080092 git checkout -f foo-becomes-binary &&
93 git diff-tree -p --binary HEAD foo-symlinked-to-bar > patch &&
94 git apply --index < patch
95 '
96test_debug 'cat patch'
97
Johannes Sixt622f98e2013-06-07 22:53:32 +020098test_expect_success 'symlink becomes binary file' '
Junio C Hamanob67b9612009-01-26 00:08:24 -080099 git checkout -f foo-symlinked-to-bar &&
100 git diff-tree -p --binary HEAD foo-becomes-binary > patch &&
101 git apply --index < patch
102 '
103test_debug 'cat patch'
104
Eric Wong8641fb22006-07-16 03:38:40 -0700105
Johannes Sixt622f98e2013-06-07 22:53:32 +0200106test_expect_success 'symlink becomes directory' '
Eric Wong8641fb22006-07-16 03:38:40 -0700107 git checkout -f foo-symlinked-to-bar &&
108 git diff-tree -p HEAD foo-becomes-a-directory > patch &&
109 git apply --index < patch
110 '
111test_debug 'cat patch'
112
113
Johannes Sixt622f98e2013-06-07 22:53:32 +0200114test_expect_success 'directory becomes symlink' '
Eric Wong8641fb22006-07-16 03:38:40 -0700115 git checkout -f foo-becomes-a-directory &&
116 git diff-tree -p HEAD foo-symlinked-to-bar > patch &&
117 git apply --index < patch
118 '
119test_debug 'cat patch'
120
121
122test_done