Extend t/t1400-update-ref.sh to cover cases using the --stdin option. Signed-off-by: Brad King <brad.king@xxxxxxxxxxx> --- t/t1400-update-ref.sh | 256 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 256 insertions(+) diff --git a/t/t1400-update-ref.sh b/t/t1400-update-ref.sh index e415ee0..b6d7dfa 100755 --- a/t/t1400-update-ref.sh +++ b/t/t1400-update-ref.sh @@ -302,4 +302,260 @@ test_expect_success \ 'git cat-file blob master@{2005-05-26 23:42}:F (expect OTHER)' \ 'test OTHER = $(git cat-file blob "master@{2005-05-26 23:42}:F")' +a=refs/heads/a +b=refs/heads/b +c=refs/heads/c +z=0000000000000000000000000000000000000000 +e='""' +pws='path with space' + +test_expect_success 'stdin test setup' ' + echo "$pws" >"$pws" && + git add -- "$pws" && + git commit -m "$pws" +' + +test_expect_success 'stdin works with no input' ' + >stdin && + git update-ref --stdin <stdin && + git rev-parse --verify -q $m +' + +test_expect_success 'stdin fails on bad input line with only whitespace' ' + echo " " >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: no ref on line: " err +' + +test_expect_success 'stdin fails on bad input line with only --' ' + echo "--" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: no ref on line: --" err +' + +test_expect_success 'stdin fails on bad input line with only --bad-option' ' + echo "--bad-option" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: unknown option --bad-option" err +' + +test_expect_success 'stdin fails on bad ref name' ' + echo "~a $m" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: invalid ref format on line: ~a $m" err +' + +test_expect_success 'stdin fails on badly quoted input' ' + echo "$a \"master" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: badly quoted argument: \\\"master" err +' + +test_expect_success 'stdin fails on bad input line with too many arguments' ' + echo "$a $m $m $m" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: too many arguments on line: $a $m $m $m" err +' + +test_expect_success 'stdin fails on bad input line with too few arguments' ' + echo "$a" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: missing new value on line: $a" err +' + +test_expect_success 'stdin fails with duplicate refs' ' + cat >stdin <<-EOF && +$a $m +$b $m +$a $m +EOF + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: Multiple updates for ref '"'"'$a'"'"' not allowed." err +' + +test_expect_success 'stdin create ref works with no old value' ' + echo "$a $m" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin create ref works with zero old value' ' + echo "$b $m $z" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $b >actual && + test_cmp expect actual && + git update-ref -d $b && + echo "$b $m $e" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin create ref works with path with space to blob' ' + echo "refs/blobs/pws \"$m:$pws\"" >stdin && + git update-ref --stdin <stdin && + git rev-parse "$m:$pws" >expect && + git rev-parse refs/blobs/pws >actual && + test_cmp expect actual +' + +test_expect_success 'stdin create ref fails with wrong old value' ' + echo "$c $m $m~1" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin create ref fails with bad old value' ' + echo "$c $m does-not-exist" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: invalid old value on line: $c $m does-not-exist" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin create ref fails with bad new value' ' + echo "$c does-not-exist" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: invalid new value on line: $c does-not-exist" err && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin update ref works with right old value' ' + echo "$b $m~1 $m" >stdin && + git update-ref --stdin <stdin && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin update ref fails with wrong old value' ' + echo "$b $m~1 $m" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: Cannot lock the ref '"'"'$b'"'"'" err && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete ref fails with wrong old value' ' + echo "$a $e $m~1" >stdin && + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: Cannot lock the ref '"'"'$a'"'"'" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual +' + +test_expect_success 'stdin update symref works with --no-deref' ' + git symbolic-ref TESTSYMREF $b && + echo "--no-deref TESTSYMREF $a $b" >stdin && + git update-ref --stdin <stdin && + git rev-parse TESTSYMREF >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete symref works with --no-deref' ' + git symbolic-ref TESTSYMREF $b && + echo "--no-deref TESTSYMREF $e $b" >stdin && + git update-ref --stdin <stdin && + test_must_fail git rev-parse --verify -q TESTSYMREF && + git rev-parse $m~1 >expect && + git rev-parse $b >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete ref works with right old value' ' + echo "$b $e $m~1" >stdin && + git update-ref --stdin <stdin && + test_must_fail git rev-parse --verify -q $b +' + +test_expect_success 'stdin create refs works with some old values' ' + cat >stdin <<-EOF && +$a $m +$b $m $z +$c $z $z +EOF + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin update refs works with identity updates' ' + cat >stdin <<-EOF && +$a $m $m +$b $m $m +$c $z $e +EOF + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin update refs works with extra whitespace' ' + cat >stdin <<-EOF && + +$a $m $m + + "$b" $m $m '' + +-- $c $z $e '' +EOF + git update-ref --stdin <stdin && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + test_must_fail git rev-parse --verify -q $c +' + +test_expect_success 'stdin update refs fails with wrong old value' ' + git update-ref $c $m && + cat >stdin <<-EOF && +$a $m $m +$b $m $m +$c $e $e +EOF + test_must_fail git update-ref --stdin <stdin 2>err && + grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err && + git rev-parse $m >expect && + git rev-parse $a >actual && + test_cmp expect actual && + git rev-parse $b >actual && + test_cmp expect actual && + git rev-parse $c >actual && + test_cmp expect actual +' + +test_expect_success 'stdin delete refs works with packed and loose refs' ' + git pack-refs --all && + git update-ref $c $m~1 && + cat >stdin <<-EOF && +$a $z $m +$b $z $m +$c $e $m~1 +EOF + git update-ref --stdin <stdin && + test_must_fail git rev-parse --verify -q $a && + test_must_fail git rev-parse --verify -q $b && + test_must_fail git rev-parse --verify -q $c +' + test_done -- 1.7.10.4 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html