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