clone_submodule: avoid using `access()` on directories
[git.git] / t / t7107-reset-pathspec-file.sh
blob523efbecde1dff517ffebf3c04cfcf74ea280f15
1 #!/bin/sh
3 test_description='reset --pathspec-from-file'
5 . ./test-lib.sh
7 test_tick
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
19 restore_checkpoint () {
20 git reset --hard checkpoint
23 verify_expect () {
24 git status --porcelain -- fileA.t fileB.t fileC.t fileD.t >actual &&
25 if test "x$1" = 'x!'
26 then
27 ! test_cmp expect actual
28 else
29 test_cmp expect actual
33 test_expect_success '--pathspec-from-file from stdin' '
34 restore_checkpoint &&
36 git rm fileA.t &&
37 echo fileA.t | git reset --pathspec-from-file=- &&
39 cat >expect <<-\EOF &&
40 D fileA.t
41 EOF
42 verify_expect
45 test_expect_success '--pathspec-from-file from file' '
46 restore_checkpoint &&
48 git rm fileA.t &&
49 echo fileA.t >list &&
50 git reset --pathspec-from-file=list &&
52 cat >expect <<-\EOF &&
53 D fileA.t
54 EOF
55 verify_expect
58 test_expect_success 'NUL delimiters' '
59 restore_checkpoint &&
61 git rm fileA.t fileB.t &&
62 printf "fileA.t\0fileB.t\0" | git reset --pathspec-from-file=- --pathspec-file-nul &&
64 cat >expect <<-\EOF &&
65 D fileA.t
66 D fileB.t
67 EOF
68 verify_expect
71 test_expect_success 'LF delimiters' '
72 restore_checkpoint &&
74 git rm fileA.t fileB.t &&
75 printf "fileA.t\nfileB.t\n" | git reset --pathspec-from-file=- &&
77 cat >expect <<-\EOF &&
78 D fileA.t
79 D fileB.t
80 EOF
81 verify_expect
84 test_expect_success 'no trailing delimiter' '
85 restore_checkpoint &&
87 git rm fileA.t fileB.t &&
88 printf "fileA.t\nfileB.t" | git reset --pathspec-from-file=- &&
90 cat >expect <<-\EOF &&
91 D fileA.t
92 D fileB.t
93 EOF
94 verify_expect
97 test_expect_success 'CRLF delimiters' '
98 restore_checkpoint &&
100 git rm fileA.t fileB.t &&
101 printf "fileA.t\r\nfileB.t\r\n" | git reset --pathspec-from-file=- &&
103 cat >expect <<-\EOF &&
104 D fileA.t
105 D fileB.t
107 verify_expect
110 test_expect_success 'quotes' '
111 restore_checkpoint &&
113 cat >list <<-\EOF &&
114 "file\101.t"
117 git rm fileA.t &&
118 git reset --pathspec-from-file=list &&
120 cat >expect <<-\EOF &&
121 D fileA.t
123 verify_expect
126 test_expect_success 'quotes not compatible with --pathspec-file-nul' '
127 restore_checkpoint &&
129 cat >list <<-\EOF &&
130 "file\101.t"
133 # Note: "git reset" has not yet learned to fail on wrong pathspecs
134 git reset --pathspec-from-file=list --pathspec-file-nul &&
136 cat >expect <<-\EOF &&
137 D fileA.t
139 verify_expect !
142 test_expect_success 'only touches what was listed' '
143 restore_checkpoint &&
145 git rm fileA.t fileB.t fileC.t fileD.t &&
146 printf "fileB.t\nfileC.t\n" | git reset --pathspec-from-file=- &&
148 cat >expect <<-\EOF &&
149 D fileA.t
150 D fileB.t
151 D fileC.t
152 D fileD.t
154 verify_expect
157 test_expect_success 'error conditions' '
158 restore_checkpoint &&
159 echo fileA.t >list &&
160 git rm fileA.t &&
162 test_must_fail git reset --pathspec-from-file=list --patch 2>err &&
163 test_i18ngrep -e "options .--pathspec-from-file. and .--patch. cannot be used together" err &&
165 test_must_fail git reset --pathspec-from-file=list -- fileA.t 2>err &&
166 test_i18ngrep -e ".--pathspec-from-file. and pathspec arguments cannot be used together" err &&
168 test_must_fail git reset --pathspec-file-nul 2>err &&
169 test_i18ngrep -e "the option .--pathspec-file-nul. requires .--pathspec-from-file." err &&
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 &&
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
178 test_done