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