Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/git/blob/master/t/t4128-apply-root.sh # git [Ported from github.com/git/git] Sync with Git 2.56.1 Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `master` Branches Tags History `git / t / t4128-apply-root.sh` 163 lines ยท 3884 bytes Raw Blame History 1 #!/bin/sh 2 3 test_description='apply same filename' 4 5 . ./test-lib.sh 6 7 test_expect_success 'setup' ' 8 9 mkdir -p some/sub/dir && 10 echo Hello > some/sub/dir/file && 11 git add some/sub/dir/file && 12 git commit -m initial && 13 git tag initial 14 15 ' 16 17 cat > patch << EOF 18 diff a/bla/blub/dir/file b/bla/blub/dir/file 19 --- a/bla/blub/dir/file 20 +++ b/bla/blub/dir/file 21 @@ -1,1 +1,1 @@ 22 -Hello 23 +Bello 24 EOF 25 26 test_expect_success 'apply --directory -p (1)' ' 27 git apply --directory=some/sub -p3 --index patch && 28 echo Bello >expect && 29 git show :some/sub/dir/file >actual && 30 test_cmp expect actual && 31 test_cmp expect some/sub/dir/file 32 33 ' 34 35 test_expect_success 'apply --directory -p (2) ' ' 36 37 git reset --hard initial && 38 git apply --directory=some/sub/ -p3 --index patch && 39 echo Bello >expect && 40 git show :some/sub/dir/file >actual && 41 test_cmp expect actual && 42 test_cmp expect some/sub/dir/file 43 44 ' 45 46 test_expect_success 'apply --directory (./ prefix)' ' 47 git reset --hard initial && 48 git apply --directory=./some/sub -p3 --index patch && 49 echo Bello >expect && 50 git show :some/sub/dir/file >actual && 51 test_cmp expect actual && 52 test_cmp expect some/sub/dir/file 53 ' 54 55 test_expect_success 'apply --directory (double slash)' ' 56 git reset --hard initial && 57 git apply --directory=some//sub -p3 --index patch && 58 echo Bello >expect && 59 git show :some/sub/dir/file >actual && 60 test_cmp expect actual && 61 test_cmp expect some/sub/dir/file 62 ' 63 64 test_expect_success 'apply --directory (./ in the middle)' ' 65 git reset --hard initial && 66 git apply --directory=some/./sub -p3 --index patch && 67 echo Bello >expect && 68 git show :some/sub/dir/file >actual && 69 test_cmp expect actual && 70 test_cmp expect some/sub/dir/file 71 ' 72 73 test_expect_success 'apply --directory (../ in the middle)' ' 74 git reset --hard initial && 75 git apply --directory=some/../some/sub -p3 --index patch && 76 echo Bello >expect && 77 git show :some/sub/dir/file >actual && 78 test_cmp expect actual && 79 test_cmp expect some/sub/dir/file 80 ' 81 82 test_expect_success 'apply --directory rejects leading ../' ' 83 test_must_fail git apply --directory=../foo -p3 patch 2>err && 84 test_grep "unable to normalize directory" err 85 ' 86 87 cat > patch << EOF 88 diff --git a/newfile b/newfile 89 new file mode 100644 90 index `0000000`..`d95f3ad` 91 --- /dev/null 92 +++ b/newfile 93 @@ -0,0 +1 @@ 94 +content 95 EOF 96 97 test_expect_success 'apply --directory (new file)' ' 98 git reset --hard initial && 99 git apply --directory=some/sub/dir/ --index patch && 100 echo content >expect && 101 git show :some/sub/dir/newfile >actual && 102 test_cmp expect actual && 103 test_cmp expect some/sub/dir/newfile 104 ' 105 106 cat > patch << EOF 107 diff --git a/c/newfile2 b/c/newfile2 108 new file mode 100644 109 index `0000000`..`d95f3ad` 110 --- /dev/null 111 +++ b/c/newfile2 112 @@ -0,0 +1 @@ 113 +content 114 EOF 115 116 test_expect_success 'apply --directory -p (new file)' ' 117 git reset --hard initial && 118 git apply -p2 --directory=some/sub/dir/ --index patch && 119 echo content >expect && 120 git show :some/sub/dir/newfile2 >actual && 121 test_cmp expect actual && 122 test_cmp expect some/sub/dir/newfile2 123 ' 124 125 cat > patch << EOF 126 diff --git a/delfile b/delfile 127 deleted file mode 100644 128 index `d95f3ad`..`0000000` 129 --- a/delfile 130 +++ /dev/null 131 @@ -1 +0,0 @@ 132 -content 133 EOF 134 135 test_expect_success 'apply --directory (delete file)' ' 136 git reset --hard initial && 137 echo content >some/sub/dir/delfile && 138 git add some/sub/dir/delfile && 139 git apply --directory=some/sub/dir/ --index patch && 140 git ls-files >out && 141 test_grep ! delfile out 142 ' 143 144 cat > patch << 'EOF' 145 diff --git "a/qu\157tefile" "b/qu\157tefile" 146 new file mode 100644 147 index `0000000`..`d95f3ad` 148 --- /dev/null 149 +++ "b/qu\157tefile" 150 @@ -0,0 +1 @@ 151 +content 152 EOF 153 154 test_expect_success 'apply --directory (quoted filename)' ' 155 git reset --hard initial && 156 git apply --directory=some/sub/dir/ --index patch && 157 echo content >expect && 158 git show :some/sub/dir/quotefile >actual && 159 test_cmp expect actual && 160 test_cmp expect some/sub/dir/quotefile 161 ' 162 163 test_done