Merge branch 'jc/ci-upload-artifact-and-linux32'
[git/gitster.git] / t / t3704-add-pathspec-file.sh
blob3aa59f6f639b5bfc79ab048f594cb2512755be73
1 #!/bin/sh
3 test_description='add --pathspec-from-file'
5 TEST_PASSES_SANITIZE_LEAK=true
6 . ./test-lib.sh
8 test_tick
10 test_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
18 restore_checkpoint () {
19 git reset
22 verify_expect () {
23 git status --porcelain --untracked-files=no -- fileA.t fileB.t fileC.t fileD.t >actual &&
24 test_cmp expect actual
27 test_expect_success '--pathspec-from-file from stdin' '
28 restore_checkpoint &&
30 echo fileA.t | git add --pathspec-from-file=- &&
32 cat >expect <<-\EOF &&
33 A fileA.t
34 EOF
35 verify_expect
38 test_expect_success '--pathspec-from-file from file' '
39 restore_checkpoint &&
41 echo fileA.t >list &&
42 git add --pathspec-from-file=list &&
44 cat >expect <<-\EOF &&
45 A fileA.t
46 EOF
47 verify_expect
50 test_expect_success 'NUL delimiters' '
51 restore_checkpoint &&
53 printf "fileA.t\0fileB.t\0" | git add --pathspec-from-file=- --pathspec-file-nul &&
55 cat >expect <<-\EOF &&
56 A fileA.t
57 A fileB.t
58 EOF
59 verify_expect
62 test_expect_success 'LF delimiters' '
63 restore_checkpoint &&
65 printf "fileA.t\nfileB.t\n" | git add --pathspec-from-file=- &&
67 cat >expect <<-\EOF &&
68 A fileA.t
69 A fileB.t
70 EOF
71 verify_expect
74 test_expect_success 'no trailing delimiter' '
75 restore_checkpoint &&
77 printf "fileA.t\nfileB.t" | git add --pathspec-from-file=- &&
79 cat >expect <<-\EOF &&
80 A fileA.t
81 A fileB.t
82 EOF
83 verify_expect
86 test_expect_success 'CRLF delimiters' '
87 restore_checkpoint &&
89 printf "fileA.t\r\nfileB.t\r\n" | git add --pathspec-from-file=- &&
91 cat >expect <<-\EOF &&
92 A fileA.t
93 A fileB.t
94 EOF
95 verify_expect
98 test_expect_success 'quotes' '
99 restore_checkpoint &&
101 cat >list <<-\EOF &&
102 "file\101.t"
105 git add --pathspec-from-file=list &&
107 cat >expect <<-\EOF &&
108 A fileA.t
110 verify_expect
113 test_expect_success 'quotes not compatible with --pathspec-file-nul' '
114 restore_checkpoint &&
116 cat >list <<-\EOF &&
117 "file\101.t"
120 test_must_fail git add --pathspec-from-file=list --pathspec-file-nul
123 test_expect_success 'only touches what was listed' '
124 restore_checkpoint &&
126 printf "fileB.t\nfileC.t\n" | git add --pathspec-from-file=- &&
128 cat >expect <<-\EOF &&
129 A fileB.t
130 A fileC.t
132 verify_expect
135 test_expect_success 'error conditions' '
136 restore_checkpoint &&
137 echo fileA.t >list &&
138 >empty_list &&
140 test_must_fail git add --pathspec-from-file=list --interactive 2>err &&
141 test_grep -e "options .--pathspec-from-file. and .--interactive/--patch. cannot be used together" err &&
143 test_must_fail git add --pathspec-from-file=list --patch 2>err &&
144 test_grep -e "options .--pathspec-from-file. and .--interactive/--patch. cannot be used together" err &&
146 test_must_fail git add --pathspec-from-file=list --edit 2>err &&
147 test_grep -e "options .--pathspec-from-file. and .--edit. cannot be used together" err &&
149 test_must_fail git add --pathspec-from-file=list -- fileA.t 2>err &&
150 test_grep -e ".--pathspec-from-file. and pathspec arguments cannot be used together" err &&
152 test_must_fail git add --pathspec-file-nul 2>err &&
153 test_grep -e "the option .--pathspec-file-nul. requires .--pathspec-from-file." err &&
155 # This case succeeds, but still prints to stderr
156 git add --pathspec-from-file=empty_list 2>err &&
157 test_grep -e "Nothing specified, nothing added." err
160 test_done