Merge branch 'mh/update-ref-batch-create-fix' into maint

* mh/update-ref-batch-create-fix:
  update-ref: fail create operation over stdin if ref already exists
This commit is contained in:
Junio C Hamano 2014-04-09 12:01:28 -07:00
commit aba7af8e67
2 changed files with 12 additions and 0 deletions

View file

@ -147,6 +147,7 @@ static void parse_cmd_create(const char *next)
struct ref_update *update;
update = update_alloc();
update->have_old = 1;
if ((next = parse_first_arg(next, &ref)) != NULL && ref.buf[0])
update_store_ref_name(update, ref.buf);

View file

@ -820,7 +820,18 @@ test_expect_success 'stdin -z update ref fails with bad old value' '
test_must_fail git rev-parse --verify -q $c
'
test_expect_success 'stdin -z create ref fails when ref exists' '
git update-ref $c $m &&
git rev-parse "$c" >expect &&
printf $F "create $c" "$m~1" >stdin &&
test_must_fail git update-ref -z --stdin <stdin 2>err &&
grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
git rev-parse "$c" >actual &&
test_cmp expect actual
'
test_expect_success 'stdin -z create ref fails with bad new value' '
git update-ref -d "$c" &&
printf $F "create $c" "does-not-exist" >stdin &&
test_must_fail git update-ref -z --stdin <stdin 2>err &&
grep "fatal: invalid new value for ref $c: does-not-exist" err &&