update-ref: fail create operation over stdin if ref already exists
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>
Aman Gupta committed
Apr 2, 2014 at 10:09 UTC
b9d56b5dd9a8819c900725b8618f8bd994a5054f
2 files changed
+12
builtin/update-ref.c
+1
@@ -147,6 +147,7 @@ static void parse_cmd_create(const char *next)
147
struct ref_update *update;
148
149
update = update_alloc();
150
+ update->have_old = 1;
151
152
if ((next = parse_first_arg(next, &ref)) != NULL && ref.buf[0])
153
update_store_ref_name(update, ref.buf);
t/t1400-update-ref.sh
+11
@@ -820,7 +820,18 @@ test_expect_success 'stdin -z update ref fails with bad old value' '
820
test_must_fail git rev-parse --verify -q $c
821
'
822
823
+test_expect_success 'stdin -z create ref fails when ref exists' '
824
+ git update-ref $c $m &&
825
+ git rev-parse "$c" >expect &&
826
+ printf $F "create $c" "$m~1" >stdin &&
827
+ test_must_fail git update-ref -z --stdin <stdin 2>err &&
828
+ grep "fatal: Cannot lock the ref '"'"'$c'"'"'" err &&
829
+ git rev-parse "$c" >actual &&
830
+ test_cmp expect actual
831
+'
832
+
833
test_expect_success 'stdin -z create ref fails with bad new value' '
834
+ git update-ref -d "$c" &&
835
printf $F "create $c" "does-not-exist" >stdin &&
836
test_must_fail git update-ref -z --stdin <stdin 2>err &&
837
grep "fatal: invalid new value for ref $c: does-not-exist" err &&