From patchwork Tue Apr 13 07:11:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12199465 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2232DC433B4 for ; Tue, 13 Apr 2021 07:11:50 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id E72B1610CA for ; Tue, 13 Apr 2021 07:11:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236725AbhDMHMI (ORCPT ); Tue, 13 Apr 2021 03:12:08 -0400 Received: from out3-smtp.messagingengine.com ([66.111.4.27]:58627 "EHLO out3-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229544AbhDMHMH (ORCPT ); Tue, 13 Apr 2021 03:12:07 -0400 Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailout.nyi.internal (Postfix) with ESMTP id 8ED965C0095; Tue, 13 Apr 2021 03:11:47 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute1.internal (MEProxy); Tue, 13 Apr 2021 03:11:47 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:cc:subject:message-id:references:mime-version :content-type:in-reply-to; s=fm3; bh=/Z98uUx5ppjKUn4QLfLogT06aUx E5/QGfsFMEI8yxdY=; b=b9IDFDlGTu86m+N7F12viuYalMmNx0sUocK+MF7jhuN UYqt4eHZgA7Npi83t2Kuh3nxxQlQVCd+BEo0WrIRw9KGRKQFpPG7W+4D9f7V0hYK h0jGu+8nf/EDRuS/dirbof2DXsXnQRldP0TqdCOnKWPDFFgRWE6ZX3pOV5e0w0ZC h4VVNgav+PDBD+1dsF23lA2EWLAvrYWafu6Veaprs85DNvH+6DA/lI+J7Wk+3YOI V8ybVdpwJkBA4mtwPNXclr3TjPjF17pTLsWSZAERuS5iKq0Z9GMk7NzxWxtI4vrv Y3vymo6ba26ym1OpZ5f2KEtCpKAQydE12KD+u+/nrNg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=/Z98uU x5ppjKUn4QLfLogT06aUxE5/QGfsFMEI8yxdY=; b=KTEmVbDirkUO/fuebzajrU KmlKCl3VD22rnn9o49Yz7ejGwHSvujq6Fn6k3UX9SqEHASnESaQHmGxbqlHpuVh0 rZzWnGN6GOPrFeCof5NiY/DIgpAtyahS/VhB3MPe5u1b/lOMjNYtrJNgmbs+1J1K Q+xIHLIJSR4GlrD5Qqe/43Ew+8aZxI8/fAzyk64PqzFwWHUNLBMXyKa/9+WfKTvE rT2XDbIeO2GxXcY0BciFElgv0bcj0EazvgJxUoKqmlGpu7Jl7+2ut9xTQeecOds+ 55WQ1s+KDH3P0kKNyUXWOSIIO1uk0uwDHlsogv88b7XcTEIB9g1nWE70Mux5f3sA == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrudekkedgudduiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmd enucfjughrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepheeghfdtfeeuffehkefgffduleffjedthfdvjeektdfhhedvlefgtefgvdettdfh necukfhppeekledrudegrdefhedrvddufeenucevlhhushhtvghrufhiiigvpedtnecurf grrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Received: from vm-mail.pks.im (dynamic-089-014-035-213.89.14.pool.telefonica.de [89.14.35.213]) by mail.messagingengine.com (Postfix) with ESMTPA id E148C108005F; Tue, 13 Apr 2021 03:11:45 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id 48f315ea (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Tue, 13 Apr 2021 07:11:38 +0000 (UTC) Date: Tue, 13 Apr 2021 09:11:37 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , =?iso-8859-1?q?=C6var_Arnfj=F6r=F0?= Bjarmason , Eric Sunshine Subject: [PATCH v4 0/3] config: allow overriding global/system config Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Hi, this is the fourth version of my patch series to provide a way of overriding the global system configuration. Compared to v3, I only dropped the special-casing of `/dev/null`. As Junio rightly pointed out, the special-casing was incomplete and would have required more work to do the right thing for all cases. It can still be re-added at a later point if the usecase actually comes up. Patrick Patrick Steinhardt (3): config: rename `git_etc_config()` config: unify code paths to get global config paths config: allow overriding of global and system configuration Documentation/git-config.txt | 5 +++ Documentation/git.txt | 10 +++++ builtin/config.c | 6 +-- config.c | 41 +++++++++++++++------ config.h | 4 +- t/t1300-config.sh | 71 ++++++++++++++++++++++++++++++++++++ 6 files changed, 121 insertions(+), 16 deletions(-) Range-diff against v3: 1: 34bdbc27d6 = 1: 34bdbc27d6 config: rename `git_etc_config()` 2: 30f18679bd = 2: 30f18679bd config: unify code paths to get global config paths 3: af663640ae ! 3: d27efc0aa8 config: allow overriding of global and system configuration @@ Commit message - If unset, git continues to use the usual locations. - If set to a specific path, we skip reading the normal - configuration files and instead take the path. - - - If set to `/dev/null`, we do not load either global- or - system-level configuration at all. + configuration files and instead take the path. By setting the path + to `/dev/null`, no configuration will be loaded for the respective + level. This implements the usecase where we want to execute code in a sanitized environment without any potential misconfigurations via `/dev/null`, but @@ Documentation/git.txt: for further details. Whether to skip reading settings from the system-wide `$(prefix)/etc/gitconfig` file. This environment variable can - ## builtin/config.c ## -@@ builtin/config.c: int cmd_config(int argc, const char **argv, const char *prefix) - char *user_config, *xdg_config; - - git_global_config(&user_config, &xdg_config); -- if (!user_config) -+ if (!user_config) { -+ if (getenv("GIT_CONFIG_GLOBAL")) -+ die(_("GIT_CONFIG_GLOBAL=/dev/null set")); -+ - /* - * It is unknown if HOME/.gitconfig exists, so - * we do not know if we should write to XDG -@@ builtin/config.c: int cmd_config(int argc, const char **argv, const char *prefix) - * is set and points at a sane location. - */ - die(_("$HOME not set")); -+ } - - given_config_source.scope = CONFIG_SCOPE_GLOBAL; - - ## config.c ## @@ config.c: static int git_config_from_blob_ref(config_fn_t fn, char *git_system_config(void) { + char *system_config = xstrdup_or_null(getenv("GIT_CONFIG_SYSTEM")); -+ if (system_config) { -+ if (!strcmp(system_config, "/dev/null")) -+ FREE_AND_NULL(system_config); ++ if (system_config) + return system_config; -+ } return system_path(ETC_GITCONFIG); } @@ config.c: static int git_config_from_blob_ref(config_fn_t fn, + char *user_config = xstrdup_or_null(getenv("GIT_CONFIG_GLOBAL")); + char *xdg_config = NULL; + -+ if (user_config) { -+ if (!strcmp(user_config, "/dev/null")) -+ FREE_AND_NULL(user_config); -+ xdg_config = NULL; -+ } else { ++ if (!user_config) { + user_config = expand_user_path("~/.gitconfig", 0); + xdg_config = xdg_config_home("config"); + }