t/gpg: simplify test for unknown key
[git/debian.git] / t / t3602-rm-sparse-checkout.sh
blobecce497a9ca177594ea6d444371c415c3a7f2b21
1 #!/bin/sh
3 test_description='git rm in sparse checked out working trees'
5 . ./test-lib.sh
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 &&
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
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 advice.updateSparsePath false\"
24 EOF
26 echo b | cat sparse_error_header - >sparse_entry_b_error &&
27 cat sparse_entry_b_error sparse_hint >b_error_and_hint
30 for opt in "" -f --dry-run
32 test_expect_success "rm${opt:+ $opt} does not remove sparse entries" '
33 git sparse-checkout set 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
38 done
40 test_expect_success 'recursive rm does not remove sparse entries' '
41 git reset --hard &&
42 git sparse-checkout set sub/dir &&
43 test_must_fail git rm -r sub &&
44 git rm --sparse -r sub &&
45 git status --porcelain -uno >actual &&
46 cat >expected <<-\EOF &&
47 D sub/d
48 D sub/dir/e
49 EOF
50 test_cmp expected actual
53 test_expect_success 'recursive rm --sparse removes sparse entries' '
54 git reset --hard &&
55 git sparse-checkout set "sub/dir" &&
56 git rm --sparse -r sub &&
57 git status --porcelain -uno >actual &&
58 cat >expected <<-\EOF &&
59 D sub/d
60 D sub/dir/e
61 EOF
62 test_cmp expected actual
65 test_expect_success 'rm obeys advice.updateSparsePath' '
66 git reset --hard &&
67 git sparse-checkout set a &&
68 test_must_fail git -c advice.updateSparsePath=false rm b 2>stderr &&
69 test_cmp sparse_entry_b_error stderr
72 test_expect_success 'do not advice about sparse entries when they do not match the pathspec' '
73 git reset --hard &&
74 git sparse-checkout set a &&
75 test_must_fail git rm nonexistent 2>stderr &&
76 grep "fatal: pathspec .nonexistent. did not match any files" stderr &&
77 ! grep -F -f sparse_error_header stderr
80 test_expect_success 'do not warn about sparse entries when pathspec matches dense entries' '
81 git reset --hard &&
82 git sparse-checkout set a &&
83 git rm "[ba]" 2>stderr &&
84 test_must_be_empty stderr &&
85 git ls-files --error-unmatch b &&
86 test_must_fail git ls-files --error-unmatch a
89 test_expect_success 'do not warn about sparse entries with --ignore-unmatch' '
90 git reset --hard &&
91 git sparse-checkout set a &&
92 git rm --ignore-unmatch b 2>stderr &&
93 test_must_be_empty stderr &&
94 git ls-files --error-unmatch b
97 test_expect_success 'refuse to rm a non-skip-worktree path outside sparse cone' '
98 git reset --hard &&
99 git sparse-checkout set a &&
100 git update-index --no-skip-worktree b &&
101 test_must_fail git rm b 2>stderr &&
102 test_cmp b_error_and_hint stderr &&
103 git rm --sparse b 2>stderr &&
104 test_must_be_empty stderr &&
105 test_path_is_missing b
108 test_done