Git fork
at reftables-rust 97 lines 2.3 kB view raw
1#!/bin/sh 2 3test_description='apply same filename' 4 5 6. ./test-lib.sh 7 8modify () { 9 sed -e "$1" < "$2" > "$2".x && 10 mv "$2".x "$2" 11} 12 13test_expect_success setup ' 14 test_write_lines a b c d e f g h i j k l m >same_fn && 15 cp same_fn other_fn && 16 git add same_fn other_fn && 17 git commit -m initial 18' 19test_expect_success 'apply same filename with independent changes' ' 20 modify "s/^d/z/" same_fn && 21 git diff > patch0 && 22 git add same_fn && 23 modify "s/^i/y/" same_fn && 24 git diff >> patch0 && 25 cp same_fn same_fn2 && 26 git reset --hard && 27 git apply patch0 && 28 test_cmp same_fn same_fn2 29' 30 31test_expect_success 'apply same filename with overlapping changes' ' 32 git reset --hard && 33 34 # Store same_fn so that we can check apply -R in next test 35 cp same_fn same_fn1 && 36 37 modify "s/^d/z/" same_fn && 38 git diff > patch0 && 39 git add same_fn && 40 modify "s/^e/y/" same_fn && 41 git diff >> patch0 && 42 cp same_fn same_fn2 && 43 git reset --hard && 44 git apply patch0 && 45 test_cmp same_fn same_fn2 46' 47 48test_expect_success 'apply same filename with overlapping changes, in reverse' ' 49 git apply -R patch0 && 50 test_cmp same_fn same_fn1 51' 52 53test_expect_success 'apply same new filename after rename' ' 54 git reset --hard && 55 git mv same_fn new_fn && 56 modify "s/^d/z/" new_fn && 57 git add new_fn && 58 git diff -M --cached > patch1 && 59 modify "s/^e/y/" new_fn && 60 git diff >> patch1 && 61 cp new_fn new_fn2 && 62 git reset --hard && 63 git apply --index patch1 && 64 test_cmp new_fn new_fn2 65' 66 67test_expect_success 'apply same old filename after rename -- should fail.' ' 68 git reset --hard && 69 git mv same_fn new_fn && 70 modify "s/^d/z/" new_fn && 71 git add new_fn && 72 git diff -M --cached > patch1 && 73 git mv new_fn same_fn && 74 modify "s/^e/y/" same_fn && 75 git diff >> patch1 && 76 git reset --hard && 77 test_must_fail git apply patch1 78' 79 80test_expect_success 'apply A->B (rename), C->A (rename), A->A -- should pass.' ' 81 git reset --hard && 82 git mv same_fn new_fn && 83 modify "s/^d/z/" new_fn && 84 git add new_fn && 85 git diff -M --cached > patch1 && 86 git commit -m "a rename" && 87 git mv other_fn same_fn && 88 modify "s/^e/y/" same_fn && 89 git add same_fn && 90 git diff -M --cached >> patch1 && 91 modify "s/^g/x/" same_fn && 92 git diff >> patch1 && 93 git reset --hard HEAD^ && 94 git apply patch1 95' 96 97test_done