]> git.ipfire.org Git - thirdparty/git.git/blob - t/t3704-add-pathspec-file.sh
Merge branch 'bc/sha-256-part-2'
[thirdparty/git.git] / t / t3704-add-pathspec-file.sh
1 #!/bin/sh
2
3 test_description='add --pathspec-from-file'
4
5 . ./test-lib.sh
6
7 test_tick
8
9 test_expect_success setup '
10 test_commit file0 &&
11 echo A >fileA.t &&
12 echo B >fileB.t &&
13 echo C >fileC.t &&
14 echo D >fileD.t
15 '
16
17 restore_checkpoint () {
18 git reset
19 }
20
21 verify_expect () {
22 git status --porcelain --untracked-files=no -- fileA.t fileB.t fileC.t fileD.t >actual &&
23 test_cmp expect actual
24 }
25
26 test_expect_success '--pathspec-from-file from stdin' '
27 restore_checkpoint &&
28
29 echo fileA.t | git add --pathspec-from-file=- &&
30
31 cat >expect <<-\EOF &&
32 A fileA.t
33 EOF
34 verify_expect
35 '
36
37 test_expect_success '--pathspec-from-file from file' '
38 restore_checkpoint &&
39
40 echo fileA.t >list &&
41 git add --pathspec-from-file=list &&
42
43 cat >expect <<-\EOF &&
44 A fileA.t
45 EOF
46 verify_expect
47 '
48
49 test_expect_success 'NUL delimiters' '
50 restore_checkpoint &&
51
52 printf "fileA.t\0fileB.t\0" | git add --pathspec-from-file=- --pathspec-file-nul &&
53
54 cat >expect <<-\EOF &&
55 A fileA.t
56 A fileB.t
57 EOF
58 verify_expect
59 '
60
61 test_expect_success 'LF delimiters' '
62 restore_checkpoint &&
63
64 printf "fileA.t\nfileB.t\n" | git add --pathspec-from-file=- &&
65
66 cat >expect <<-\EOF &&
67 A fileA.t
68 A fileB.t
69 EOF
70 verify_expect
71 '
72
73 test_expect_success 'no trailing delimiter' '
74 restore_checkpoint &&
75
76 printf "fileA.t\nfileB.t" | git add --pathspec-from-file=- &&
77
78 cat >expect <<-\EOF &&
79 A fileA.t
80 A fileB.t
81 EOF
82 verify_expect
83 '
84
85 test_expect_success 'CRLF delimiters' '
86 restore_checkpoint &&
87
88 printf "fileA.t\r\nfileB.t\r\n" | git add --pathspec-from-file=- &&
89
90 cat >expect <<-\EOF &&
91 A fileA.t
92 A fileB.t
93 EOF
94 verify_expect
95 '
96
97 test_expect_success 'quotes' '
98 restore_checkpoint &&
99
100 cat >list <<-\EOF &&
101 "file\101.t"
102 EOF
103
104 git add --pathspec-from-file=list &&
105
106 cat >expect <<-\EOF &&
107 A fileA.t
108 EOF
109 verify_expect
110 '
111
112 test_expect_success 'quotes not compatible with --pathspec-file-nul' '
113 restore_checkpoint &&
114
115 cat >list <<-\EOF &&
116 "file\101.t"
117 EOF
118
119 test_must_fail git add --pathspec-from-file=list --pathspec-file-nul
120 '
121
122 test_expect_success 'only touches what was listed' '
123 restore_checkpoint &&
124
125 printf "fileB.t\nfileC.t\n" | git add --pathspec-from-file=- &&
126
127 cat >expect <<-\EOF &&
128 A fileB.t
129 A fileC.t
130 EOF
131 verify_expect
132 '
133
134 test_expect_success 'error conditions' '
135 restore_checkpoint &&
136 echo fileA.t >list &&
137 >empty_list &&
138
139 test_must_fail git add --pathspec-from-file=list --interactive 2>err &&
140 test_i18ngrep -e "--pathspec-from-file is incompatible with --interactive/--patch" err &&
141
142 test_must_fail git add --pathspec-from-file=list --patch 2>err &&
143 test_i18ngrep -e "--pathspec-from-file is incompatible with --interactive/--patch" err &&
144
145 test_must_fail git add --pathspec-from-file=list --edit 2>err &&
146 test_i18ngrep -e "--pathspec-from-file is incompatible with --edit" err &&
147
148 test_must_fail git add --pathspec-from-file=list -- fileA.t 2>err &&
149 test_i18ngrep -e "--pathspec-from-file is incompatible with pathspec arguments" err &&
150
151 test_must_fail git add --pathspec-file-nul 2>err &&
152 test_i18ngrep -e "--pathspec-file-nul requires --pathspec-from-file" err &&
153
154 # This case succeeds, but still prints to stderr
155 git add --pathspec-from-file=empty_list 2>err &&
156 test_i18ngrep -e "Nothing specified, nothing added." err
157 '
158
159 test_done