]> git.ipfire.org Git - thirdparty/git.git/blob - t/t2072-restore-pathspec-file.sh
Merge branch 'ea/blame-use-oideq'
[thirdparty/git.git] / t / t2072-restore-pathspec-file.sh
1 #!/bin/sh
2
3 test_description='restore --pathspec-from-file'
4
5 . ./test-lib.sh
6
7 test_tick
8
9 test_expect_success setup '
10 test_commit file0 &&
11
12 mkdir dir1 &&
13 echo 1 >dir1/file &&
14 echo 1 >fileA.t &&
15 echo 1 >fileB.t &&
16 echo 1 >fileC.t &&
17 echo 1 >fileD.t &&
18 git add dir1 fileA.t fileB.t fileC.t fileD.t &&
19 git commit -m "files 1" &&
20
21 echo 2 >dir1/file &&
22 echo 2 >fileA.t &&
23 echo 2 >fileB.t &&
24 echo 2 >fileC.t &&
25 echo 2 >fileD.t &&
26 git add dir1 fileA.t fileB.t fileC.t fileD.t &&
27 git commit -m "files 2" &&
28
29 git tag checkpoint
30 '
31
32 restore_checkpoint () {
33 git reset --hard checkpoint
34 }
35
36 verify_expect () {
37 git status --porcelain --untracked-files=no -- dir1 fileA.t fileB.t fileC.t fileD.t >actual &&
38 test_cmp expect actual
39 }
40
41 test_expect_success '--pathspec-from-file from stdin' '
42 restore_checkpoint &&
43
44 echo fileA.t | git restore --pathspec-from-file=- --source=HEAD^1 &&
45
46 cat >expect <<-\EOF &&
47 M fileA.t
48 EOF
49 verify_expect
50 '
51
52 test_expect_success '--pathspec-from-file from file' '
53 restore_checkpoint &&
54
55 echo fileA.t >list &&
56 git restore --pathspec-from-file=list --source=HEAD^1 &&
57
58 cat >expect <<-\EOF &&
59 M fileA.t
60 EOF
61 verify_expect
62 '
63
64 test_expect_success 'NUL delimiters' '
65 restore_checkpoint &&
66
67 printf "fileA.t\0fileB.t\0" | git restore --pathspec-from-file=- --pathspec-file-nul --source=HEAD^1 &&
68
69 cat >expect <<-\EOF &&
70 M fileA.t
71 M fileB.t
72 EOF
73 verify_expect
74 '
75
76 test_expect_success 'LF delimiters' '
77 restore_checkpoint &&
78
79 printf "fileA.t\nfileB.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
80
81 cat >expect <<-\EOF &&
82 M fileA.t
83 M fileB.t
84 EOF
85 verify_expect
86 '
87
88 test_expect_success 'no trailing delimiter' '
89 restore_checkpoint &&
90
91 printf "fileA.t\nfileB.t" | git restore --pathspec-from-file=- --source=HEAD^1 &&
92
93 cat >expect <<-\EOF &&
94 M fileA.t
95 M fileB.t
96 EOF
97 verify_expect
98 '
99
100 test_expect_success 'CRLF delimiters' '
101 restore_checkpoint &&
102
103 printf "fileA.t\r\nfileB.t\r\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
104
105 cat >expect <<-\EOF &&
106 M fileA.t
107 M fileB.t
108 EOF
109 verify_expect
110 '
111
112 test_expect_success 'quotes' '
113 restore_checkpoint &&
114
115 cat >list <<-\EOF &&
116 "file\101.t"
117 EOF
118
119 git restore --pathspec-from-file=list --source=HEAD^1 &&
120
121 cat >expect <<-\EOF &&
122 M fileA.t
123 EOF
124 verify_expect
125 '
126
127 test_expect_success 'quotes not compatible with --pathspec-file-nul' '
128 restore_checkpoint &&
129
130 cat >list <<-\EOF &&
131 "file\101.t"
132 EOF
133
134 test_must_fail git restore --pathspec-from-file=list --pathspec-file-nul --source=HEAD^1
135 '
136
137 test_expect_success 'only touches what was listed' '
138 restore_checkpoint &&
139
140 printf "fileB.t\nfileC.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
141
142 cat >expect <<-\EOF &&
143 M fileB.t
144 M fileC.t
145 EOF
146 verify_expect
147 '
148
149 test_expect_success 'error conditions' '
150 restore_checkpoint &&
151 echo fileA.t >list &&
152 >empty_list &&
153
154 test_must_fail git restore --pathspec-from-file=list --patch --source=HEAD^1 2>err &&
155 test_i18ngrep -e "--pathspec-from-file is incompatible with --patch" err &&
156
157 test_must_fail git restore --pathspec-from-file=list --source=HEAD^1 -- fileA.t 2>err &&
158 test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
159
160 test_must_fail git restore --pathspec-file-nul --source=HEAD^1 2>err &&
161 test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err &&
162
163 test_must_fail git restore --pathspec-from-file=empty_list --source=HEAD^1 2>err &&
164 test_i18ngrep -e "you must specify path(s) to restore" err
165 '
166
167 test_expect_success 'wildcard pathspec matches file in subdirectory' '
168 restore_checkpoint &&
169
170 echo "*file" | git restore --pathspec-from-file=- --source=HEAD^1 &&
171 cat >expect <<-\EOF &&
172 M dir1/file
173 EOF
174 verify_expect
175 '
176
177 test_done