Merge branch 'ja/doc-synopsis-markup'
[git/gitster.git] / t / t7107-reset-pathspec-file.sh
blob020db201d57c3c38e75a0e2b9a38c2b3455a9309
1 #!/bin/sh
3 test_description='reset --pathspec-from-file'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_tick
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
20 restore_checkpoint () {
21 git reset --hard checkpoint
24 verify_expect () {
25 git status --porcelain -- fileA.t fileB.t fileC.t fileD.t >actual &&
26 if test "x$1" = 'x!'
27 then
28 ! test_cmp expect actual
29 else
30 test_cmp expect actual
34 test_expect_success '--pathspec-from-file from stdin' '
35 restore_checkpoint &&
37 git rm fileA.t &&
38 echo fileA.t | git reset --pathspec-from-file=- &&
40 cat >expect <<-\EOF &&
41 D fileA.t
42 EOF
43 verify_expect
46 test_expect_success '--pathspec-from-file from file' '
47 restore_checkpoint &&
49 git rm fileA.t &&
50 echo fileA.t >list &&
51 git reset --pathspec-from-file=list &&
53 cat >expect <<-\EOF &&
54 D fileA.t
55 EOF
56 verify_expect
59 test_expect_success 'NUL delimiters' '
60 restore_checkpoint &&
62 git rm fileA.t fileB.t &&
63 printf "fileA.t\0fileB.t\0" | git reset --pathspec-from-file=- --pathspec-file-nul &&
65 cat >expect <<-\EOF &&
66 D fileA.t
67 D fileB.t
68 EOF
69 verify_expect
72 test_expect_success 'LF delimiters' '
73 restore_checkpoint &&
75 git rm fileA.t fileB.t &&
76 printf "fileA.t\nfileB.t\n" | git reset --pathspec-from-file=- &&
78 cat >expect <<-\EOF &&
79 D fileA.t
80 D fileB.t
81 EOF
82 verify_expect
85 test_expect_success 'no trailing delimiter' '
86 restore_checkpoint &&
88 git rm fileA.t fileB.t &&
89 printf "fileA.t\nfileB.t" | git reset --pathspec-from-file=- &&
91 cat >expect <<-\EOF &&
92 D fileA.t
93 D fileB.t
94 EOF
95 verify_expect
98 test_expect_success 'CRLF delimiters' '
99 restore_checkpoint &&
101 git rm fileA.t fileB.t &&
102 printf "fileA.t\r\nfileB.t\r\n" | git reset --pathspec-from-file=- &&
104 cat >expect <<-\EOF &&
105 D fileA.t
106 D fileB.t
108 verify_expect
111 test_expect_success 'quotes' '
112 restore_checkpoint &&
114 cat >list <<-\EOF &&
115 "file\101.t"
118 git rm fileA.t &&
119 git reset --pathspec-from-file=list &&
121 cat >expect <<-\EOF &&
122 D fileA.t
124 verify_expect
127 test_expect_success 'quotes not compatible with --pathspec-file-nul' '
128 restore_checkpoint &&
130 cat >list <<-\EOF &&
131 "file\101.t"
134 # Note: "git reset" has not yet learned to fail on wrong pathspecs
135 git reset --pathspec-from-file=list --pathspec-file-nul &&
137 cat >expect <<-\EOF &&
138 D fileA.t
140 verify_expect !
143 test_expect_success 'only touches what was listed' '
144 restore_checkpoint &&
146 git rm fileA.t fileB.t fileC.t fileD.t &&
147 printf "fileB.t\nfileC.t\n" | git reset --pathspec-from-file=- &&
149 cat >expect <<-\EOF &&
150 D fileA.t
151 D fileB.t
152 D fileC.t
153 D fileD.t
155 verify_expect
158 test_expect_success 'error conditions' '
159 restore_checkpoint &&
160 echo fileA.t >list &&
161 git rm fileA.t &&
163 test_must_fail git reset --pathspec-from-file=list --patch 2>err &&
164 test_grep -e "options .--pathspec-from-file. and .--patch. cannot be used together" err &&
166 test_must_fail git reset --pathspec-from-file=list -- fileA.t 2>err &&
167 test_grep -e ".--pathspec-from-file. and pathspec arguments cannot be used together" err &&
169 test_must_fail git reset --pathspec-file-nul 2>err &&
170 test_grep -e "the option .--pathspec-file-nul. requires .--pathspec-from-file." err &&
172 test_must_fail git reset --soft --pathspec-from-file=list 2>err &&
173 test_grep -e "fatal: Cannot do soft reset with paths" err &&
175 test_must_fail git reset --hard --pathspec-from-file=list 2>err &&
176 test_grep -e "fatal: Cannot do hard reset with paths" err
179 test_done