Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
Michael Haggerty | bf0c660 | 2016-06-07 10:13:04 +0200 | [diff] [blame] | 3 | test_description='Test git update-ref error handling' |
Ævar Arnfjörð Bjarmason | 03267e8 | 2022-11-08 19:17:39 +0100 | [diff] [blame] | 4 | |
| 5 | TEST_PASSES_SANITIZE_LEAK=true |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 6 | . ./test-lib.sh |
| 7 | |
Michael Haggerty | 017f722 | 2016-06-10 08:55:40 +0200 | [diff] [blame] | 8 | # Create some references, perhaps run pack-refs --all, then try to |
| 9 | # create some more references. Ensure that the second creation fails |
| 10 | # with the correct error message. |
| 11 | # Usage: test_update_rejected <before> <pack> <create> <error> |
| 12 | # <before> is a ws-separated list of refs to create before the test |
| 13 | # <pack> (true or false) tells whether to pack the refs before the test |
| 14 | # <create> is a list of variables to attempt creating |
| 15 | # <error> is a string to look for in the stderr of update-ref. |
| 16 | # All references are created in the namespace specified by the current |
| 17 | # value of $prefix. |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 18 | test_update_rejected () { |
Michael Haggerty | 0e4b63b | 2016-06-10 08:50:53 +0200 | [diff] [blame] | 19 | before="$1" && |
| 20 | pack="$2" && |
| 21 | create="$3" && |
| 22 | error="$4" && |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 23 | printf "create $prefix/%s $C\n" $before | |
| 24 | git update-ref --stdin && |
| 25 | git for-each-ref $prefix >unchanged && |
| 26 | if $pack |
| 27 | then |
| 28 | git pack-refs --all |
| 29 | fi && |
| 30 | printf "create $prefix/%s $C\n" $create >input && |
| 31 | test_must_fail git update-ref --stdin <input 2>output.err && |
Junio C Hamano | 6789275 | 2023-10-31 14:23:30 +0900 | [diff] [blame] | 32 | test_grep -F "$error" output.err && |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 33 | git for-each-ref $prefix >actual && |
| 34 | test_cmp unchanged actual |
| 35 | } |
| 36 | |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 37 | # Test adding and deleting D/F-conflicting references in a single |
| 38 | # transaction. |
| 39 | df_test() { |
| 40 | prefix="$1" |
| 41 | pack=: symadd=false symdel=false add_del=false addref= delref= |
| 42 | shift |
| 43 | while test $# -gt 0 |
| 44 | do |
| 45 | case "$1" in |
| 46 | --pack) |
| 47 | pack="git pack-refs --all" |
| 48 | shift |
| 49 | ;; |
| 50 | --sym-add) |
| 51 | # Perform the add via a symbolic reference |
| 52 | symadd=true |
| 53 | shift |
| 54 | ;; |
| 55 | --sym-del) |
| 56 | # Perform the del via a symbolic reference |
| 57 | symdel=true |
| 58 | shift |
| 59 | ;; |
| 60 | --del-add) |
| 61 | # Delete first reference then add second |
| 62 | add_del=false |
| 63 | delref="$prefix/r/$2" |
| 64 | addref="$prefix/r/$3" |
| 65 | shift 3 |
| 66 | ;; |
| 67 | --add-del) |
| 68 | # Add first reference then delete second |
| 69 | add_del=true |
| 70 | addref="$prefix/r/$2" |
| 71 | delref="$prefix/r/$3" |
| 72 | shift 3 |
| 73 | ;; |
| 74 | *) |
| 75 | echo 1>&2 "Extra args to df_test: $*" |
| 76 | return 1 |
| 77 | ;; |
| 78 | esac |
| 79 | done |
| 80 | git update-ref "$delref" $C && |
| 81 | if $symadd |
| 82 | then |
| 83 | addname="$prefix/s/symadd" && |
| 84 | git symbolic-ref "$addname" "$addref" |
| 85 | else |
| 86 | addname="$addref" |
| 87 | fi && |
| 88 | if $symdel |
| 89 | then |
| 90 | delname="$prefix/s/symdel" && |
| 91 | git symbolic-ref "$delname" "$delref" |
| 92 | else |
| 93 | delname="$delref" |
| 94 | fi && |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 95 | $pack && |
| 96 | if $add_del |
| 97 | then |
| 98 | printf "%s\n" "create $addname $D" "delete $delname" |
| 99 | else |
| 100 | printf "%s\n" "delete $delname" "create $addname $D" |
| 101 | fi >commands && |
| 102 | test_must_fail git update-ref --stdin <commands 2>output.err && |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 103 | grep "fatal:\( cannot lock ref $SQ$addname$SQ:\)\? $SQ$delref$SQ exists; cannot create $SQ$addref$SQ" output.err && |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 104 | printf "%s\n" "$C $delref" >expected-refs && |
| 105 | git for-each-ref --format="%(objectname) %(refname)" $prefix/r >actual-refs && |
| 106 | test_cmp expected-refs actual-refs |
| 107 | } |
| 108 | |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 109 | test_expect_success 'setup' ' |
| 110 | |
| 111 | git commit --allow-empty -m Initial && |
Michael Haggerty | 19dd7d0 | 2016-05-05 13:22:23 +0200 | [diff] [blame] | 112 | C=$(git rev-parse HEAD) && |
| 113 | git commit --allow-empty -m Second && |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 114 | D=$(git rev-parse HEAD) && |
| 115 | git commit --allow-empty -m Third && |
| 116 | E=$(git rev-parse HEAD) |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 117 | ' |
| 118 | |
| 119 | test_expect_success 'existing loose ref is a simple prefix of new' ' |
| 120 | |
| 121 | prefix=refs/1l && |
Michael Haggerty | 0e4b63b | 2016-06-10 08:50:53 +0200 | [diff] [blame] | 122 | test_update_rejected "a c e" false "b c/x d" \ |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 123 | "$SQ$prefix/c$SQ exists; cannot create $SQ$prefix/c/x$SQ" |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 124 | |
| 125 | ' |
| 126 | |
| 127 | test_expect_success 'existing packed ref is a simple prefix of new' ' |
| 128 | |
| 129 | prefix=refs/1p && |
Michael Haggerty | 0e4b63b | 2016-06-10 08:50:53 +0200 | [diff] [blame] | 130 | test_update_rejected "a c e" true "b c/x d" \ |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 131 | "$SQ$prefix/c$SQ exists; cannot create $SQ$prefix/c/x$SQ" |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 132 | |
| 133 | ' |
| 134 | |
| 135 | test_expect_success 'existing loose ref is a deeper prefix of new' ' |
| 136 | |
| 137 | prefix=refs/2l && |
Michael Haggerty | 0e4b63b | 2016-06-10 08:50:53 +0200 | [diff] [blame] | 138 | test_update_rejected "a c e" false "b c/x/y d" \ |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 139 | "$SQ$prefix/c$SQ exists; cannot create $SQ$prefix/c/x/y$SQ" |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 140 | |
| 141 | ' |
| 142 | |
| 143 | test_expect_success 'existing packed ref is a deeper prefix of new' ' |
| 144 | |
| 145 | prefix=refs/2p && |
Michael Haggerty | 0e4b63b | 2016-06-10 08:50:53 +0200 | [diff] [blame] | 146 | test_update_rejected "a c e" true "b c/x/y d" \ |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 147 | "$SQ$prefix/c$SQ exists; cannot create $SQ$prefix/c/x/y$SQ" |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 148 | |
| 149 | ' |
| 150 | |
| 151 | test_expect_success 'new ref is a simple prefix of existing loose' ' |
| 152 | |
| 153 | prefix=refs/3l && |
Michael Haggerty | 0e4b63b | 2016-06-10 08:50:53 +0200 | [diff] [blame] | 154 | test_update_rejected "a c/x e" false "b c d" \ |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 155 | "$SQ$prefix/c/x$SQ exists; cannot create $SQ$prefix/c$SQ" |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 156 | |
| 157 | ' |
| 158 | |
| 159 | test_expect_success 'new ref is a simple prefix of existing packed' ' |
| 160 | |
| 161 | prefix=refs/3p && |
Michael Haggerty | 0e4b63b | 2016-06-10 08:50:53 +0200 | [diff] [blame] | 162 | test_update_rejected "a c/x e" true "b c d" \ |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 163 | "$SQ$prefix/c/x$SQ exists; cannot create $SQ$prefix/c$SQ" |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 164 | |
| 165 | ' |
| 166 | |
| 167 | test_expect_success 'new ref is a deeper prefix of existing loose' ' |
| 168 | |
| 169 | prefix=refs/4l && |
Michael Haggerty | 0e4b63b | 2016-06-10 08:50:53 +0200 | [diff] [blame] | 170 | test_update_rejected "a c/x/y e" false "b c d" \ |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 171 | "$SQ$prefix/c/x/y$SQ exists; cannot create $SQ$prefix/c$SQ" |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 172 | |
| 173 | ' |
| 174 | |
| 175 | test_expect_success 'new ref is a deeper prefix of existing packed' ' |
| 176 | |
| 177 | prefix=refs/4p && |
Michael Haggerty | 0e4b63b | 2016-06-10 08:50:53 +0200 | [diff] [blame] | 178 | test_update_rejected "a c/x/y e" true "b c d" \ |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 179 | "$SQ$prefix/c/x/y$SQ exists; cannot create $SQ$prefix/c$SQ" |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 180 | |
| 181 | ' |
| 182 | |
Michael Haggerty | e911104 | 2015-05-11 17:25:12 +0200 | [diff] [blame] | 183 | test_expect_success 'one new ref is a simple prefix of another' ' |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 184 | |
| 185 | prefix=refs/5 && |
Michael Haggerty | 0e4b63b | 2016-06-10 08:50:53 +0200 | [diff] [blame] | 186 | test_update_rejected "a e" false "b c c/x d" \ |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 187 | "cannot process $SQ$prefix/c$SQ and $SQ$prefix/c/x$SQ at the same time" |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 188 | |
| 189 | ' |
| 190 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 191 | test_expect_success 'D/F conflict prevents add long + delete short' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 192 | df_test refs/df-al-ds --add-del foo/bar foo |
| 193 | ' |
| 194 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 195 | test_expect_success 'D/F conflict prevents add short + delete long' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 196 | df_test refs/df-as-dl --add-del foo foo/bar |
| 197 | ' |
| 198 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 199 | test_expect_success 'D/F conflict prevents delete long + add short' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 200 | df_test refs/df-dl-as --del-add foo/bar foo |
| 201 | ' |
| 202 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 203 | test_expect_success 'D/F conflict prevents delete short + add long' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 204 | df_test refs/df-ds-al --del-add foo foo/bar |
| 205 | ' |
| 206 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 207 | test_expect_success 'D/F conflict prevents add long + delete short packed' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 208 | df_test refs/df-al-dsp --pack --add-del foo/bar foo |
| 209 | ' |
| 210 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 211 | test_expect_success 'D/F conflict prevents add short + delete long packed' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 212 | df_test refs/df-as-dlp --pack --add-del foo foo/bar |
| 213 | ' |
| 214 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 215 | test_expect_success 'D/F conflict prevents delete long packed + add short' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 216 | df_test refs/df-dlp-as --pack --del-add foo/bar foo |
| 217 | ' |
| 218 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 219 | test_expect_success 'D/F conflict prevents delete short packed + add long' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 220 | df_test refs/df-dsp-al --pack --del-add foo foo/bar |
| 221 | ' |
| 222 | |
| 223 | # Try some combinations involving symbolic refs... |
| 224 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 225 | test_expect_success 'D/F conflict prevents indirect add long + delete short' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 226 | df_test refs/df-ial-ds --sym-add --add-del foo/bar foo |
| 227 | ' |
| 228 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 229 | test_expect_success 'D/F conflict prevents indirect add long + indirect delete short' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 230 | df_test refs/df-ial-ids --sym-add --sym-del --add-del foo/bar foo |
| 231 | ' |
| 232 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 233 | test_expect_success 'D/F conflict prevents indirect add short + indirect delete long' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 234 | df_test refs/df-ias-idl --sym-add --sym-del --add-del foo foo/bar |
| 235 | ' |
| 236 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 237 | test_expect_success 'D/F conflict prevents indirect delete long + indirect add short' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 238 | df_test refs/df-idl-ias --sym-add --sym-del --del-add foo/bar foo |
| 239 | ' |
| 240 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 241 | test_expect_success 'D/F conflict prevents indirect add long + delete short packed' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 242 | df_test refs/df-ial-dsp --sym-add --pack --add-del foo/bar foo |
| 243 | ' |
| 244 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 245 | test_expect_success 'D/F conflict prevents indirect add long + indirect delete short packed' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 246 | df_test refs/df-ial-idsp --sym-add --sym-del --pack --add-del foo/bar foo |
| 247 | ' |
| 248 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 249 | test_expect_success 'D/F conflict prevents add long + indirect delete short packed' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 250 | df_test refs/df-al-idsp --sym-del --pack --add-del foo/bar foo |
| 251 | ' |
| 252 | |
Patrick Steinhardt | 3f87bb2 | 2024-02-15 09:25:42 +0100 | [diff] [blame] | 253 | test_expect_success 'D/F conflict prevents indirect delete long packed + indirect add short' ' |
Michael Haggerty | 2e9de01 | 2017-10-24 17:16:24 +0200 | [diff] [blame] | 254 | df_test refs/df-idlp-ias --sym-add --sym-del --pack --del-add foo/bar foo |
| 255 | ' |
| 256 | |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 257 | # Test various errors when reading the old values of references... |
| 258 | |
| 259 | test_expect_success 'missing old value blocks update' ' |
| 260 | prefix=refs/missing-update && |
| 261 | cat >expected <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 262 | fatal: cannot lock ref $SQ$prefix/foo$SQ: unable to resolve reference $SQ$prefix/foo$SQ |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 263 | EOF |
| 264 | printf "%s\n" "update $prefix/foo $E $D" | |
| 265 | test_must_fail git update-ref --stdin 2>output.err && |
| 266 | test_cmp expected output.err |
| 267 | ' |
| 268 | |
| 269 | test_expect_success 'incorrect old value blocks update' ' |
| 270 | prefix=refs/incorrect-update && |
| 271 | git update-ref $prefix/foo $C && |
| 272 | cat >expected <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 273 | fatal: cannot lock ref $SQ$prefix/foo$SQ: is at $C but expected $D |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 274 | EOF |
| 275 | printf "%s\n" "update $prefix/foo $E $D" | |
| 276 | test_must_fail git update-ref --stdin 2>output.err && |
| 277 | test_cmp expected output.err |
| 278 | ' |
| 279 | |
| 280 | test_expect_success 'existing old value blocks create' ' |
| 281 | prefix=refs/existing-create && |
| 282 | git update-ref $prefix/foo $C && |
| 283 | cat >expected <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 284 | fatal: cannot lock ref $SQ$prefix/foo$SQ: reference already exists |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 285 | EOF |
| 286 | printf "%s\n" "create $prefix/foo $E" | |
| 287 | test_must_fail git update-ref --stdin 2>output.err && |
| 288 | test_cmp expected output.err |
| 289 | ' |
| 290 | |
| 291 | test_expect_success 'incorrect old value blocks delete' ' |
| 292 | prefix=refs/incorrect-delete && |
| 293 | git update-ref $prefix/foo $C && |
| 294 | cat >expected <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 295 | fatal: cannot lock ref $SQ$prefix/foo$SQ: is at $C but expected $D |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 296 | EOF |
| 297 | printf "%s\n" "delete $prefix/foo $D" | |
| 298 | test_must_fail git update-ref --stdin 2>output.err && |
| 299 | test_cmp expected output.err |
| 300 | ' |
| 301 | |
| 302 | test_expect_success 'missing old value blocks indirect update' ' |
| 303 | prefix=refs/missing-indirect-update && |
| 304 | git symbolic-ref $prefix/symref $prefix/foo && |
| 305 | cat >expected <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 306 | fatal: cannot lock ref $SQ$prefix/symref$SQ: unable to resolve reference $SQ$prefix/foo$SQ |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 307 | EOF |
| 308 | printf "%s\n" "update $prefix/symref $E $D" | |
| 309 | test_must_fail git update-ref --stdin 2>output.err && |
| 310 | test_cmp expected output.err |
| 311 | ' |
| 312 | |
| 313 | test_expect_success 'incorrect old value blocks indirect update' ' |
| 314 | prefix=refs/incorrect-indirect-update && |
| 315 | git symbolic-ref $prefix/symref $prefix/foo && |
| 316 | git update-ref $prefix/foo $C && |
| 317 | cat >expected <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 318 | fatal: cannot lock ref $SQ$prefix/symref$SQ: is at $C but expected $D |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 319 | EOF |
| 320 | printf "%s\n" "update $prefix/symref $E $D" | |
| 321 | test_must_fail git update-ref --stdin 2>output.err && |
| 322 | test_cmp expected output.err |
| 323 | ' |
| 324 | |
| 325 | test_expect_success 'existing old value blocks indirect create' ' |
| 326 | prefix=refs/existing-indirect-create && |
| 327 | git symbolic-ref $prefix/symref $prefix/foo && |
| 328 | git update-ref $prefix/foo $C && |
| 329 | cat >expected <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 330 | fatal: cannot lock ref $SQ$prefix/symref$SQ: reference already exists |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 331 | EOF |
| 332 | printf "%s\n" "create $prefix/symref $E" | |
| 333 | test_must_fail git update-ref --stdin 2>output.err && |
| 334 | test_cmp expected output.err |
| 335 | ' |
| 336 | |
| 337 | test_expect_success 'incorrect old value blocks indirect delete' ' |
| 338 | prefix=refs/incorrect-indirect-delete && |
| 339 | git symbolic-ref $prefix/symref $prefix/foo && |
| 340 | git update-ref $prefix/foo $C && |
| 341 | cat >expected <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 342 | fatal: cannot lock ref $SQ$prefix/symref$SQ: is at $C but expected $D |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 343 | EOF |
| 344 | printf "%s\n" "delete $prefix/symref $D" | |
| 345 | test_must_fail git update-ref --stdin 2>output.err && |
| 346 | test_cmp expected output.err |
| 347 | ' |
| 348 | |
| 349 | test_expect_success 'missing old value blocks indirect no-deref update' ' |
| 350 | prefix=refs/missing-noderef-update && |
| 351 | git symbolic-ref $prefix/symref $prefix/foo && |
| 352 | cat >expected <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 353 | fatal: cannot lock ref $SQ$prefix/symref$SQ: reference is missing but expected $D |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 354 | EOF |
| 355 | printf "%s\n" "option no-deref" "update $prefix/symref $E $D" | |
| 356 | test_must_fail git update-ref --stdin 2>output.err && |
| 357 | test_cmp expected output.err |
| 358 | ' |
| 359 | |
| 360 | test_expect_success 'incorrect old value blocks indirect no-deref update' ' |
| 361 | prefix=refs/incorrect-noderef-update && |
| 362 | git symbolic-ref $prefix/symref $prefix/foo && |
| 363 | git update-ref $prefix/foo $C && |
| 364 | cat >expected <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 365 | fatal: cannot lock ref $SQ$prefix/symref$SQ: is at $C but expected $D |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 366 | EOF |
| 367 | printf "%s\n" "option no-deref" "update $prefix/symref $E $D" | |
| 368 | test_must_fail git update-ref --stdin 2>output.err && |
| 369 | test_cmp expected output.err |
| 370 | ' |
| 371 | |
Michael Haggerty | e3f5103 | 2016-06-07 09:29:23 +0200 | [diff] [blame] | 372 | test_expect_success 'existing old value blocks indirect no-deref create' ' |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 373 | prefix=refs/existing-noderef-create && |
| 374 | git symbolic-ref $prefix/symref $prefix/foo && |
| 375 | git update-ref $prefix/foo $C && |
| 376 | cat >expected <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 377 | fatal: cannot lock ref $SQ$prefix/symref$SQ: reference already exists |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 378 | EOF |
| 379 | printf "%s\n" "option no-deref" "create $prefix/symref $E" | |
| 380 | test_must_fail git update-ref --stdin 2>output.err && |
| 381 | test_cmp expected output.err |
| 382 | ' |
| 383 | |
| 384 | test_expect_success 'incorrect old value blocks indirect no-deref delete' ' |
| 385 | prefix=refs/incorrect-noderef-delete && |
| 386 | git symbolic-ref $prefix/symref $prefix/foo && |
| 387 | git update-ref $prefix/foo $C && |
| 388 | cat >expected <<-EOF && |
Denton Liu | bd482d6 | 2019-09-05 15:10:05 -0700 | [diff] [blame] | 389 | fatal: cannot lock ref $SQ$prefix/symref$SQ: is at $C but expected $D |
Michael Haggerty | c5119dc | 2016-06-07 12:29:02 +0200 | [diff] [blame] | 390 | EOF |
| 391 | printf "%s\n" "option no-deref" "delete $prefix/symref $D" | |
| 392 | test_must_fail git update-ref --stdin 2>output.err && |
| 393 | test_cmp expected output.err |
| 394 | ' |
| 395 | |
Michael Haggerty | 433efca | 2015-05-11 17:25:03 +0200 | [diff] [blame] | 396 | test_done |