Merge branch 'mh/update-ref-verify'

"git update-ref --stdin"'s verify command did not work well when
<oldvalue>, which is documented as optional, was missing.

* mh/update-ref-verify:
  update-ref: fix "verify" command with missing <oldvalue>
  t1400: add some more tests of "update-ref --stdin"'s verify command
This commit is contained in:
Junio C Hamano 2014-12-29 09:30:55 -08:00
commit cb71e73ade
2 changed files with 97 additions and 9 deletions

View File

@ -282,26 +282,22 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
char *refname;
unsigned char new_sha1[20];
unsigned char old_sha1[20];
int have_old;
refname = parse_refname(input, &next);
if (!refname)
die("verify: missing <ref>");
if (parse_next_sha1(input, &next, old_sha1, "verify", refname,
PARSE_SHA1_OLD)) {
hashclr(new_sha1);
have_old = 0;
} else {
hashcpy(new_sha1, old_sha1);
have_old = 1;
}
PARSE_SHA1_OLD))
hashclr(old_sha1);
hashcpy(new_sha1, old_sha1);
if (*next != line_termination)
die("verify %s: extra input: %s", refname, next);
if (ref_transaction_update(transaction, refname, new_sha1, old_sha1,
update_flags, have_old, msg, &err))
update_flags, 1, msg, &err))
die("%s", err.buf);
update_flags = 0;

View File

@ -619,6 +619,52 @@ test_expect_success 'stdin update/create/verify combination works' '
test_must_fail git rev-parse --verify -q $c
'
test_expect_success 'stdin verify succeeds for correct value' '
git rev-parse $m >expect &&
echo "verify $m $m" >stdin &&
git update-ref --stdin <stdin &&
git rev-parse $m >actual &&
test_cmp expect actual
'
test_expect_success 'stdin verify succeeds for missing reference' '
echo "verify refs/heads/missing $Z" >stdin &&
git update-ref --stdin <stdin &&
test_must_fail git rev-parse --verify -q refs/heads/missing
'
test_expect_success 'stdin verify treats no value as missing' '
echo "verify refs/heads/missing" >stdin &&
git update-ref --stdin <stdin &&
test_must_fail git rev-parse --verify -q refs/heads/missing
'
test_expect_success 'stdin verify fails for wrong value' '
git rev-parse $m >expect &&
echo "verify $m $m~1" >stdin &&
test_must_fail git update-ref --stdin <stdin &&
git rev-parse $m >actual &&
test_cmp expect actual
'
test_expect_success 'stdin verify fails for mistaken null value' '
git rev-parse $m >expect &&
echo "verify $m $Z" >stdin &&
test_must_fail git update-ref --stdin <stdin &&
git rev-parse $m >actual &&
test_cmp expect actual
'
test_expect_success 'stdin verify fails for mistaken empty value' '
M=$(git rev-parse $m) &&
test_when_finished "git update-ref $m $M" &&
git rev-parse $m >expect &&
echo "verify $m" >stdin &&
test_must_fail git update-ref --stdin <stdin &&
git rev-parse $m >actual &&
test_cmp expect actual
'
test_expect_success 'stdin update refs works with identity updates' '
cat >stdin <<-EOF &&
update $a $m $m
@ -938,6 +984,52 @@ test_expect_success 'stdin -z update/create/verify combination works' '
test_must_fail git rev-parse --verify -q $c
'
test_expect_success 'stdin -z verify succeeds for correct value' '
git rev-parse $m >expect &&
printf $F "verify $m" "$m" >stdin &&
git update-ref -z --stdin <stdin &&
git rev-parse $m >actual &&
test_cmp expect actual
'
test_expect_success 'stdin -z verify succeeds for missing reference' '
printf $F "verify refs/heads/missing" "$Z" >stdin &&
git update-ref -z --stdin <stdin &&
test_must_fail git rev-parse --verify -q refs/heads/missing
'
test_expect_success 'stdin -z verify treats no value as missing' '
printf $F "verify refs/heads/missing" "" >stdin &&
git update-ref -z --stdin <stdin &&
test_must_fail git rev-parse --verify -q refs/heads/missing
'
test_expect_success 'stdin -z verify fails for wrong value' '
git rev-parse $m >expect &&
printf $F "verify $m" "$m~1" >stdin &&
test_must_fail git update-ref -z --stdin <stdin &&
git rev-parse $m >actual &&
test_cmp expect actual
'
test_expect_success 'stdin -z verify fails for mistaken null value' '
git rev-parse $m >expect &&
printf $F "verify $m" "$Z" >stdin &&
test_must_fail git update-ref -z --stdin <stdin &&
git rev-parse $m >actual &&
test_cmp expect actual
'
test_expect_success 'stdin -z verify fails for mistaken empty value' '
M=$(git rev-parse $m) &&
test_when_finished "git update-ref $m $M" &&
git rev-parse $m >expect &&
printf $F "verify $m" "" >stdin &&
test_must_fail git update-ref -z --stdin <stdin &&
git rev-parse $m >actual &&
test_cmp expect actual
'
test_expect_success 'stdin -z update refs works with identity updates' '
printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
git update-ref -z --stdin <stdin &&