]>
Commit | Line | Data |
---|---|---|
2c71810b JH |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2005 Junio C Hamano | |
4 | # | |
5 | ||
5be60078 | 6 | test_description='git apply symlinks and partial files |
2c71810b JH |
7 | |
8 | ' | |
9 | ||
9081a421 | 10 | TEST_PASSES_SANITIZE_LEAK=true |
2c71810b JH |
11 | . ./test-lib.sh |
12 | ||
889c6f0e | 13 | test_expect_success setup ' |
2c71810b | 14 | |
889c6f0e | 15 | test_ln_s_add path1/path2/path3/path4/path5 link1 && |
2c71810b JH |
16 | git commit -m initial && |
17 | ||
18 | git branch side && | |
19 | ||
20 | rm -f link? && | |
21 | ||
889c6f0e | 22 | test_ln_s_add htap6 link1 && |
2c71810b JH |
23 | git commit -m second && |
24 | ||
25 | git diff-tree -p HEAD^ HEAD >patch && | |
26 | git apply --stat --summary patch | |
27 | ||
28 | ' | |
29 | ||
41be8ea2 | 30 | test_expect_success SYMLINKS 'apply symlink patch' ' |
2c71810b JH |
31 | |
32 | git checkout side && | |
33 | git apply patch && | |
34 | git diff-files -p >patched && | |
3af82863 | 35 | test_cmp patch patched |
2c71810b JH |
36 | |
37 | ' | |
38 | ||
889c6f0e | 39 | test_expect_success 'apply --index symlink patch' ' |
2c71810b JH |
40 | |
41 | git checkout -f side && | |
42 | git apply --index patch && | |
43 | git diff-index --cached -p HEAD >patched && | |
3af82863 | 44 | test_cmp patch patched |
2c71810b JH |
45 | |
46 | ' | |
47 | ||
fade728d PS |
48 | test_expect_success 'symlink setup' ' |
49 | ln -s .git symlink && | |
50 | git add symlink && | |
51 | git commit -m "add symlink" | |
52 | ' | |
53 | ||
54 | test_expect_success SYMLINKS 'symlink escape when creating new files' ' | |
55 | test_when_finished "git reset --hard && git clean -dfx" && | |
56 | ||
57 | cat >patch <<-EOF && | |
58 | diff --git a/symlink b/renamed-symlink | |
59 | similarity index 100% | |
60 | rename from symlink | |
61 | rename to renamed-symlink | |
62 | -- | |
63 | diff --git /dev/null b/renamed-symlink/create-me | |
64 | new file mode 100644 | |
65 | index 0000000..039727e | |
66 | --- /dev/null | |
67 | +++ b/renamed-symlink/create-me | |
68 | @@ -0,0 +1,1 @@ | |
69 | +busted | |
70 | EOF | |
71 | ||
72 | test_must_fail git apply patch 2>stderr && | |
73 | cat >expected_stderr <<-EOF && | |
74 | error: affected file ${SQ}renamed-symlink/create-me${SQ} is beyond a symbolic link | |
75 | EOF | |
76 | test_cmp expected_stderr stderr && | |
c2059236 | 77 | test_path_is_missing .git/create-me |
fade728d PS |
78 | ' |
79 | ||
80 | test_expect_success SYMLINKS 'symlink escape when modifying file' ' | |
81 | test_when_finished "git reset --hard && git clean -dfx" && | |
82 | touch .git/modify-me && | |
83 | ||
84 | cat >patch <<-EOF && | |
85 | diff --git a/symlink b/renamed-symlink | |
86 | similarity index 100% | |
87 | rename from symlink | |
88 | rename to renamed-symlink | |
89 | -- | |
90 | diff --git a/renamed-symlink/modify-me b/renamed-symlink/modify-me | |
91 | index 1111111..2222222 100644 | |
92 | --- a/renamed-symlink/modify-me | |
93 | +++ b/renamed-symlink/modify-me | |
94 | @@ -0,0 +1,1 @@ | |
95 | +busted | |
96 | EOF | |
97 | ||
98 | test_must_fail git apply patch 2>stderr && | |
99 | cat >expected_stderr <<-EOF && | |
100 | error: renamed-symlink/modify-me: No such file or directory | |
101 | EOF | |
102 | test_cmp expected_stderr stderr && | |
103 | test_must_be_empty .git/modify-me | |
104 | ' | |
105 | ||
106 | test_expect_success SYMLINKS 'symlink escape when deleting file' ' | |
107 | test_when_finished "git reset --hard && git clean -dfx && rm .git/delete-me" && | |
108 | touch .git/delete-me && | |
109 | ||
110 | cat >patch <<-EOF && | |
111 | diff --git a/symlink b/renamed-symlink | |
112 | similarity index 100% | |
113 | rename from symlink | |
114 | rename to renamed-symlink | |
115 | -- | |
116 | diff --git a/renamed-symlink/delete-me b/renamed-symlink/delete-me | |
117 | deleted file mode 100644 | |
118 | index 1111111..0000000 100644 | |
119 | EOF | |
120 | ||
121 | test_must_fail git apply patch 2>stderr && | |
122 | cat >expected_stderr <<-EOF && | |
123 | error: renamed-symlink/delete-me: No such file or directory | |
124 | EOF | |
125 | test_cmp expected_stderr stderr && | |
126 | test_path_is_file .git/delete-me | |
127 | ' | |
128 | ||
9db05711 JS |
129 | test_expect_success SYMLINKS '--reject removes .rej symlink if it exists' ' |
130 | test_when_finished "git reset --hard && git clean -dfx" && | |
131 | ||
132 | test_commit file && | |
133 | echo modified >file.t && | |
134 | git diff -- file.t >patch && | |
135 | echo modified-again >file.t && | |
136 | ||
137 | ln -s foo file.t.rej && | |
138 | test_must_fail git apply patch --reject 2>err && | |
6789275d | 139 | test_grep "Rejected hunk" err && |
9db05711 JS |
140 | test_path_is_missing foo && |
141 | test_path_is_file file.t.rej | |
142 | ' | |
143 | ||
2c71810b | 144 | test_done |