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