mailmap.c: fix a memory leak in free_mailap_{info,entry}()
[alt-git.git] / t / t2072-restore-pathspec-file.sh
blobb48345bf95f4a34df369d385e74e49d94be96e5f
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 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" &&
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" &&
29 git tag checkpoint
32 restore_checkpoint () {
33 git reset --hard checkpoint
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
41 test_expect_success '--pathspec-from-file from stdin' '
42 restore_checkpoint &&
44 echo fileA.t | git restore --pathspec-from-file=- --source=HEAD^1 &&
46 cat >expect <<-\EOF &&
47 M fileA.t
48 EOF
49 verify_expect
52 test_expect_success '--pathspec-from-file from file' '
53 restore_checkpoint &&
55 echo fileA.t >list &&
56 git restore --pathspec-from-file=list --source=HEAD^1 &&
58 cat >expect <<-\EOF &&
59 M fileA.t
60 EOF
61 verify_expect
64 test_expect_success 'NUL delimiters' '
65 restore_checkpoint &&
67 printf "fileA.t\0fileB.t\0" | git restore --pathspec-from-file=- --pathspec-file-nul --source=HEAD^1 &&
69 cat >expect <<-\EOF &&
70 M fileA.t
71 M fileB.t
72 EOF
73 verify_expect
76 test_expect_success 'LF delimiters' '
77 restore_checkpoint &&
79 printf "fileA.t\nfileB.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
81 cat >expect <<-\EOF &&
82 M fileA.t
83 M fileB.t
84 EOF
85 verify_expect
88 test_expect_success 'no trailing delimiter' '
89 restore_checkpoint &&
91 printf "fileA.t\nfileB.t" | git restore --pathspec-from-file=- --source=HEAD^1 &&
93 cat >expect <<-\EOF &&
94 M fileA.t
95 M fileB.t
96 EOF
97 verify_expect
100 test_expect_success 'CRLF delimiters' '
101 restore_checkpoint &&
103 printf "fileA.t\r\nfileB.t\r\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
105 cat >expect <<-\EOF &&
106 M fileA.t
107 M fileB.t
109 verify_expect
112 test_expect_success 'quotes' '
113 restore_checkpoint &&
115 cat >list <<-\EOF &&
116 "file\101.t"
119 git restore --pathspec-from-file=list --source=HEAD^1 &&
121 cat >expect <<-\EOF &&
122 M 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 test_must_fail git restore --pathspec-from-file=list --pathspec-file-nul --source=HEAD^1
137 test_expect_success 'only touches what was listed' '
138 restore_checkpoint &&
140 printf "fileB.t\nfileC.t\n" | git restore --pathspec-from-file=- --source=HEAD^1 &&
142 cat >expect <<-\EOF &&
143 M fileB.t
144 M fileC.t
146 verify_expect
149 test_expect_success 'error conditions' '
150 restore_checkpoint &&
151 echo fileA.t >list &&
152 >empty_list &&
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 &&
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 &&
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 &&
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
167 test_expect_success 'wildcard pathspec matches file in subdirectory' '
168 restore_checkpoint &&
170 echo "*file" | git restore --pathspec-from-file=- --source=HEAD^1 &&
171 cat >expect <<-\EOF &&
172 M dir1/file
174 verify_expect
177 test_done