Merge branch 'ds/doc-clone-filter'
[git.git] / t / t2072-restore-pathspec-file.sh
blob0d47946e8a9b06f044542e373f3de477e53e3261
1 #!/bin/sh
3 test_description='restore --pathspec-from-file'
5 . ./test-lib.sh
7 test_tick
9 test_expect_success setup '
10 test_commit file0 &&
12 echo 1 >fileA.t &&
13 echo 1 >fileB.t &&
14 echo 1 >fileC.t &&
15 echo 1 >fileD.t &&
16 git add fileA.t fileB.t fileC.t fileD.t &&
17 git commit -m "files 1" &&
19 echo 2 >fileA.t &&
20 echo 2 >fileB.t &&
21 echo 2 >fileC.t &&
22 echo 2 >fileD.t &&
23 git add fileA.t fileB.t fileC.t fileD.t &&
24 git commit -m "files 2" &&
26 git tag checkpoint
29 restore_checkpoint () {
30 git reset --hard checkpoint
33 verify_expect () {
34 git status --porcelain --untracked-files=no -- fileA.t fileB.t fileC.t fileD.t >actual &&
35 test_cmp expect actual
38 test_expect_success '--pathspec-from-file from stdin' '
39 restore_checkpoint &&
41 echo fileA.t | git restore --pathspec-from-file=- --source=HEAD^1 &&
43 cat >expect <<-\EOF &&
44 M fileA.t
45 EOF
46 verify_expect
49 test_expect_success '--pathspec-from-file from file' '
50 restore_checkpoint &&
52 echo fileA.t >list &&
53 git restore --pathspec-from-file=list --source=HEAD^1 &&
55 cat >expect <<-\EOF &&
56 M fileA.t
57 EOF
58 verify_expect
61 test_expect_success 'NUL delimiters' '
62 restore_checkpoint &&
64 printf "fileA.t\0fileB.t\0" | git restore --pathspec-from-file=- --pathspec-file-nul --source=HEAD^1 &&
66 cat >expect <<-\EOF &&
67 M fileA.t
68 M fileB.t
69 EOF
70 verify_expect
73 test_expect_success 'LF delimiters' '
74 restore_checkpoint &&
76 printf "fileA.t\nfileB.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
78 cat >expect <<-\EOF &&
79 M fileA.t
80 M fileB.t
81 EOF
82 verify_expect
85 test_expect_success 'no trailing delimiter' '
86 restore_checkpoint &&
88 printf "fileA.t\nfileB.t" | git restore --pathspec-from-file=- --source=HEAD^1 &&
90 cat >expect <<-\EOF &&
91 M fileA.t
92 M fileB.t
93 EOF
94 verify_expect
97 test_expect_success 'CRLF delimiters' '
98 restore_checkpoint &&
100 printf "fileA.t\r\nfileB.t\r\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
102 cat >expect <<-\EOF &&
103 M fileA.t
104 M fileB.t
106 verify_expect
109 test_expect_success 'quotes' '
110 restore_checkpoint &&
112 cat >list <<-\EOF &&
113 "file\101.t"
116 git restore --pathspec-from-file=list --source=HEAD^1 &&
118 cat >expect <<-\EOF &&
119 M fileA.t
121 verify_expect
124 test_expect_success 'quotes not compatible with --pathspec-file-nul' '
125 restore_checkpoint &&
127 cat >list <<-\EOF &&
128 "file\101.t"
131 test_must_fail git restore --pathspec-from-file=list --pathspec-file-nul --source=HEAD^1
134 test_expect_success 'only touches what was listed' '
135 restore_checkpoint &&
137 printf "fileB.t\nfileC.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
139 cat >expect <<-\EOF &&
140 M fileB.t
141 M fileC.t
143 verify_expect
146 test_expect_success 'error conditions' '
147 restore_checkpoint &&
148 echo fileA.t >list &&
149 >empty_list &&
151 test_must_fail git restore --pathspec-from-file=list --patch --source=HEAD^1 2>err &&
152 test_i18ngrep -e "--pathspec-from-file is incompatible with --patch" err &&
154 test_must_fail git restore --pathspec-from-file=list --source=HEAD^1 -- fileA.t 2>err &&
155 test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
157 test_must_fail git restore --pathspec-file-nul --source=HEAD^1 2>err &&
158 test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err &&
160 test_must_fail git restore --pathspec-from-file=empty_list --source=HEAD^1 2>err &&
161 test_i18ngrep -e "you must specify path(s) to restore" err
164 test_done