Merge branch 'bb/iso-strict-utc'
[alt-git.git] / t / t4115-apply-symlink.sh
blobcbef0a593fb7ccfded7b9e97735c41dda0ce1cbd
1 #!/bin/sh
3 # Copyright (c) 2005 Junio C Hamano
6 test_description='git apply symlinks and partial files
10 TEST_PASSES_SANITIZE_LEAK=true
11 . ./test-lib.sh
13 test_expect_success setup '
15 test_ln_s_add path1/path2/path3/path4/path5 link1 &&
16 git commit -m initial &&
18 git branch side &&
20 rm -f link? &&
22 test_ln_s_add htap6 link1 &&
23 git commit -m second &&
25 git diff-tree -p HEAD^ HEAD >patch &&
26 git apply --stat --summary patch
30 test_expect_success SYMLINKS 'apply symlink patch' '
32 git checkout side &&
33 git apply patch &&
34 git diff-files -p >patched &&
35 test_cmp patch patched
39 test_expect_success 'apply --index symlink patch' '
41 git checkout -f side &&
42 git apply --index patch &&
43 git diff-index --cached -p HEAD >patched &&
44 test_cmp patch patched
48 test_expect_success 'symlink setup' '
49 ln -s .git symlink &&
50 git add symlink &&
51 git commit -m "add symlink"
54 test_expect_success SYMLINKS 'symlink escape when creating new files' '
55 test_when_finished "git reset --hard && git clean -dfx" &&
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
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
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 &&
77 test_path_is_missing .git/create-me
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 &&
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
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
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
102 test_cmp expected_stderr stderr &&
103 test_must_be_empty .git/modify-me
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 &&
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
116 diff --git a/renamed-symlink/delete-me b/renamed-symlink/delete-me
117 deleted file mode 100644
118 index 1111111..0000000 100644
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
125 test_cmp expected_stderr stderr &&
126 test_path_is_file .git/delete-me
129 test_expect_success SYMLINKS '--reject removes .rej symlink if it exists' '
130 test_when_finished "git reset --hard && git clean -dfx" &&
132 test_commit file &&
133 echo modified >file.t &&
134 git diff -- file.t >patch &&
135 echo modified-again >file.t &&
137 ln -s foo file.t.rej &&
138 test_must_fail git apply patch --reject 2>err &&
139 test_grep "Rejected hunk" err &&
140 test_path_is_missing foo &&
141 test_path_is_file file.t.rej
144 test_done