| 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='sparse checkout tests |
| 4 | |
| 5 | * (tag: removed, main) removed |
| 6 | | D sub/added |
| 7 | * (HEAD, tag: top) modified and added |
| 8 | | M init.t |
| 9 | | A sub/added |
| 10 | * (tag: init) init |
| 11 | A init.t |
| 12 | ' |
| 13 | |
| 14 | TEST_CREATE_REPO_NO_TEMPLATE=1 |
| 15 | . ./test-lib.sh |
| 16 | . "$TEST_DIRECTORY"/lib-read-tree.sh |
| 17 | |
| 18 | test_expect_success 'setup' ' |
| 19 | test_commit init && |
| 20 | echo modified >>init.t && |
| 21 | |
| 22 | cat >expected <<-EOF && |
| 23 | 100644 $(git hash-object init.t) 0 init.t |
| 24 | 100644 $EMPTY_BLOB 0 sub/added |
| 25 | 100644 $EMPTY_BLOB 0 sub/addedtoo |
| 26 | 100644 $EMPTY_BLOB 0 subsub/added |
| 27 | EOF |
| 28 | cat >expected.swt <<-\EOF && |
| 29 | H init.t |
| 30 | H sub/added |
| 31 | H sub/addedtoo |
| 32 | H subsub/added |
| 33 | EOF |
| 34 | |
| 35 | mkdir sub subsub && |
| 36 | touch sub/added sub/addedtoo subsub/added && |
| 37 | git add init.t sub/added sub/addedtoo subsub/added && |
| 38 | git commit -m "modified and added" && |
| 39 | git tag top && |
| 40 | git rm sub/added && |
| 41 | git commit -m removed && |
| 42 | git tag removed && |
| 43 | git checkout top && |
| 44 | git ls-files --stage >result && |
| 45 | test_cmp expected result |
| 46 | ' |
| 47 | |
| 48 | test_expect_success 'read-tree without .git/info/sparse-checkout' ' |
| 49 | read_tree_u_must_succeed -m -u HEAD && |
| 50 | git ls-files --stage >result && |
| 51 | test_cmp expected result && |
| 52 | git ls-files -t >result && |
| 53 | test_cmp expected.swt result |
| 54 | ' |
| 55 | |
| 56 | test_expect_success 'read-tree with .git/info/sparse-checkout but disabled' ' |
| 57 | mkdir .git/info && |
| 58 | echo >.git/info/sparse-checkout && |
| 59 | read_tree_u_must_succeed -m -u HEAD && |
| 60 | git ls-files -t >result && |
| 61 | test_cmp expected.swt result && |
| 62 | test_path_is_file init.t && |
| 63 | test_path_is_file sub/added |
| 64 | ' |
| 65 | |
| 66 | test_expect_success 'read-tree --no-sparse-checkout with empty .git/info/sparse-checkout and enabled' ' |
| 67 | git config core.sparsecheckout true && |
| 68 | echo >.git/info/sparse-checkout && |
| 69 | read_tree_u_must_succeed --no-sparse-checkout -m -u HEAD && |
| 70 | git ls-files -t >result && |
| 71 | test_cmp expected.swt result && |
| 72 | test_path_is_file init.t && |
| 73 | test_path_is_file sub/added |
| 74 | ' |
| 75 | |
| 76 | test_expect_success 'read-tree with empty .git/info/sparse-checkout' ' |
| 77 | git config core.sparsecheckout true && |
| 78 | echo >.git/info/sparse-checkout && |
| 79 | read_tree_u_must_succeed -m -u HEAD && |
| 80 | git ls-files --stage >result && |
| 81 | test_cmp expected result && |
| 82 | git ls-files -t >result && |
| 83 | cat >expected.swt <<-\EOF && |
| 84 | S init.t |
| 85 | S sub/added |
| 86 | S sub/addedtoo |
| 87 | S subsub/added |
| 88 | EOF |
| 89 | test_cmp expected.swt result && |
| 90 | test_path_is_missing init.t && |
| 91 | test_path_is_missing sub/added |
| 92 | ' |
| 93 | |
| 94 | test_expect_success 'match directories with trailing slash' ' |
| 95 | cat >expected.swt-noinit <<-\EOF && |
| 96 | S init.t |
| 97 | H sub/added |
| 98 | H sub/addedtoo |
| 99 | S subsub/added |
| 100 | EOF |
| 101 | |
| 102 | echo sub/ > .git/info/sparse-checkout && |
| 103 | read_tree_u_must_succeed -m -u HEAD && |
| 104 | git ls-files -t > result && |
| 105 | test_cmp expected.swt-noinit result && |
| 106 | test_path_is_missing init.t && |
| 107 | test_path_is_file sub/added |
| 108 | ' |
| 109 | |
| 110 | test_expect_success 'match directories without trailing slash' ' |
| 111 | echo sub >.git/info/sparse-checkout && |
| 112 | read_tree_u_must_succeed -m -u HEAD && |
| 113 | git ls-files -t >result && |
| 114 | test_cmp expected.swt-noinit result && |
| 115 | test_path_is_missing init.t && |
| 116 | test_path_is_file sub/added |
| 117 | ' |
| 118 | |
| 119 | test_expect_success 'match directories with negated patterns' ' |
| 120 | cat >expected.swt-negation <<\EOF && |
| 121 | S init.t |
| 122 | S sub/added |
| 123 | H sub/addedtoo |
| 124 | S subsub/added |
| 125 | EOF |
| 126 | |
| 127 | cat >.git/info/sparse-checkout <<\EOF && |
| 128 | sub |
| 129 | !sub/added |
| 130 | EOF |
| 131 | git read-tree -m -u HEAD && |
| 132 | git ls-files -t >result && |
| 133 | test_cmp expected.swt-negation result && |
| 134 | test_path_is_missing init.t && |
| 135 | test_path_is_missing sub/added && |
| 136 | test_path_is_file sub/addedtoo |
| 137 | ' |
| 138 | |
| 139 | test_expect_success 'match directories with negated patterns (2)' ' |
| 140 | cat >expected.swt-negation2 <<\EOF && |
| 141 | H init.t |
| 142 | H sub/added |
| 143 | S sub/addedtoo |
| 144 | H subsub/added |
| 145 | EOF |
| 146 | |
| 147 | cat >.git/info/sparse-checkout <<\EOF && |
| 148 | /* |
| 149 | !sub |
| 150 | sub/added |
| 151 | EOF |
| 152 | git read-tree -m -u HEAD && |
| 153 | git ls-files -t >result && |
| 154 | test_cmp expected.swt-negation2 result && |
| 155 | test_path_is_file init.t && |
| 156 | test_path_is_file sub/added && |
| 157 | test_path_is_missing sub/addedtoo |
| 158 | ' |
| 159 | |
| 160 | test_expect_success 'match directory pattern' ' |
| 161 | echo "s?b" >.git/info/sparse-checkout && |
| 162 | read_tree_u_must_succeed -m -u HEAD && |
| 163 | git ls-files -t >result && |
| 164 | test_cmp expected.swt-noinit result && |
| 165 | test_path_is_missing init.t && |
| 166 | test_path_is_file sub/added |
| 167 | ' |
| 168 | |
| 169 | test_expect_success 'checkout area changes' ' |
| 170 | cat >expected.swt-nosub <<-\EOF && |
| 171 | H init.t |
| 172 | S sub/added |
| 173 | S sub/addedtoo |
| 174 | S subsub/added |
| 175 | EOF |
| 176 | |
| 177 | echo init.t >.git/info/sparse-checkout && |
| 178 | read_tree_u_must_succeed -m -u HEAD && |
| 179 | git ls-files -t >result && |
| 180 | test_cmp expected.swt-nosub result && |
| 181 | test_path_is_file init.t && |
| 182 | test_path_is_missing sub/added |
| 183 | ' |
| 184 | |
| 185 | test_expect_success 'read-tree updates worktree, absent case' ' |
| 186 | echo sub/added >.git/info/sparse-checkout && |
| 187 | git checkout -f top && |
| 188 | read_tree_u_must_succeed -m -u HEAD^ && |
| 189 | test_path_is_missing init.t |
| 190 | ' |
| 191 | |
| 192 | test_expect_success 'read-tree will not throw away dirty changes, non-sparse' ' |
| 193 | echo "/*" >.git/info/sparse-checkout && |
| 194 | read_tree_u_must_succeed -m -u HEAD && |
| 195 | |
| 196 | echo dirty >init.t && |
| 197 | read_tree_u_must_fail -m -u HEAD^ && |
| 198 | test_path_is_file init.t && |
| 199 | test_grep -q dirty init.t |
| 200 | ' |
| 201 | |
| 202 | test_expect_success 'read-tree will not throw away dirty changes, sparse' ' |
| 203 | echo "/*" >.git/info/sparse-checkout && |
| 204 | read_tree_u_must_succeed -m -u HEAD && |
| 205 | |
| 206 | echo dirty >init.t && |
| 207 | echo sub/added >.git/info/sparse-checkout && |
| 208 | read_tree_u_must_fail -m -u HEAD^ && |
| 209 | test_path_is_file init.t && |
| 210 | test_grep -q dirty init.t |
| 211 | ' |
| 212 | |
| 213 | test_expect_success 'read-tree updates worktree, dirty case' ' |
| 214 | echo sub/added >.git/info/sparse-checkout && |
| 215 | git checkout -f top && |
| 216 | echo dirty >init.t && |
| 217 | read_tree_u_must_fail -m -u HEAD^ && |
| 218 | test_grep -q dirty init.t && |
| 219 | rm init.t |
| 220 | ' |
| 221 | |
| 222 | test_expect_success 'read-tree removes worktree, dirty case' ' |
| 223 | echo init.t >.git/info/sparse-checkout && |
| 224 | git checkout -f top && |
| 225 | echo dirty >added && |
| 226 | read_tree_u_must_succeed -m -u HEAD^ && |
| 227 | test_grep -q dirty added |
| 228 | ' |
| 229 | |
| 230 | test_expect_success 'read-tree adds to worktree, absent case' ' |
| 231 | echo init.t >.git/info/sparse-checkout && |
| 232 | git checkout -f removed && |
| 233 | read_tree_u_must_succeed -u -m HEAD^ && |
| 234 | test_path_is_missing sub/added |
| 235 | ' |
| 236 | |
| 237 | test_expect_success 'read-tree adds to worktree, dirty case' ' |
| 238 | echo init.t >.git/info/sparse-checkout && |
| 239 | git checkout -f removed && |
| 240 | mkdir sub && |
| 241 | echo dirty >sub/added && |
| 242 | read_tree_u_must_succeed -u -m HEAD^ && |
| 243 | test_grep -q dirty sub/added |
| 244 | ' |
| 245 | |
| 246 | test_expect_success 'index removal and worktree narrowing at the same time' ' |
| 247 | echo init.t >.git/info/sparse-checkout && |
| 248 | echo sub/added >>.git/info/sparse-checkout && |
| 249 | git checkout -f top && |
| 250 | echo init.t >.git/info/sparse-checkout && |
| 251 | git checkout removed && |
| 252 | git ls-files sub/added >result && |
| 253 | test_path_is_missing sub/added && |
| 254 | test_must_be_empty result |
| 255 | ' |
| 256 | |
| 257 | test_expect_success 'read-tree --reset removes outside worktree' ' |
| 258 | echo init.t >.git/info/sparse-checkout && |
| 259 | git checkout -f top && |
| 260 | git reset --hard removed && |
| 261 | git ls-files sub/added >result && |
| 262 | test_must_be_empty result |
| 263 | ' |
| 264 | |
| 265 | test_expect_success 'print warnings when some worktree updates disabled' ' |
| 266 | echo sub >.git/info/sparse-checkout && |
| 267 | git checkout -f init && |
| 268 | mkdir sub && |
| 269 | touch sub/added sub/addedtoo && |
| 270 | # Use -q to suppress "Previous HEAD position" and "Head is now at" msgs |
| 271 | git checkout -q top 2>actual && |
| 272 | cat >expected <<\EOF && |
| 273 | warning: The following paths were already present and thus not updated despite sparse patterns: |
| 274 | sub/added |
| 275 | sub/addedtoo |
| 276 | |
| 277 | After fixing the above paths, you may want to run `git sparse-checkout reapply`. |
| 278 | EOF |
| 279 | test_cmp expected actual |
| 280 | ' |
| 281 | |
| 282 | test_expect_success 'checkout without --ignore-skip-worktree-bits' ' |
| 283 | echo "*" >.git/info/sparse-checkout && |
| 284 | git checkout -f top && |
| 285 | test_path_is_file init.t && |
| 286 | echo sub >.git/info/sparse-checkout && |
| 287 | git checkout && |
| 288 | echo modified >> sub/added && |
| 289 | git checkout . && |
| 290 | test_path_is_missing init.t && |
| 291 | git diff --exit-code HEAD |
| 292 | ' |
| 293 | |
| 294 | test_expect_success 'checkout with --ignore-skip-worktree-bits' ' |
| 295 | echo "*" >.git/info/sparse-checkout && |
| 296 | git checkout -f top && |
| 297 | test_path_is_file init.t && |
| 298 | echo sub >.git/info/sparse-checkout && |
| 299 | git checkout && |
| 300 | echo modified >> sub/added && |
| 301 | git checkout --ignore-skip-worktree-bits . && |
| 302 | test_path_is_file init.t && |
| 303 | git diff --exit-code HEAD |
| 304 | ' |
| 305 | |
| 306 | test_done |