Matheus Tavares | d5f4b82 | 2021-04-08 17:41:28 -0300 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | test_description='git rm in sparse checked out working trees' |
| 4 | |
| 5 | . ./test-lib.sh |
| 6 | |
| 7 | test_expect_success 'setup' " |
| 8 | mkdir -p sub/dir && |
| 9 | touch a b c sub/d sub/dir/e && |
| 10 | git add -A && |
| 11 | git commit -m files && |
| 12 | |
| 13 | cat >sparse_error_header <<-EOF && |
Derrick Stolee | 6579e78 | 2021-09-24 15:39:14 +0000 | [diff] [blame] | 14 | The following paths and/or pathspecs matched paths that exist |
| 15 | outside of your sparse-checkout definition, so will not be |
| 16 | updated in the index: |
Matheus Tavares | d5f4b82 | 2021-04-08 17:41:28 -0300 | [diff] [blame] | 17 | EOF |
| 18 | |
| 19 | cat >sparse_hint <<-EOF && |
Derrick Stolee | 6579e78 | 2021-09-24 15:39:14 +0000 | [diff] [blame] | 20 | hint: If you intend to update such entries, try one of the following: |
| 21 | hint: * Use the --sparse option. |
| 22 | hint: * Disable or modify the sparsity rules. |
Matheus Tavares | d5f4b82 | 2021-04-08 17:41:28 -0300 | [diff] [blame] | 23 | hint: Disable this message with \"git config advice.updateSparsePath false\" |
| 24 | EOF |
| 25 | |
| 26 | echo b | cat sparse_error_header - >sparse_entry_b_error && |
| 27 | cat sparse_entry_b_error sparse_hint >b_error_and_hint |
| 28 | " |
| 29 | |
| 30 | for opt in "" -f --dry-run |
| 31 | do |
| 32 | test_expect_success "rm${opt:+ $opt} does not remove sparse entries" ' |
Elijah Newren | dde1358 | 2022-04-22 02:32:18 +0000 | [diff] [blame] | 33 | git sparse-checkout set --no-cone a && |
Matheus Tavares | d5f4b82 | 2021-04-08 17:41:28 -0300 | [diff] [blame] | 34 | test_must_fail git rm $opt b 2>stderr && |
| 35 | test_cmp b_error_and_hint stderr && |
| 36 | git ls-files --error-unmatch b |
| 37 | ' |
| 38 | done |
| 39 | |
| 40 | test_expect_success 'recursive rm does not remove sparse entries' ' |
| 41 | git reset --hard && |
| 42 | git sparse-checkout set sub/dir && |
Matheus Tavares | 20141e3 | 2021-10-28 11:21:11 -0300 | [diff] [blame] | 43 | git rm -r sub && |
Matheus Tavares | d5f4b82 | 2021-04-08 17:41:28 -0300 | [diff] [blame] | 44 | git status --porcelain -uno >actual && |
Derrick Stolee | d7c4415 | 2021-09-24 15:39:12 +0000 | [diff] [blame] | 45 | cat >expected <<-\EOF && |
Matheus Tavares | 20141e3 | 2021-10-28 11:21:11 -0300 | [diff] [blame] | 46 | D sub/dir/e |
| 47 | EOF |
| 48 | test_cmp expected actual && |
| 49 | |
| 50 | git rm --sparse -r sub && |
| 51 | git status --porcelain -uno >actual2 && |
| 52 | cat >expected2 <<-\EOF && |
Derrick Stolee | d7c4415 | 2021-09-24 15:39:12 +0000 | [diff] [blame] | 53 | D sub/d |
| 54 | D sub/dir/e |
| 55 | EOF |
Matheus Tavares | 20141e3 | 2021-10-28 11:21:11 -0300 | [diff] [blame] | 56 | test_cmp expected2 actual2 |
Matheus Tavares | d5f4b82 | 2021-04-08 17:41:28 -0300 | [diff] [blame] | 57 | ' |
| 58 | |
Derrick Stolee | f9786f9 | 2021-09-24 15:39:11 +0000 | [diff] [blame] | 59 | test_expect_success 'recursive rm --sparse removes sparse entries' ' |
| 60 | git reset --hard && |
| 61 | git sparse-checkout set "sub/dir" && |
| 62 | git rm --sparse -r sub && |
| 63 | git status --porcelain -uno >actual && |
| 64 | cat >expected <<-\EOF && |
| 65 | D sub/d |
| 66 | D sub/dir/e |
| 67 | EOF |
| 68 | test_cmp expected actual |
| 69 | ' |
| 70 | |
Matheus Tavares | d5f4b82 | 2021-04-08 17:41:28 -0300 | [diff] [blame] | 71 | test_expect_success 'rm obeys advice.updateSparsePath' ' |
| 72 | git reset --hard && |
| 73 | git sparse-checkout set a && |
| 74 | test_must_fail git -c advice.updateSparsePath=false rm b 2>stderr && |
| 75 | test_cmp sparse_entry_b_error stderr |
| 76 | ' |
| 77 | |
| 78 | test_expect_success 'do not advice about sparse entries when they do not match the pathspec' ' |
| 79 | git reset --hard && |
| 80 | git sparse-checkout set a && |
| 81 | test_must_fail git rm nonexistent 2>stderr && |
| 82 | grep "fatal: pathspec .nonexistent. did not match any files" stderr && |
| 83 | ! grep -F -f sparse_error_header stderr |
| 84 | ' |
| 85 | |
| 86 | test_expect_success 'do not warn about sparse entries when pathspec matches dense entries' ' |
| 87 | git reset --hard && |
| 88 | git sparse-checkout set a && |
| 89 | git rm "[ba]" 2>stderr && |
| 90 | test_must_be_empty stderr && |
| 91 | git ls-files --error-unmatch b && |
| 92 | test_must_fail git ls-files --error-unmatch a |
| 93 | ' |
| 94 | |
| 95 | test_expect_success 'do not warn about sparse entries with --ignore-unmatch' ' |
| 96 | git reset --hard && |
| 97 | git sparse-checkout set a && |
| 98 | git rm --ignore-unmatch b 2>stderr && |
| 99 | test_must_be_empty stderr && |
| 100 | git ls-files --error-unmatch b |
| 101 | ' |
| 102 | |
Derrick Stolee | d7c4415 | 2021-09-24 15:39:12 +0000 | [diff] [blame] | 103 | test_expect_success 'refuse to rm a non-skip-worktree path outside sparse cone' ' |
| 104 | git reset --hard && |
| 105 | git sparse-checkout set a && |
| 106 | git update-index --no-skip-worktree b && |
| 107 | test_must_fail git rm b 2>stderr && |
| 108 | test_cmp b_error_and_hint stderr && |
| 109 | git rm --sparse b 2>stderr && |
| 110 | test_must_be_empty stderr && |
| 111 | test_path_is_missing b |
| 112 | ' |
| 113 | |
Matheus Tavares | 20141e3 | 2021-10-28 11:21:11 -0300 | [diff] [blame] | 114 | test_expect_success 'can remove files from non-sparse dir' ' |
| 115 | git reset --hard && |
| 116 | git sparse-checkout disable && |
| 117 | mkdir -p w x/y && |
| 118 | test_commit w/f && |
| 119 | test_commit x/y/f && |
| 120 | |
Elijah Newren | dde1358 | 2022-04-22 02:32:18 +0000 | [diff] [blame] | 121 | git sparse-checkout set --no-cone w !/x y/ && |
Matheus Tavares | 20141e3 | 2021-10-28 11:21:11 -0300 | [diff] [blame] | 122 | git rm w/f.t x/y/f.t 2>stderr && |
| 123 | test_must_be_empty stderr |
| 124 | ' |
| 125 | |
| 126 | test_expect_success 'refuse to remove non-skip-worktree file from sparse dir' ' |
| 127 | git reset --hard && |
| 128 | git sparse-checkout disable && |
| 129 | mkdir -p x/y/z && |
| 130 | test_commit x/y/z/f && |
Elijah Newren | dde1358 | 2022-04-22 02:32:18 +0000 | [diff] [blame] | 131 | git sparse-checkout set --no-cone !/x y/ !x/y/z && |
Matheus Tavares | 20141e3 | 2021-10-28 11:21:11 -0300 | [diff] [blame] | 132 | |
| 133 | git update-index --no-skip-worktree x/y/z/f.t && |
| 134 | test_must_fail git rm x/y/z/f.t 2>stderr && |
| 135 | echo x/y/z/f.t | cat sparse_error_header - sparse_hint >expect && |
| 136 | test_cmp expect stderr |
| 137 | ' |
| 138 | |
Matheus Tavares | d5f4b82 | 2021-04-08 17:41:28 -0300 | [diff] [blame] | 139 | test_done |