Skip to content

Commit 9b30a03

Browse files
committed
Merge branch 'mh/update-ref-batch-create-fix'
* mh/update-ref-batch-create-fix: update-ref: fail create operation over stdin if ref already exists
2 parents b389e04 + b9d56b5 commit 9b30a03

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

builtin/update-ref.c

+1
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ static void parse_cmd_create(const char *next)
147147
struct ref_update *update;
148148

149149
update = update_alloc();
150+
update->have_old = 1;
150151

151152
if ((next = parse_first_arg(next, &ref)) != NULL && ref.buf[0])
152153
update_store_ref_name(update, ref.buf);

t/t1400-update-ref.sh

+11
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,18 @@ test_expect_success 'stdin -z update ref fails with bad old value' '
820820
test_must_fail git rev-parse --verify -q $c
821821
'
822822

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+
823833
test_expect_success 'stdin -z create ref fails with bad new value' '
834+
git update-ref -d "$c" &&
824835
printf $F "create $c" "does-not-exist" >stdin &&
825836
test_must_fail git update-ref -z --stdin <stdin 2>err &&
826837
grep "fatal: invalid new value for ref $c: does-not-exist" err &&

0 commit comments

Comments
 (0)