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