update-ref: use err argument to get error from ref_transaction_commit
Call ref_transaction_commit with QUIET_ON_ERR and use the strbuf that is returned to print a log message if/after the transaction fails. Reviewed-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Ronnie Sahlberg <sahlberg@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Acked-by: Michael Haggerty <mhagger@alum.mit.edu>maint
parent
c1703d7634
commit
8bcd37482e
|
@ -342,6 +342,7 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
|
||||||
const char *refname, *oldval, *msg = NULL;
|
const char *refname, *oldval, *msg = NULL;
|
||||||
unsigned char sha1[20], oldsha1[20];
|
unsigned char sha1[20], oldsha1[20];
|
||||||
int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0, flags = 0;
|
int delete = 0, no_deref = 0, read_stdin = 0, end_null = 0, flags = 0;
|
||||||
|
struct strbuf err = STRBUF_INIT;
|
||||||
struct option options[] = {
|
struct option options[] = {
|
||||||
OPT_STRING( 'm', NULL, &msg, N_("reason"), N_("reason of the update")),
|
OPT_STRING( 'm', NULL, &msg, N_("reason"), N_("reason of the update")),
|
||||||
OPT_BOOL('d', NULL, &delete, N_("delete the reference")),
|
OPT_BOOL('d', NULL, &delete, N_("delete the reference")),
|
||||||
|
@ -359,18 +360,17 @@ int cmd_update_ref(int argc, const char **argv, const char *prefix)
|
||||||
die("Refusing to perform update with empty message.");
|
die("Refusing to perform update with empty message.");
|
||||||
|
|
||||||
if (read_stdin) {
|
if (read_stdin) {
|
||||||
int ret;
|
|
||||||
transaction = ref_transaction_begin();
|
transaction = ref_transaction_begin();
|
||||||
|
|
||||||
if (delete || no_deref || argc > 0)
|
if (delete || no_deref || argc > 0)
|
||||||
usage_with_options(git_update_ref_usage, options);
|
usage_with_options(git_update_ref_usage, options);
|
||||||
if (end_null)
|
if (end_null)
|
||||||
line_termination = '\0';
|
line_termination = '\0';
|
||||||
update_refs_stdin();
|
update_refs_stdin();
|
||||||
ret = ref_transaction_commit(transaction, msg, NULL,
|
if (ref_transaction_commit(transaction, msg, &err,
|
||||||
UPDATE_REFS_DIE_ON_ERR);
|
UPDATE_REFS_QUIET_ON_ERR))
|
||||||
|
die("%s", err.buf);
|
||||||
ref_transaction_free(transaction);
|
ref_transaction_free(transaction);
|
||||||
return ret;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (end_null)
|
if (end_null)
|
||||||
|
|
Loading…
Reference in New Issue