Skip to content

Commit cb71e73

Browse files
committed
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
2 parents bbcefff + 0e729c7 commit cb71e73

File tree

2 files changed

+97
-9
lines changed

2 files changed

+97
-9
lines changed

builtin/update-ref.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -282,26 +282,22 @@ static const char *parse_cmd_verify(struct ref_transaction *transaction,
282282
char *refname;
283283
unsigned char new_sha1[20];
284284
unsigned char old_sha1[20];
285-
int have_old;
286285

287286
refname = parse_refname(input, &next);
288287
if (!refname)
289288
die("verify: missing <ref>");
290289

291290
if (parse_next_sha1(input, &next, old_sha1, "verify", refname,
292-
PARSE_SHA1_OLD)) {
293-
hashclr(new_sha1);
294-
have_old = 0;
295-
} else {
296-
hashcpy(new_sha1, old_sha1);
297-
have_old = 1;
298-
}
291+
PARSE_SHA1_OLD))
292+
hashclr(old_sha1);
293+
294+
hashcpy(new_sha1, old_sha1);
299295

300296
if (*next != line_termination)
301297
die("verify %s: extra input: %s", refname, next);
302298

303299
if (ref_transaction_update(transaction, refname, new_sha1, old_sha1,
304-
update_flags, have_old, msg, &err))
300+
update_flags, 1, msg, &err))
305301
die("%s", err.buf);
306302

307303
update_flags = 0;

t/t1400-update-ref.sh

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -619,6 +619,52 @@ test_expect_success 'stdin update/create/verify combination works' '
619619
test_must_fail git rev-parse --verify -q $c
620620
'
621621

622+
test_expect_success 'stdin verify succeeds for correct value' '
623+
git rev-parse $m >expect &&
624+
echo "verify $m $m" >stdin &&
625+
git update-ref --stdin <stdin &&
626+
git rev-parse $m >actual &&
627+
test_cmp expect actual
628+
'
629+
630+
test_expect_success 'stdin verify succeeds for missing reference' '
631+
echo "verify refs/heads/missing $Z" >stdin &&
632+
git update-ref --stdin <stdin &&
633+
test_must_fail git rev-parse --verify -q refs/heads/missing
634+
'
635+
636+
test_expect_success 'stdin verify treats no value as missing' '
637+
echo "verify refs/heads/missing" >stdin &&
638+
git update-ref --stdin <stdin &&
639+
test_must_fail git rev-parse --verify -q refs/heads/missing
640+
'
641+
642+
test_expect_success 'stdin verify fails for wrong value' '
643+
git rev-parse $m >expect &&
644+
echo "verify $m $m~1" >stdin &&
645+
test_must_fail git update-ref --stdin <stdin &&
646+
git rev-parse $m >actual &&
647+
test_cmp expect actual
648+
'
649+
650+
test_expect_success 'stdin verify fails for mistaken null value' '
651+
git rev-parse $m >expect &&
652+
echo "verify $m $Z" >stdin &&
653+
test_must_fail git update-ref --stdin <stdin &&
654+
git rev-parse $m >actual &&
655+
test_cmp expect actual
656+
'
657+
658+
test_expect_success 'stdin verify fails for mistaken empty value' '
659+
M=$(git rev-parse $m) &&
660+
test_when_finished "git update-ref $m $M" &&
661+
git rev-parse $m >expect &&
662+
echo "verify $m" >stdin &&
663+
test_must_fail git update-ref --stdin <stdin &&
664+
git rev-parse $m >actual &&
665+
test_cmp expect actual
666+
'
667+
622668
test_expect_success 'stdin update refs works with identity updates' '
623669
cat >stdin <<-EOF &&
624670
update $a $m $m
@@ -938,6 +984,52 @@ test_expect_success 'stdin -z update/create/verify combination works' '
938984
test_must_fail git rev-parse --verify -q $c
939985
'
940986

987+
test_expect_success 'stdin -z verify succeeds for correct value' '
988+
git rev-parse $m >expect &&
989+
printf $F "verify $m" "$m" >stdin &&
990+
git update-ref -z --stdin <stdin &&
991+
git rev-parse $m >actual &&
992+
test_cmp expect actual
993+
'
994+
995+
test_expect_success 'stdin -z verify succeeds for missing reference' '
996+
printf $F "verify refs/heads/missing" "$Z" >stdin &&
997+
git update-ref -z --stdin <stdin &&
998+
test_must_fail git rev-parse --verify -q refs/heads/missing
999+
'
1000+
1001+
test_expect_success 'stdin -z verify treats no value as missing' '
1002+
printf $F "verify refs/heads/missing" "" >stdin &&
1003+
git update-ref -z --stdin <stdin &&
1004+
test_must_fail git rev-parse --verify -q refs/heads/missing
1005+
'
1006+
1007+
test_expect_success 'stdin -z verify fails for wrong value' '
1008+
git rev-parse $m >expect &&
1009+
printf $F "verify $m" "$m~1" >stdin &&
1010+
test_must_fail git update-ref -z --stdin <stdin &&
1011+
git rev-parse $m >actual &&
1012+
test_cmp expect actual
1013+
'
1014+
1015+
test_expect_success 'stdin -z verify fails for mistaken null value' '
1016+
git rev-parse $m >expect &&
1017+
printf $F "verify $m" "$Z" >stdin &&
1018+
test_must_fail git update-ref -z --stdin <stdin &&
1019+
git rev-parse $m >actual &&
1020+
test_cmp expect actual
1021+
'
1022+
1023+
test_expect_success 'stdin -z verify fails for mistaken empty value' '
1024+
M=$(git rev-parse $m) &&
1025+
test_when_finished "git update-ref $m $M" &&
1026+
git rev-parse $m >expect &&
1027+
printf $F "verify $m" "" >stdin &&
1028+
test_must_fail git update-ref -z --stdin <stdin &&
1029+
git rev-parse $m >actual &&
1030+
test_cmp expect actual
1031+
'
1032+
9411033
test_expect_success 'stdin -z update refs works with identity updates' '
9421034
printf $F "update $a" "$m" "$m" "update $b" "$m" "$m" "update $c" "$Z" "" >stdin &&
9431035
git update-ref -z --stdin <stdin &&

0 commit comments

Comments
 (0)