From a46e41fca301be48130cca80b45027eff328903d Mon Sep 17 00:00:00 2001 From: Michael Haggerty Date: Thu, 11 Dec 2014 00:47:51 +0100 Subject: t1400: add some more tests of "update-ref --stdin"'s verify command Two of the tests fail because verify refs/heads/foo with no argument (not even zeros) actually *deletes* refs/heads/foo. This problem will be fixed in the next commit. Signed-off-by: Michael Haggerty Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 92 insertions(+) (limited to 't') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 7b4707b776..6a3cdd1ac6 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -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 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 && + git update-ref --stdin expect && + echo "verify $m $m~1" >stdin && + test_must_fail git update-ref --stdin 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 actual && + test_cmp expect actual +' + +test_expect_failure '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 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 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 && + git update-ref -z --stdin expect && + printf $F "verify $m" "$m~1" >stdin && + test_must_fail git update-ref -z --stdin 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 actual && + test_cmp expect actual +' + +test_expect_failure '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 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 Date: Thu, 11 Dec 2014 00:47:52 +0100 Subject: update-ref: fix "verify" command with missing If "git update-ref --stdin" was given a "verify" command with no "" at all (not even zeros), the code was mistakenly setting have_old=0 (and leaving old_sha1 uninitialized). But this is incorrect: this command is supposed to verify that the reference doesn't exist. So in this case we really need old_sha1 to be set to null_sha1 and have_old to be set to 1. Moreover, since have_old was being set to zero, *no* check of the old value was being done, so the new value of the reference was being set unconditionally to the value in new_sha1. new_sha1, in turn, was set to null_sha1 in the expectation that that was the old value and it shouldn't be changed. But because the precondition was not being checked, the result was that the reference was being deleted unconditionally. So, if is missing, set have_old unconditionally and set old_sha1 to null_sha1. Signed-off-by: Michael Haggerty Acked-by: Brad King Signed-off-by: Junio C Hamano --- t/t1400-update-ref.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 't') diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index 6a3cdd1ac6..6805b9e6bb 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -655,7 +655,7 @@ test_expect_success 'stdin verify fails for mistaken null value' ' test_cmp expect actual ' -test_expect_failure 'stdin verify fails for mistaken empty value' ' +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 && @@ -1020,7 +1020,7 @@ test_expect_success 'stdin -z verify fails for mistaken null value' ' test_cmp expect actual ' -test_expect_failure 'stdin -z verify fails for mistaken empty value' ' +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 && -- cgit v1.2.3