]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3601-rm-pathspec-file.sh
The third batch
[thirdparty/git.git] / t / t3601-rm-pathspec-file.sh
1 #!/bin/sh
2
3 test_description='rm --pathspec-from-file'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_tick
9
10 test_expect_success setup '
11 echo A >fileA.t &&
12 echo B >fileB.t &&
13 echo C >fileC.t &&
14 echo D >fileD.t &&
15 git add fileA.t fileB.t fileC.t fileD.t &&
16 git commit -m "files" &&
17
18 git tag checkpoint
19 '
20
21 restore_checkpoint () {
22 git reset --hard checkpoint
23 }
24
25 verify_expect () {
26 git status --porcelain --untracked-files=no -- fileA.t fileB.t fileC.t fileD.t >actual &&
27 test_cmp expect actual
28 }
29
30 test_expect_success 'simplest' '
31 restore_checkpoint &&
32
33 cat >expect <<-\EOF &&
34 D fileA.t
35 EOF
36
37 echo fileA.t | git rm --pathspec-from-file=- &&
38 verify_expect
39 '
40
41 test_expect_success '--pathspec-file-nul' '
42 restore_checkpoint &&
43
44 cat >expect <<-\EOF &&
45 D fileA.t
46 D fileB.t
47 EOF
48
49 printf "fileA.t\0fileB.t\0" | git rm --pathspec-from-file=- --pathspec-file-nul &&
50 verify_expect
51 '
52
53 test_expect_success 'only touches what was listed' '
54 restore_checkpoint &&
55
56 cat >expect <<-\EOF &&
57 D fileB.t
58 D fileC.t
59 EOF
60
61 printf "fileB.t\nfileC.t\n" | git rm --pathspec-from-file=- &&
62 verify_expect
63 '
64
65 test_expect_success 'error conditions' '
66 restore_checkpoint &&
67 echo fileA.t >list &&
68
69 test_must_fail git rm --pathspec-from-file=list -- fileA.t 2>err &&
70 test_grep -e ".--pathspec-from-file. and pathspec arguments cannot be used together" err &&
71
72 test_must_fail git rm --pathspec-file-nul 2>err &&
73 test_grep -e "the option .--pathspec-file-nul. requires .--pathspec-from-file." err &&
74
75 >empty_list &&
76 test_must_fail git rm --pathspec-from-file=empty_list 2>err &&
77 test_grep -e "No pathspec was given. Which files should I remove?" err
78 '
79
80 test_done