2066
grep "$(git rev-parse $a) $(git rev-parse $a)" actual
2067
'
2068
2069
+ test_expect_success "stdin $type batch-updates" '
2070
+ git init repo &&
2071
+ test_when_finished "rm -fr repo" &&
2072
+ (
2073
+ cd repo &&
2074
+ test_commit commit &&
2075
+ head=$(git rev-parse HEAD) &&
2076
+
2077
+ format_command $type "update refs/heads/ref1" "$head" "$Z" >stdin &&
2078
+ format_command $type "update refs/heads/ref2" "$head" "$Z" >>stdin &&
2079
+ git update-ref $type --stdin --batch-updates <stdin &&
2080
+ echo $head >expect &&
2081
+ git rev-parse refs/heads/ref1 >actual &&
2082
+ test_cmp expect actual &&
2083
+ git rev-parse refs/heads/ref2 >actual &&
2084
+ test_cmp expect actual
2085
+ )
2086
+ '
2087
+
2088
+ test_expect_success "stdin $type batch-updates with invalid new_oid" '
2089
+ git init repo &&
2090
+ test_when_finished "rm -fr repo" &&
2091
+ (
2092
+ cd repo &&
2093
+ test_commit one &&
2094
+ old_head=$(git rev-parse HEAD) &&
2095
+ test_commit two &&
2096
+ head=$(git rev-parse HEAD) &&
2097
+ git update-ref refs/heads/ref1 $head &&
2098
+ git update-ref refs/heads/ref2 $head &&
2099
+
2100
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2101
+ format_command $type "update refs/heads/ref2" "$(test_oid 001)" "$head" >>stdin &&
2102
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
2103
+ echo $old_head >expect &&
2104
+ git rev-parse refs/heads/ref1 >actual &&
2105
+ test_cmp expect actual &&
2106
+ echo $head >expect &&
2107
+ git rev-parse refs/heads/ref2 >actual &&
2108
+ test_cmp expect actual &&
2109
+ test_grep -q "invalid new value provided" stdout
2110
+ )
2111
+ '
2112
+
2113
+ test_expect_success "stdin $type batch-updates with non-commit new_oid" '
2114
+ git init repo &&
2115
+ test_when_finished "rm -fr repo" &&
2116
+ (
2117
+ cd repo &&
2118
+ test_commit one &&
2119
+ old_head=$(git rev-parse HEAD) &&
2120
+ test_commit two &&
2121
+ head=$(git rev-parse HEAD) &&
2122
+ head_tree=$(git rev-parse HEAD^{tree}) &&
2123
+ git update-ref refs/heads/ref1 $head &&
2124
+ git update-ref refs/heads/ref2 $head &&
2125
+
2126
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2127
+ format_command $type "update refs/heads/ref2" "$head_tree" "$head" >>stdin &&
2128
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
2129
+ echo $old_head >expect &&
2130
+ git rev-parse refs/heads/ref1 >actual &&
2131
+ test_cmp expect actual &&
2132
+ echo $head >expect &&
2133
+ git rev-parse refs/heads/ref2 >actual &&
2134
+ test_cmp expect actual &&
2135
+ test_grep -q "invalid new value provided" stdout
2136
+ )
2137
+ '
2138
+
2139
+ test_expect_success "stdin $type batch-updates with non-existent ref" '
2140
+ git init repo &&
2141
+ test_when_finished "rm -fr repo" &&
2142
+ (
2143
+ cd repo &&
2144
+ test_commit one &&
2145
+ old_head=$(git rev-parse HEAD) &&
2146
+ test_commit two &&
2147
+ head=$(git rev-parse HEAD) &&
2148
+ git update-ref refs/heads/ref1 $head &&
2149
+
2150
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2151
+ format_command $type "update refs/heads/ref2" "$old_head" "$head" >>stdin &&
2152
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
2153
+ echo $old_head >expect &&
2154
+ git rev-parse refs/heads/ref1 >actual &&
2155
+ test_cmp expect actual &&
2156
+ test_must_fail git rev-parse refs/heads/ref2 &&
2157
+ test_grep -q "reference does not exist" stdout
2158
+ )
2159
+ '
2160
+
2161
+ test_expect_success "stdin $type batch-updates with dangling symref" '
2162
+ git init repo &&
2163
+ test_when_finished "rm -fr repo" &&
2164
+ (
2165
+ cd repo &&
2166
+ test_commit one &&
2167
+ old_head=$(git rev-parse HEAD) &&
2168
+ test_commit two &&
2169
+ head=$(git rev-parse HEAD) &&
2170
+ git update-ref refs/heads/ref1 $head &&
2171
+ git symbolic-ref refs/heads/ref2 refs/heads/nonexistent &&
2172
+
2173
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2174
+ format_command $type "update refs/heads/ref2" "$old_head" "$head" >>stdin &&
2175
+ git update-ref $type --no-deref --stdin --batch-updates <stdin >stdout &&
2176
+ echo $old_head >expect &&
2177
+ git rev-parse refs/heads/ref1 >actual &&
2178
+ test_cmp expect actual &&
2179
+ echo $head >expect &&
2180
+ test_must_fail git rev-parse refs/heads/ref2 &&
2181
+ test_grep -q "reference does not exist" stdout
2182
+ )
2183
+ '
2184
+
2185
+ test_expect_success "stdin $type batch-updates with regular ref as symref" '
2186
+ git init repo &&
2187
+ test_when_finished "rm -fr repo" &&
2188
+ (
2189
+ cd repo &&
2190
+ test_commit one &&
2191
+ old_head=$(git rev-parse HEAD) &&
2192
+ test_commit two &&
2193
+ head=$(git rev-parse HEAD) &&
2194
+ git update-ref refs/heads/ref1 $head &&
2195
+ git update-ref refs/heads/ref2 $head &&
2196
+
2197
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2198
+ format_command $type "symref-update refs/heads/ref2" "$old_head" "ref" "refs/heads/nonexistent" >>stdin &&
2199
+ git update-ref $type --no-deref --stdin --batch-updates <stdin >stdout &&
2200
+ echo $old_head >expect &&
2201
+ git rev-parse refs/heads/ref1 >actual &&
2202
+ test_cmp expect actual &&
2203
+ echo $head >expect &&
2204
+ echo $head >expect &&
2205
+ git rev-parse refs/heads/ref2 >actual &&
2206
+ test_cmp expect actual &&
2207
+ test_grep -q "expected symref but found regular ref" stdout
2208
+ )
2209
+ '
2210
+
2211
+ test_expect_success "stdin $type batch-updates with invalid old_oid" '
2212
+ git init repo &&
2213
+ test_when_finished "rm -fr repo" &&
2214
+ (
2215
+ cd repo &&
2216
+ test_commit one &&
2217
+ old_head=$(git rev-parse HEAD) &&
2218
+ test_commit two &&
2219
+ head=$(git rev-parse HEAD) &&
2220
+ git update-ref refs/heads/ref1 $head &&
2221
+ git update-ref refs/heads/ref2 $head &&
2222
+
2223
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2224
+ format_command $type "update refs/heads/ref2" "$old_head" "$Z" >>stdin &&
2225
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
2226
+ echo $old_head >expect &&
2227
+ git rev-parse refs/heads/ref1 >actual &&
2228
+ test_cmp expect actual &&
2229
+ echo $head >expect &&
2230
+ git rev-parse refs/heads/ref2 >actual &&
2231
+ test_cmp expect actual &&
2232
+ test_grep -q "reference already exists" stdout
2233
+ )
2234
+ '
2235
+
2236
+ test_expect_success "stdin $type batch-updates with incorrect old oid" '
2237
+ git init repo &&
2238
+ test_when_finished "rm -fr repo" &&
2239
+ (
2240
+ cd repo &&
2241
+ test_commit one &&
2242
+ old_head=$(git rev-parse HEAD) &&
2243
+ test_commit two &&
2244
+ head=$(git rev-parse HEAD) &&
2245
+ git update-ref refs/heads/ref1 $head &&
2246
+ git update-ref refs/heads/ref2 $head &&
2247
+
2248
+ format_command $type "update refs/heads/ref1" "$old_head" "$head" >stdin &&
2249
+ format_command $type "update refs/heads/ref2" "$head" "$old_head" >>stdin &&
2250
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
2251
+ echo $old_head >expect &&
2252
+ git rev-parse refs/heads/ref1 >actual &&
2253
+ test_cmp expect actual &&
2254
+ echo $head >expect &&
2255
+ git rev-parse refs/heads/ref2 >actual &&
2256
+ test_cmp expect actual &&
2257
+ test_grep -q "incorrect old value provided" stdout
2258
+ )
2259
+ '
2260
+
2261
+ test_expect_success "stdin $type batch-updates refname conflict" '
2262
+ git init repo &&
2263
+ test_when_finished "rm -fr repo" &&
2264
+ (
2265
+ cd repo &&
2266
+ test_commit one &&
2267
+ old_head=$(git rev-parse HEAD) &&
2268
+ test_commit two &&
2269
+ head=$(git rev-parse HEAD) &&
2270
+ git update-ref refs/heads/ref/foo $head &&
2271
+
2272
+ format_command $type "update refs/heads/ref/foo" "$old_head" "$head" >stdin &&
2273
+ format_command $type "update refs/heads/ref" "$old_head" "" >>stdin &&
2274
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
2275
+ echo $old_head >expect &&
2276
+ git rev-parse refs/heads/ref/foo >actual &&
2277
+ test_cmp expect actual &&
2278
+ test_grep -q "refname conflict" stdout
2279
+ )
2280
+ '
2281
+
2282
+ test_expect_success "stdin $type batch-updates refname conflict new ref" '
2283
+ git init repo &&
2284
+ test_when_finished "rm -fr repo" &&
2285
+ (
2286
+ cd repo &&
2287
+ test_commit one &&
2288
+ old_head=$(git rev-parse HEAD) &&
2289
+ test_commit two &&
2290
+ head=$(git rev-parse HEAD) &&
2291
+ git update-ref refs/heads/ref/foo $head &&
2292
+
2293
+ format_command $type "update refs/heads/foo" "$old_head" "" >stdin &&
2294
+ format_command $type "update refs/heads/ref" "$old_head" "" >>stdin &&
2295
+ git update-ref $type --stdin --batch-updates <stdin >stdout &&
2296
+ echo $old_head >expect &&
2297
+ git rev-parse refs/heads/foo >actual &&
2298
+ test_cmp expect actual &&
2299
+ test_grep -q "refname conflict" stdout
2300
+ )
2301
+ '
2302
done
2303
2304
test_expect_success 'update-ref should also create reflog for HEAD' '