blame: validate and peel the object names on the ignore list
[git] / t / t7107-reset-pathspec-file.sh
1 #!/bin/sh
2
3 test_description='reset --pathspec-from-file'
4
5 . ./test-lib.sh
6
7 test_tick
8
9 test_expect_success setup '
10         echo A >fileA.t &&
11         echo B >fileB.t &&
12         echo C >fileC.t &&
13         echo D >fileD.t &&
14         git add . &&
15         git commit --include . -m "Commit" &&
16         git tag checkpoint
17 '
18
19 restore_checkpoint () {
20         git reset --hard checkpoint
21 }
22
23 verify_expect () {
24         git status --porcelain -- fileA.t fileB.t fileC.t fileD.t >actual &&
25         test_cmp expect actual
26 }
27
28 test_expect_success '--pathspec-from-file from stdin' '
29         restore_checkpoint &&
30
31         git rm fileA.t &&
32         echo fileA.t | git reset --pathspec-from-file=- &&
33
34         cat >expect <<-\EOF &&
35          D fileA.t
36         EOF
37         verify_expect
38 '
39
40 test_expect_success '--pathspec-from-file from file' '
41         restore_checkpoint &&
42
43         git rm fileA.t &&
44         echo fileA.t >list &&
45         git reset --pathspec-from-file=list &&
46
47         cat >expect <<-\EOF &&
48          D fileA.t
49         EOF
50         verify_expect
51 '
52
53 test_expect_success 'NUL delimiters' '
54         restore_checkpoint &&
55
56         git rm fileA.t fileB.t &&
57         printf "fileA.t\0fileB.t\0" | git reset --pathspec-from-file=- --pathspec-file-nul &&
58
59         cat >expect <<-\EOF &&
60          D fileA.t
61          D fileB.t
62         EOF
63         verify_expect
64 '
65
66 test_expect_success 'LF delimiters' '
67         restore_checkpoint &&
68
69         git rm fileA.t fileB.t &&
70         printf "fileA.t\nfileB.t\n" | git reset --pathspec-from-file=- &&
71
72         cat >expect <<-\EOF &&
73          D fileA.t
74          D fileB.t
75         EOF
76         verify_expect
77 '
78
79 test_expect_success 'no trailing delimiter' '
80         restore_checkpoint &&
81
82         git rm fileA.t fileB.t &&
83         printf "fileA.t\nfileB.t" | git reset --pathspec-from-file=- &&
84
85         cat >expect <<-\EOF &&
86          D fileA.t
87          D fileB.t
88         EOF
89         verify_expect
90 '
91
92 test_expect_success 'CRLF delimiters' '
93         restore_checkpoint &&
94
95         git rm fileA.t fileB.t &&
96         printf "fileA.t\r\nfileB.t\r\n" | git reset --pathspec-from-file=- &&
97
98         cat >expect <<-\EOF &&
99          D fileA.t
100          D fileB.t
101         EOF
102         verify_expect
103 '
104
105 test_expect_success 'quotes' '
106         restore_checkpoint &&
107
108         cat >list <<-\EOF &&
109         "file\101.t"
110         EOF
111
112         git rm fileA.t &&
113         git reset --pathspec-from-file=list &&
114
115         cat >expect <<-\EOF &&
116          D fileA.t
117         EOF
118         verify_expect
119 '
120
121 test_expect_success 'quotes not compatible with --pathspec-file-nul' '
122         restore_checkpoint &&
123
124         cat >list <<-\EOF &&
125         "file\101.t"
126         EOF
127
128         # Note: "git reset" has not yet learned to fail on wrong pathspecs
129         git reset --pathspec-from-file=list --pathspec-file-nul &&
130
131         cat >expect <<-\EOF &&
132          D fileA.t
133         EOF
134         test_must_fail verify_expect
135 '
136
137 test_expect_success 'only touches what was listed' '
138         restore_checkpoint &&
139
140         git rm fileA.t fileB.t fileC.t fileD.t &&
141         printf "fileB.t\nfileC.t\n" | git reset --pathspec-from-file=- &&
142
143         cat >expect <<-\EOF &&
144         D  fileA.t
145          D fileB.t
146          D fileC.t
147         D  fileD.t
148         EOF
149         verify_expect
150 '
151
152 test_expect_success 'error conditions' '
153         restore_checkpoint &&
154         echo fileA.t >list &&
155         git rm fileA.t &&
156
157         test_must_fail git reset --pathspec-from-file=list --patch 2>err &&
158         test_i18ngrep -e "--pathspec-from-file is incompatible with --patch" err &&
159
160         test_must_fail git reset --pathspec-from-file=list -- fileA.t 2>err &&
161         test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
162
163         test_must_fail git reset --pathspec-file-nul 2>err &&
164         test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err &&
165
166         test_must_fail git reset --soft --pathspec-from-file=list 2>err &&
167         test_i18ngrep -e "fatal: Cannot do soft reset with paths" err &&
168
169         test_must_fail git reset --hard --pathspec-from-file=list 2>err &&
170         test_i18ngrep -e "fatal: Cannot do hard reset with paths" err
171 '
172
173 test_done