diff options
author | Junio C Hamano <gitster@pobox.com> | 2022-05-20 22:26:52 (GMT) |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2022-05-20 22:26:52 (GMT) |
commit | f5203a4220759e824e187082db3f4f09a3e0e570 (patch) | |
tree | cb8138830acf9f12779c361330f6d9ea72274786 | |
parent | 1256a25ecd5df8fb418a537d856bf442da984c17 (diff) | |
parent | d097a23bfaa85b4f37c771d30358e8fb5adacd7f (diff) | |
download | git-f5203a4220759e824e187082db3f4f09a3e0e570.zip git-f5203a4220759e824e187082db3f4f09a3e0e570.tar.gz git-f5203a4220759e824e187082db3f4f09a3e0e570.tar.bz2 |
Merge branch 'ds/do-not-call-bug-on-bad-refs'
Code clean-up.
* ds/do-not-call-bug-on-bad-refs:
clone: die() instead of BUG() on bad refs
-rw-r--r-- | refs.c | 6 | ||||
-rwxr-xr-x | t/t5605-clone-local.sh | 9 |
2 files changed, 13 insertions, 2 deletions
@@ -1109,8 +1109,10 @@ int ref_transaction_create(struct ref_transaction *transaction, unsigned int flags, const char *msg, struct strbuf *err) { - if (!new_oid || is_null_oid(new_oid)) - BUG("create called without valid new_oid"); + if (!new_oid || is_null_oid(new_oid)) { + strbuf_addf(err, "'%s' has a null OID", refname); + return 1; + } return ref_transaction_update(transaction, refname, new_oid, null_oid(), flags, msg, err); } diff --git a/t/t5605-clone-local.sh b/t/t5605-clone-local.sh index 7d63365..21ab619 100755 --- a/t/t5605-clone-local.sh +++ b/t/t5605-clone-local.sh @@ -141,4 +141,13 @@ test_expect_success 'cloning locally respects "-u" for fetching refs' ' test_must_fail git clone --bare -u false a should_not_work.git ' +test_expect_success 'local clone from repo with corrupt refs fails gracefully' ' + git init corrupt && + test_commit -C corrupt one && + echo a >corrupt/.git/refs/heads/topic && + + test_must_fail git clone corrupt working 2>err && + grep "has a null OID" err +' + test_done |