packfile.c: fix a typo in `each_file_in_pack_dir_fn()`'s declaration
[alt-git.git] / t / t2026-checkout-pathspec-file.sh
blob9c651aefbca44283f3ac5f018557d97fb615106c
1 #!/bin/sh
3 test_description='checkout --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 &&
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" &&
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" &&
27 git tag checkpoint
30 restore_checkpoint () {
31 git reset --hard checkpoint
34 verify_expect () {
35 git status --porcelain --untracked-files=no -- fileA.t fileB.t fileC.t fileD.t >actual &&
36 test_cmp expect actual
39 test_expect_success '--pathspec-from-file from stdin' '
40 restore_checkpoint &&
42 echo fileA.t | git checkout --pathspec-from-file=- HEAD^1 &&
44 cat >expect <<-\EOF &&
45 M fileA.t
46 EOF
47 verify_expect
50 test_expect_success '--pathspec-from-file from file' '
51 restore_checkpoint &&
53 echo fileA.t >list &&
54 git checkout --pathspec-from-file=list HEAD^1 &&
56 cat >expect <<-\EOF &&
57 M fileA.t
58 EOF
59 verify_expect
62 test_expect_success 'NUL delimiters' '
63 restore_checkpoint &&
65 printf "fileA.t\0fileB.t\0" | git checkout --pathspec-from-file=- --pathspec-file-nul HEAD^1 &&
67 cat >expect <<-\EOF &&
68 M fileA.t
69 M fileB.t
70 EOF
71 verify_expect
74 test_expect_success 'LF delimiters' '
75 restore_checkpoint &&
77 printf "fileA.t\nfileB.t\n" | git checkout --pathspec-from-file=- HEAD^1 &&
79 cat >expect <<-\EOF &&
80 M fileA.t
81 M fileB.t
82 EOF
83 verify_expect
86 test_expect_success 'no trailing delimiter' '
87 restore_checkpoint &&
89 printf "fileA.t\nfileB.t" | git checkout --pathspec-from-file=- HEAD^1 &&
91 cat >expect <<-\EOF &&
92 M fileA.t
93 M fileB.t
94 EOF
95 verify_expect
98 test_expect_success 'CRLF delimiters' '
99 restore_checkpoint &&
101 printf "fileA.t\r\nfileB.t\r\n" | git checkout --pathspec-from-file=- HEAD^1 &&
103 cat >expect <<-\EOF &&
104 M fileA.t
105 M fileB.t
107 verify_expect
110 test_expect_success 'quotes' '
111 restore_checkpoint &&
113 cat >list <<-\EOF &&
114 "file\101.t"
117 git checkout --pathspec-from-file=list HEAD^1 &&
119 cat >expect <<-\EOF &&
120 M fileA.t
122 verify_expect
125 test_expect_success 'quotes not compatible with --pathspec-file-nul' '
126 restore_checkpoint &&
128 cat >list <<-\EOF &&
129 "file\101.t"
132 test_must_fail git checkout --pathspec-from-file=list --pathspec-file-nul HEAD^1
135 test_expect_success 'only touches what was listed' '
136 restore_checkpoint &&
138 printf "fileB.t\nfileC.t\n" | git checkout --pathspec-from-file=- HEAD^1 &&
140 cat >expect <<-\EOF &&
141 M fileB.t
142 M fileC.t
144 verify_expect
147 test_expect_success 'error conditions' '
148 restore_checkpoint &&
149 echo fileA.t >list &&
151 test_must_fail git checkout --pathspec-from-file=list --detach 2>err &&
152 test_i18ngrep -e "options .--pathspec-from-file. and .--detach. cannot be used together" err &&
154 test_must_fail git checkout --pathspec-from-file=list --patch 2>err &&
155 test_i18ngrep -e "options .--pathspec-from-file. and .--patch. cannot be used together" err &&
157 test_must_fail git checkout --pathspec-from-file=list -- fileA.t 2>err &&
158 test_i18ngrep -e ".--pathspec-from-file. and pathspec arguments cannot be used together" err &&
160 test_must_fail git checkout --pathspec-file-nul 2>err &&
161 test_i18ngrep -e "the option .--pathspec-file-nul. requires .--pathspec-from-file." err
164 test_done