Git fork
at reftables-rust 139 lines 3.8 kB view raw
1#!/bin/sh 2 3test_description='git rm in sparse checked out working trees' 4 5. ./test-lib.sh 6 7test_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 && 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: 17 EOF 18 19 cat >sparse_hint <<-EOF && 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. 23 hint: Disable this message with \"git config set 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 30for opt in "" -f --dry-run 31do 32 test_expect_success "rm${opt:+ $opt} does not remove sparse entries" ' 33 git sparse-checkout set --no-cone a && 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 ' 38done 39 40test_expect_success 'recursive rm does not remove sparse entries' ' 41 git reset --hard && 42 git sparse-checkout set sub/dir && 43 git rm -r sub && 44 git status --porcelain -uno >actual && 45 cat >expected <<-\EOF && 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 && 53 D sub/d 54 D sub/dir/e 55 EOF 56 test_cmp expected2 actual2 57' 58 59test_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 71test_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 78test_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 86test_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 95test_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 103test_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 114test_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 121 git sparse-checkout set --no-cone w !/x y/ && 122 git rm w/f.t x/y/f.t 2>stderr && 123 test_must_be_empty stderr 124' 125 126test_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 && 131 git sparse-checkout set --no-cone !/x y/ !x/y/z && 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 139test_done