summaryrefslogtreecommitdiff
path: root/t/t4115-apply-symlink.sh
diff options
context:
space:
mode:
authorJohannes Schindelin <johannes.schindelin@gmx.de>2023-03-09 15:02:54 (GMT)
committerJohannes Schindelin <johannes.schindelin@gmx.de>2023-04-17 19:15:38 (GMT)
commit9db05711c98efc14f414d4c87135a34c13586e0b (patch)
tree20f2b635d2612ce45fd88178a0012d884f667795 /t/t4115-apply-symlink.sh
parent2f3b28f27234a0130583131a6785c44e3dd1cac4 (diff)
downloadgit-9db05711c98efc14f414d4c87135a34c13586e0b.zip
git-9db05711c98efc14f414d4c87135a34c13586e0b.tar.gz
git-9db05711c98efc14f414d4c87135a34c13586e0b.tar.bz2
apply --reject: overwrite existing `.rej` symlink if it exists
The `git apply --reject` is expected to write out `.rej` files in case one or more hunks fail to apply cleanly. Historically, the command overwrites any existing `.rej` files. The idea being that apply/reject/edit cycles are relatively common, and the generated `.rej` files are not considered precious. But the command does not overwrite existing `.rej` symbolic links, and instead follows them. This is unsafe because the same patch could potentially create such a symbolic link and point at arbitrary paths outside the current worktree, and `git apply` would write the contents of the `.rej` file into that location. Therefore, let's make sure that any existing `.rej` file or symbolic link is removed before writing it. Reported-by: RyotaK <ryotak.mail@gmail.com> Helped-by: Taylor Blau <me@ttaylorr.com> Helped-by: Junio C Hamano <gitster@pobox.com> Helped-by: Linus Torvalds <torvalds@linuxfoundation.org> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Diffstat (limited to 't/t4115-apply-symlink.sh')
-rwxr-xr-xt/t4115-apply-symlink.sh15
1 files changed, 15 insertions, 0 deletions
diff --git a/t/t4115-apply-symlink.sh b/t/t4115-apply-symlink.sh
index 14e0f4d..2d03c4e 100755
--- a/t/t4115-apply-symlink.sh
+++ b/t/t4115-apply-symlink.sh
@@ -125,4 +125,19 @@ test_expect_success SYMLINKS 'symlink escape when deleting file' '
test_path_is_file .git/delete-me
'
+test_expect_success SYMLINKS '--reject removes .rej symlink if it exists' '
+ test_when_finished "git reset --hard && git clean -dfx" &&
+
+ test_commit file &&
+ echo modified >file.t &&
+ git diff -- file.t >patch &&
+ echo modified-again >file.t &&
+
+ ln -s foo file.t.rej &&
+ test_must_fail git apply patch --reject 2>err &&
+ test_i18ngrep "Rejected hunk" err &&
+ test_path_is_missing foo &&
+ test_path_is_file file.t.rej
+'
+
test_done