From c8bae7493d2f2910b57f13ded012e86bdcfb0532 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 16:47:53 +0200 Subject: Adding upstream version 1:2.39.2. Signed-off-by: Daniel Baumann --- t/t4127-apply-same-fn.sh | 98 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100755 t/t4127-apply-same-fn.sh (limited to 't/t4127-apply-same-fn.sh') diff --git a/t/t4127-apply-same-fn.sh b/t/t4127-apply-same-fn.sh new file mode 100755 index 0000000..aa5cfae --- /dev/null +++ b/t/t4127-apply-same-fn.sh @@ -0,0 +1,98 @@ +#!/bin/sh + +test_description='apply same filename' + + +TEST_PASSES_SANITIZE_LEAK=true +. ./test-lib.sh + +modify () { + sed -e "$1" < "$2" > "$2".x && + mv "$2".x "$2" +} + +test_expect_success setup ' + test_write_lines a b c d e f g h i j k l m >same_fn && + cp same_fn other_fn && + git add same_fn other_fn && + git commit -m initial +' +test_expect_success 'apply same filename with independent changes' ' + modify "s/^d/z/" same_fn && + git diff > patch0 && + git add same_fn && + modify "s/^i/y/" same_fn && + git diff >> patch0 && + cp same_fn same_fn2 && + git reset --hard && + git apply patch0 && + test_cmp same_fn same_fn2 +' + +test_expect_success 'apply same filename with overlapping changes' ' + git reset --hard && + + # Store same_fn so that we can check apply -R in next test + cp same_fn same_fn1 && + + modify "s/^d/z/" same_fn && + git diff > patch0 && + git add same_fn && + modify "s/^e/y/" same_fn && + git diff >> patch0 && + cp same_fn same_fn2 && + git reset --hard && + git apply patch0 && + test_cmp same_fn same_fn2 +' + +test_expect_success 'apply same filename with overlapping changes, in reverse' ' + git apply -R patch0 && + test_cmp same_fn same_fn1 +' + +test_expect_success 'apply same new filename after rename' ' + git reset --hard && + git mv same_fn new_fn && + modify "s/^d/z/" new_fn && + git add new_fn && + git diff -M --cached > patch1 && + modify "s/^e/y/" new_fn && + git diff >> patch1 && + cp new_fn new_fn2 && + git reset --hard && + git apply --index patch1 && + test_cmp new_fn new_fn2 +' + +test_expect_success 'apply same old filename after rename -- should fail.' ' + git reset --hard && + git mv same_fn new_fn && + modify "s/^d/z/" new_fn && + git add new_fn && + git diff -M --cached > patch1 && + git mv new_fn same_fn && + modify "s/^e/y/" same_fn && + git diff >> patch1 && + git reset --hard && + test_must_fail git apply patch1 +' + +test_expect_success 'apply A->B (rename), C->A (rename), A->A -- should pass.' ' + git reset --hard && + git mv same_fn new_fn && + modify "s/^d/z/" new_fn && + git add new_fn && + git diff -M --cached > patch1 && + git commit -m "a rename" && + git mv other_fn same_fn && + modify "s/^e/y/" same_fn && + git add same_fn && + git diff -M --cached >> patch1 && + modify "s/^g/x/" same_fn && + git diff >> patch1 && + git reset --hard HEAD^ && + git apply patch1 +' + +test_done -- cgit v1.2.3