Skip to content

Commit

Permalink
update-ref: fail create operation over stdin if ref already exists
Browse files Browse the repository at this point in the history
Signed-off-by: Aman Gupta <aman@tmm1.net>
Signed-off-by: Michael Haggerty <mhagger@alum.mit.edu>
Acked-by: Brad King <brad.king@kitware.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Aman Gupta authored and Junio C Hamano committed Apr 2, 2014
1 parent 5f95c9f commit b9d56b5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
1 change: 1 addition & 0 deletions builtin/update-ref.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 11 additions & 0 deletions t/t1400-update-ref.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit b9d56b5

Please sign in to comment.