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