]> git.ipfire.org Git - thirdparty/git.git/blob - t/t7526-commit-pathspec-file.sh
Merge branch 'en/fetch-negotiation-default-fix'
[thirdparty/git.git] / t / t7526-commit-pathspec-file.sh
1 #!/bin/sh
2
3 test_description='commit --pathspec-from-file'
4
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
7
8 test_tick
9
10 test_expect_success setup '
11 test_commit file0 &&
12 git tag checkpoint &&
13
14 echo A >fileA.t &&
15 echo B >fileB.t &&
16 echo C >fileC.t &&
17 echo D >fileD.t &&
18 git add fileA.t fileB.t fileC.t fileD.t
19 '
20
21 restore_checkpoint () {
22 git reset --soft checkpoint
23 }
24
25 verify_expect () {
26 git diff-tree --no-commit-id --name-status -r HEAD >actual &&
27 test_cmp expect actual
28 }
29
30 test_expect_success '--pathspec-from-file from stdin' '
31 restore_checkpoint &&
32
33 echo fileA.t | git commit --pathspec-from-file=- -m "Commit" &&
34
35 cat >expect <<-\EOF &&
36 A fileA.t
37 EOF
38 verify_expect
39 '
40
41 test_expect_success '--pathspec-from-file from file' '
42 restore_checkpoint &&
43
44 echo fileA.t >list &&
45 git commit --pathspec-from-file=list -m "Commit" &&
46
47 cat >expect <<-\EOF &&
48 A fileA.t
49 EOF
50 verify_expect
51 '
52
53 test_expect_success 'NUL delimiters' '
54 restore_checkpoint &&
55
56 printf "fileA.t\0fileB.t\0" | git commit --pathspec-from-file=- --pathspec-file-nul -m "Commit" &&
57
58 cat >expect <<-\EOF &&
59 A fileA.t
60 A fileB.t
61 EOF
62 verify_expect
63 '
64
65 test_expect_success 'LF delimiters' '
66 restore_checkpoint &&
67
68 printf "fileA.t\nfileB.t\n" | git commit --pathspec-from-file=- -m "Commit" &&
69
70 cat >expect <<-\EOF &&
71 A fileA.t
72 A fileB.t
73 EOF
74 verify_expect
75 '
76
77 test_expect_success 'no trailing delimiter' '
78 restore_checkpoint &&
79
80 printf "fileA.t\nfileB.t" | git commit --pathspec-from-file=- -m "Commit" &&
81
82 cat >expect <<-\EOF &&
83 A fileA.t
84 A fileB.t
85 EOF
86 verify_expect
87 '
88
89 test_expect_success 'CRLF delimiters' '
90 restore_checkpoint &&
91
92 printf "fileA.t\r\nfileB.t\r\n" | git commit --pathspec-from-file=- -m "Commit" &&
93
94 cat >expect <<-\EOF &&
95 A fileA.t
96 A fileB.t
97 EOF
98 verify_expect
99 '
100
101 test_expect_success 'quotes' '
102 restore_checkpoint &&
103
104 cat >list <<-\EOF &&
105 "file\101.t"
106 EOF
107
108 git commit --pathspec-from-file=list -m "Commit" &&
109
110 cat >expect <<-\EOF &&
111 A fileA.t
112 EOF
113 verify_expect expect
114 '
115
116 test_expect_success 'quotes not compatible with --pathspec-file-nul' '
117 restore_checkpoint &&
118
119 cat >list <<-\EOF &&
120 "file\101.t"
121 EOF
122
123 test_must_fail git commit --pathspec-from-file=list --pathspec-file-nul -m "Commit"
124 '
125
126 test_expect_success 'only touches what was listed' '
127 restore_checkpoint &&
128
129 printf "fileB.t\nfileC.t\n" | git commit --pathspec-from-file=- -m "Commit" &&
130
131 cat >expect <<-\EOF &&
132 A fileB.t
133 A fileC.t
134 EOF
135 verify_expect
136 '
137
138 test_expect_success 'error conditions' '
139 restore_checkpoint &&
140 echo fileA.t >list &&
141 >empty_list &&
142
143 test_must_fail git commit --pathspec-from-file=list --interactive -m "Commit" 2>err &&
144 test_i18ngrep -e "options .--pathspec-from-file. and .--interactive/--patch. cannot be used together" err &&
145
146 test_must_fail git commit --pathspec-from-file=list --patch -m "Commit" 2>err &&
147 test_i18ngrep -e "options .--pathspec-from-file. and .--interactive/--patch. cannot be used together" err &&
148
149 test_must_fail git commit --pathspec-from-file=list --all -m "Commit" 2>err &&
150 test_i18ngrep -e "options .--pathspec-from-file. and .-a. cannot be used together" err &&
151
152 test_must_fail git commit --pathspec-from-file=list -m "Commit" -- fileA.t 2>err &&
153 test_i18ngrep -e ".--pathspec-from-file. and pathspec arguments cannot be used together" err &&
154
155 test_must_fail git commit --pathspec-file-nul -m "Commit" 2>err &&
156 test_i18ngrep -e "the option .--pathspec-file-nul. requires .--pathspec-from-file." err &&
157
158 test_must_fail git commit --pathspec-from-file=empty_list --include -m "Commit" 2>err &&
159 test_i18ngrep -e "No paths with --include/--only does not make sense." err &&
160
161 test_must_fail git commit --pathspec-from-file=empty_list --only -m "Commit" 2>err &&
162 test_i18ngrep -e "No paths with --include/--only does not make sense." err
163 '
164
165 test_done