From mboxrd@z Thu Jan 1 00:00:00 1970 From: Patrick Steinhardt Subject: [PATCH v5 09/15] remote: die on config error when manipulating remotes Date: Tue, 16 Feb 2016 13:56:36 +0100 Message-ID: <1455627402-752-10-git-send-email-ps@pks.im> References: <1455627402-752-1-git-send-email-ps@pks.im> Cc: Jeff King , Junio C Hamano , ps@pks.im, Eric Sunshine , Stefan Beller To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Tue Feb 16 13:57:27 2016 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1aVfC2-0001v0-5e for gcvg-git-2@plane.gmane.org; Tue, 16 Feb 2016 13:57:26 +0100 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932224AbcBPM5K (ORCPT ); Tue, 16 Feb 2016 07:57:10 -0500 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:53078 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932213AbcBPM5D (ORCPT ); Tue, 16 Feb 2016 07:57:03 -0500 Received: from compute2.internal (compute2.nyi.internal [10.202.2.42]) by mailout.nyi.internal (Postfix) with ESMTP id 6CFD520AC1 for ; Tue, 16 Feb 2016 07:57:02 -0500 (EST) Received: from frontend2 ([10.202.2.161]) by compute2.internal (MEProxy); Tue, 16 Feb 2016 07:57:02 -0500 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=cc:date:from:in-reply-to:message-id :references:subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=2w99 qRFhOQW/uxFZgaL+ZR/r+Zc=; b=T7vNFbFUle38LXtvyx5/kB7Nca1MxyIezWYi 8mNtKsQeaA/gF9x1VeGiLkn2Z8ZAF7QRkp7k8M1NpsLa9ZF3zMBPvTF4pgox7am/ 8/BcVMvO+kL/et6cDlj6RNV7VtTYRb4wSemQMX36FuY/vDmdI68n68SjQGWPd0Kj QPNlBMw= X-Sasl-enc: To6Jx3R4DRjbwzn1+DHgQsGDkbS1uWaJ22oSA/mVNYmR 1455627422 Received: from localhost (unknown [46.189.27.162]) by mail.messagingengine.com (Postfix) with ESMTPA id F41D4680159; Tue, 16 Feb 2016 07:57:01 -0500 (EST) X-Mailer: git-send-email 2.7.1 In-Reply-To: <1455627402-752-1-git-send-email-ps@pks.im> Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: When manipulating remotes we try to set various configuration values without checking if the values were persisted correctly, possibly leaving the remote in an inconsistent state. Fix this issue by dying early and notifying the user about the error. Signed-off-by: Patrick Steinhardt --- builtin/remote.c | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) diff --git a/builtin/remote.c b/builtin/remote.c index eeb6d2e..fe57f77 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -197,8 +197,7 @@ static int add(int argc, const char **argv) die(_("'%s' is not a valid remote name"), name); strbuf_addf(&buf, "remote.%s.url", name); - if (git_config_set(buf.buf, url)) - return 1; + git_config_set_or_die(buf.buf, url); if (!mirror || mirror & MIRROR_FETCH) { strbuf_reset(&buf); @@ -214,16 +213,14 @@ static int add(int argc, const char **argv) if (mirror & MIRROR_PUSH) { strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.mirror", name); - if (git_config_set(buf.buf, "true")) - return 1; + git_config_set_or_die(buf.buf, "true"); } if (fetch_tags != TAGS_DEFAULT) { strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.tagopt", name); - if (git_config_set(buf.buf, - fetch_tags == TAGS_SET ? "--tags" : "--no-tags")) - return 1; + git_config_set_or_die(buf.buf, + fetch_tags == TAGS_SET ? "--tags" : "--no-tags"); } if (fetch && fetch_remote(name)) @@ -591,25 +588,20 @@ static int migrate_file(struct remote *remote) strbuf_addf(&buf, "remote.%s.url", remote->name); for (i = 0; i < remote->url_nr; i++) - if (git_config_set_multivar(buf.buf, remote->url[i], "^$", 0)) - return error(_("Could not append '%s' to '%s'"), - remote->url[i], buf.buf); + git_config_set_multivar_or_die(buf.buf, remote->url[i], "^$", 0); strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.push", remote->name); for (i = 0; i < remote->push_refspec_nr; i++) - if (git_config_set_multivar(buf.buf, remote->push_refspec[i], "^$", 0)) - return error(_("Could not append '%s' to '%s'"), - remote->push_refspec[i], buf.buf); + git_config_set_multivar_or_die(buf.buf, remote->push_refspec[i], "^$", 0); strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.fetch", remote->name); for (i = 0; i < remote->fetch_refspec_nr; i++) - if (git_config_set_multivar(buf.buf, remote->fetch_refspec[i], "^$", 0)) - return error(_("Could not append '%s' to '%s'"), - remote->fetch_refspec[i], buf.buf); + git_config_set_multivar_or_die(buf.buf, remote->fetch_refspec[i], "^$", 0); if (remote->origin == REMOTE_REMOTES) unlink_or_warn(git_path("remotes/%s", remote->name)); else if (remote->origin == REMOTE_BRANCHES) unlink_or_warn(git_path("branches/%s", remote->name)); + return 0; } @@ -656,8 +648,7 @@ static int mv(int argc, const char **argv) strbuf_reset(&buf); strbuf_addf(&buf, "remote.%s.fetch", rename.new); - if (git_config_set_multivar(buf.buf, NULL, NULL, 1)) - return error(_("Could not remove config section '%s'"), buf.buf); + git_config_set_multivar_or_die(buf.buf, NULL, NULL, 1); strbuf_addf(&old_remote_context, ":refs/remotes/%s/", rename.old); for (i = 0; i < oldremote->fetch_refspec_nr; i++) { char *ptr; @@ -677,8 +668,7 @@ static int mv(int argc, const char **argv) "\tPlease update the configuration manually if necessary."), buf2.buf); - if (git_config_set_multivar(buf.buf, buf2.buf, "^$", 0)) - return error(_("Could not append '%s'"), buf.buf); + git_config_set_multivar_or_die(buf.buf, buf2.buf, "^$", 0); } read_branches(); @@ -688,9 +678,7 @@ static int mv(int argc, const char **argv) if (info->remote_name && !strcmp(info->remote_name, rename.old)) { strbuf_reset(&buf); strbuf_addf(&buf, "branch.%s.remote", item->string); - if (git_config_set(buf.buf, rename.new)) { - return error(_("Could not set '%s'"), buf.buf); - } + git_config_set_or_die(buf.buf, rename.new); } } @@ -788,10 +776,7 @@ static int rm(int argc, const char **argv) strbuf_reset(&buf); strbuf_addf(&buf, "branch.%s.%s", item->string, *k); - if (git_config_set(buf.buf, NULL)) { - strbuf_release(&buf); - return -1; - } + git_config_set_or_die(buf.buf, NULL); } } } -- 2.7.1