diff --git a/builtin/update-ref.c b/builtin/update-ref.c index 1fd7a8918693fca9610cb8d5de68b8607be4a30a..22617afb0aff95bfd923ac3873dfbd0f4faa29a9 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -367,7 +367,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix) if (end_null) line_termination = '\0'; update_refs_stdin(); - ret = ref_transaction_commit(transaction, msg, + ret = ref_transaction_commit(transaction, msg, NULL, UPDATE_REFS_DIE_ON_ERR); ref_transaction_free(transaction); return ret; diff --git a/refs.c b/refs.c index 1d6dece4266226b3a3b6f44a0afc006ac39151c4..db0560259069b87961f9799a01b37035d73ff091 100644 --- a/refs.c +++ b/refs.c @@ -3444,7 +3444,8 @@ static int ref_update_reject_duplicates(struct ref_update **updates, int n, } int ref_transaction_commit(struct ref_transaction *transaction, - const char *msg, enum action_on_err onerr) + const char *msg, struct strbuf *err, + enum action_on_err onerr) { int ret = 0, delnum = 0, i; const char **delnames; @@ -3473,6 +3474,9 @@ int ref_transaction_commit(struct ref_transaction *transaction, update->flags, &update->type, onerr); if (!update->lock) { + if (err) + strbuf_addf(err, "Cannot lock the ref '%s'.", + update->refname); ret = 1; goto cleanup; } diff --git a/refs.h b/refs.h index 8c7f9c44dcab7fb07b49ee1a4a1867f18e062023..09d3564116974c862f974bc9c86e7a409b1cb48d 100644 --- a/refs.h +++ b/refs.h @@ -269,9 +269,12 @@ void ref_transaction_delete(struct ref_transaction *transaction, * Commit all of the changes that have been queued in transaction, as * atomically as possible. Return a nonzero value if there is a * problem. + * If err is non-NULL we will add an error string to it to explain why + * the transaction failed. The string does not end in newline. */ int ref_transaction_commit(struct ref_transaction *transaction, - const char *msg, enum action_on_err onerr); + const char *msg, struct strbuf *err, + enum action_on_err onerr); /* * Free an existing transaction and all associated data.