From patchwork Wed Mar 6 11:31:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13583954 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41F2D78682 for ; Wed, 6 Mar 2024 11:31:37 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724700; cv=none; b=KvFdePHFxtnvYfhUOXeYHwsQo9/544UhQ0IUpUckxysq6WRtonLqrUle08Bp7eaztNy4lJ/XE5tPHSzqatxKYmUWNBEAmLycyAaoV0YgqL4LbJtkTj0BRt92mrHZ/hs1bm3V/m5iGd3Hl7RMAOuic3u0DDtVBjX9Z0QSUq7lsnI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724700; c=relaxed/simple; bh=Z9ZMYQtjkOdsKMzcjrrJXMViLvmD32EUp95zUhLjR8E=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=q+gmWi9And0cVC70MK1hBvnOX8AeB1vl+lBDbUFoHh51jCRQB4KWzHDoBtUETwKeNKe45lNn7+OjHiZibn6p44+waPxTN27p6FeP1V0iyH36jG6rukT0AQwDX+jUmEWFGhpS+ezQE8C9wmHwYJ2OVyBTAldfyTzZ7AF2mSiFeF4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=C6Z82Prw; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=nsOJ/91v; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="C6Z82Prw"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="nsOJ/91v" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfout.nyi.internal (Postfix) with ESMTP id 3CB261380125 for ; Wed, 6 Mar 2024 06:31:37 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 06 Mar 2024 06:31:37 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1709724697; x=1709811097; bh=twsR/+TCFo DauGIieTaIXEK3VOhuj85N2hWYIfa0Bg0=; b=C6Z82PrwS8pa8VhBu4uyWbu0JZ cj2Ocr+I/XGhV7ydtv/M9nyWOxbHvqxRWZaDawIZipNBTZ6woLsRMtxtIpcfGGjk hetdSGPNCIXg52lZal2teVtE27YUPUOTGGXN8XXkQ78GxuNL+ADIXkmIVrjIP5mh 8qpSQ+fDEaDtYrJwBbe4edA6cdvNxDUWvSlFTmCE9+g3zu3potLsjcYUBL+3kGrR p9fHGMVIIp5PmBQEkQ7qLaNq5uGvb2z1Y2J2f7EO+lf+c4yB1OrapI0+K1WybRtR xijyc7esRZHKpSLeiXgNfHJLZy7VVkuZR48NMGbny7f1l6QAD7Zlpbuhi/9A== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1709724697; x=1709811097; bh=twsR/+TCFoDauGIieTaIXEK3VOhu j85N2hWYIfa0Bg0=; b=nsOJ/91v8owS2se7yuDo03lfatE/9T4EOQqM9TerxH7P q/xJ7nBUfikapTBKOCh+igDT1FVUjNDL0MAvHwT3tk+Tc0diH6kYuBvGAJUv3z1L pXezMLT4NZHo58wBZYlBU3Mjhx+k9DvAbhoEn6U8u2b5KHUl3OJ1yGYPJ+6YJ9fD CE8QoiS5KBqQUGlfqJcCNbWH3MrpUfu8bJoDm1RB7bBskMGV2wrNRmQxruIUHJxJ YLb4m2OkIUnFKl9eDXYai1RbjiOqDZN0n8bWiTMR32uBC9Y2QcWJZAgiI5v3RvgG NOYI9to0E9G8q7779SqZvh8s6k8WAyLIqJKWQ5PGEA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugddvjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 6 Mar 2024 06:31:36 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 012f78e1 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 6 Mar 2024 11:27:07 +0000 (UTC) Date: Wed, 6 Mar 2024 12:31:34 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 1/8] builtin/config: move option array around Message-ID: <04210c1932c7df1b2e336089e49d50cf422e9da0.1709724089.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Move around the option array. This will help us with a follow-up commit that introduces subcommands to git-config(1). Signed-off-by: Patrick Steinhardt --- builtin/config.c | 94 ++++++++++++++++++++++++------------------------ 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index b55bfae7d6..6eb6aff917 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -134,53 +134,6 @@ static int option_parse_type(const struct option *opt, const char *arg, return 0; } -static struct option builtin_config_options[] = { - OPT_GROUP(N_("Config file location")), - OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), - OPT_BOOL(0, "system", &use_system_config, N_("use system config file")), - OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")), - OPT_BOOL(0, "worktree", &use_worktree_config, N_("use per-worktree config file")), - OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), - OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")), - OPT_GROUP(N_("Action")), - OPT_BIT(0, "get", &actions, N_("get value: name [value-pattern]"), ACTION_GET), - OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-pattern]"), ACTION_GET_ALL), - OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP), - OPT_BIT(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), - OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL), - OPT_BIT(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), - OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-pattern]"), ACTION_UNSET), - OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL), - OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), - OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), - OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST), - OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), - OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), - OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), - OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), - OPT_GROUP(N_("Type")), - OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), - OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), - OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT), - OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT), - OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR), - OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), - OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE), - OPT_GROUP(N_("Other")), - OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), - OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")), - OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), - OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), - OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")), - OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), - OPT_END(), -}; - -static NORETURN void usage_builtin_config(void) -{ - usage_with_options(builtin_config_usage, builtin_config_options); -} - static void check_argc(int argc, int min, int max) { if (argc >= min && argc <= max) @@ -669,6 +622,53 @@ static char *default_user_config(void) return strbuf_detach(&buf, NULL); } +static struct option builtin_config_options[] = { + OPT_GROUP(N_("Config file location")), + OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), + OPT_BOOL(0, "system", &use_system_config, N_("use system config file")), + OPT_BOOL(0, "local", &use_local_config, N_("use repository config file")), + OPT_BOOL(0, "worktree", &use_worktree_config, N_("use per-worktree config file")), + OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), + OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")), + OPT_GROUP(N_("Action")), + OPT_BIT(0, "get", &actions, N_("get value: name [value-pattern]"), ACTION_GET), + OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-pattern]"), ACTION_GET_ALL), + OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP), + OPT_BIT(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), + OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL), + OPT_BIT(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), + OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-pattern]"), ACTION_UNSET), + OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL), + OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), + OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), + OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST), + OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), + OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), + OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), + OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), + OPT_GROUP(N_("Type")), + OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), + OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), + OPT_CALLBACK_VALUE(0, "int", &type, N_("value is decimal number"), TYPE_INT), + OPT_CALLBACK_VALUE(0, "bool-or-int", &type, N_("value is --bool or --int"), TYPE_BOOL_OR_INT), + OPT_CALLBACK_VALUE(0, "bool-or-str", &type, N_("value is --bool or string"), TYPE_BOOL_OR_STR), + OPT_CALLBACK_VALUE(0, "path", &type, N_("value is a path (file or directory name)"), TYPE_PATH), + OPT_CALLBACK_VALUE(0, "expiry-date", &type, N_("value is an expiry date"), TYPE_EXPIRY_DATE), + OPT_GROUP(N_("Other")), + OPT_BOOL('z', "null", &end_nul, N_("terminate values with NUL byte")), + OPT_BOOL(0, "name-only", &omit_values, N_("show variable names only")), + OPT_BOOL(0, "includes", &respect_includes_opt, N_("respect include directives on lookup")), + OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), + OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")), + OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), + OPT_END(), +}; + +static NORETURN void usage_builtin_config(void) +{ + usage_with_options(builtin_config_usage, builtin_config_options); +} + int cmd_config(int argc, const char **argv, const char *prefix) { int nongit = !startup_info->have_repository; From patchwork Wed Mar 6 11:31:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13583955 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 012CD7FBC5 for ; Wed, 6 Mar 2024 11:31:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724703; cv=none; b=EOmI1mm12HNG3z8r2mYSyGmX12kt/7LTxjAcbfnFZK0ZC8KzN3ZcPNl1t6TyLcvcnGTT9Sqfl32dsY0ccXKWqF3ZfHPgLcq4cA5DqCDDztbDrtuA0j88Ml1yW4Hvk0EvM09QJfRFEUzm/Mijl6tUzOgJe1Cl2nPSbFMIsaHKXho= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724703; c=relaxed/simple; bh=B+pmX9y1AMaO3yw38gCrP9JwMRU/2MV2dOdSvvH7JOo=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=NBZ8bUZidlsxBrpiaILxl2dtrPoYxsoXPLh7ZXzORkoZqc7ulauCxao0YfUknnml+tfI+NdQ1sMzwbDW3VKg2MkEAvgXGPtQhiU35/cn0bFRcXpU0sbiO0lNqQ5yXbUqGAoEvN8IQ+qvAaZWJZetPbJvu5Xa2oJW+G7ZqHX5Fs4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=G0i72UGr; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=kBoVBPQX; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="G0i72UGr"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="kBoVBPQX" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 1E7E91140087 for ; Wed, 6 Mar 2024 06:31:41 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 06 Mar 2024 06:31:41 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1709724701; x=1709811101; bh=n4amtdMpjF XUbqhAlpC7nT12kHAdrFTqr6WpcnrlAPU=; b=G0i72UGr2KWe/VxsPujhxZYD70 PcycdC2VC8CDKOXpRL+l5mPGqYWJV16/dMmcSo7x0NbRsdN/7TJfeR9V/fSnWuPX HOIwsB4wTgV0UP4AMCDr47c5p8S8tEXTKKvfAqO6Y4TFY1PmYHQrZFcg/+BqZqi6 aJNZ9vxqOFnylB7sMSQk4K/3X1BwAk7/KyHcBb+NU8Y/pUiLtiwbmbawGbQuBxrk xW2068zFfzps9RTNp/CxvtGOtXGwgHwZySniKUTQoOdcMfBnl4zqEWz5LDmB+aHI dVqC5fdO/YMix3YOIvuI+xeqhfkDMSJgQvNuzlr0HUlTQ6Kzq5NkA0RdQ0Xw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1709724701; x=1709811101; bh=n4amtdMpjFXUbqhAlpC7nT12kHAd rFTqr6WpcnrlAPU=; b=kBoVBPQXVxMRECCZyEVaLnKZho/Pd4p3VHnsTO+xBB5Q 93KqZRklsDYxEmGDuSoFCza9n2WplYbZbu4yvMxpw4F1L9sSznfAyaiQ3Nz5Alux YgfOuKYRqSf2VgUQHSk27R2q2sdgmv17wah2jRUCI6TVJJYqxL+iUyXG0xDhrj3+ mZQ8PmZhAgztzysXxh5QcLijDslFwTgaHGwecOsQewFulGbgh8bsTv7fsKTP1CfL 2xaussWDgtJwFdIxN/CEVFb4ukNprmrsS/OpjWKIeV5UH59B21oOGZg+BYYquqOP eH16U1Sa3PwFKGlSLse2N+t73c3MDoyxrchp18vd+w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugddviecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 6 Mar 2024 06:31:40 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 53f4194d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 6 Mar 2024 11:27:11 +0000 (UTC) Date: Wed, 6 Mar 2024 12:31:38 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 2/8] builtin/config: move "fixed-value" option to correct group Message-ID: <4c3655574ab7ef1eadf75aed883536204e542979.1709724089.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The `--fixed-value` option can be used to alter how the value-pattern parameter is interpreted for the various submodes of git-config(1). But while it is an option, it is currently listed as part of the submodes group the command, which is wrong. Move the option to the "Other" group, which hosts the various options known to git-config(1). Signed-off-by: Patrick Steinhardt --- builtin/config.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/config.c b/builtin/config.c index 6eb6aff917..fcd6190f12 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -642,7 +642,6 @@ static struct option builtin_config_options[] = { OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST), - OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), @@ -661,6 +660,7 @@ static struct option builtin_config_options[] = { OPT_BOOL(0, "show-origin", &show_origin, N_("show origin of config (file, standard input, blob, command line)")), OPT_BOOL(0, "show-scope", &show_scope, N_("show scope of config (worktree, local, global, system, command)")), OPT_STRING(0, "default", &default_value, N_("value"), N_("with --get, use default value when missing entry")), + OPT_BOOL(0, "fixed-value", &fixed_value, N_("use string equality when comparing values to 'value-pattern'")), OPT_END(), }; From patchwork Wed Mar 6 11:31:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13583956 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B30107FBA5 for ; Wed, 6 Mar 2024 11:31:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724707; cv=none; b=prdox6wNjkVHg2pf4T6sFJBfGDZrKRwqQbt5quxB42WVOD3G4UTFF/2u8yHULmasTF5HuMUBSm/XPYlBaP/CNe27un7HQAg0MtqVGmbqstDfHhNJ92xcVu2fVhcmyUOy2oiyWnxrEqZGdKF23+DBLPDkZx+tpVOCp7lm6agtVXo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724707; c=relaxed/simple; bh=+tyrTuqhu4N6kOmtI9lBR4/ozeIqvIk3L2/PzIdSFMQ=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UMSVLMQp5iL5hj0CkfzToMg1dBQak+/EFPRcEAB2KcTJmrSmD+Trec2oC72uicVqGryQqcHdyMqRWY8WYcIWk7QdOT7cYl59WAONjZu9x+8n+Rm+cafL/9v/HIsMmE8I6QdRgUjsF0qhhBHzcOFYV9XNs1habZOIB8iQBuOis8M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=XjFQrm8t; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=SB4fbh2G; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="XjFQrm8t"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="SB4fbh2G" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id F406711400D9 for ; Wed, 6 Mar 2024 06:31:44 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 06 Mar 2024 06:31:44 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1709724704; x=1709811104; bh=0JDoXiHCXt blsTQzRV+ve3MyFZ69lw/k5MmilvQ7F6w=; b=XjFQrm8t6J8pTZi8w+GEeeokIr pvY5OkFOgK5W6T9+fAdrdTmDtH/TaGuct/kv3Knj/HJ5NQVguWt+9JUWHPY2U9vG +XNhXQoN5HvhlH3lEIcNxpsa8Ii209vQKrVFkvrbGev2xDLNS38fVFnYzeozCtCP BWeL7s8dBhudn99U79d9HlvlzpzJ5qdtbMtJskPZhoY2JBu78toWDIK62a6cQRwU 21wWv5wZBGNip6ngz0cBbDxGr7ZemZzXGyoYTohLlrKfxSTsadDIC721kmF1b8tB rmUpvO6upKhHm09+i84IncQ3oJKbPUGOJNi/5vIukEnDy714UHiMtG16c+Pg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1709724704; x=1709811104; bh=0JDoXiHCXtblsTQzRV+ve3MyFZ69 lw/k5MmilvQ7F6w=; b=SB4fbh2Gk287wCfcQDkggxQeH+TplFu/Jj33JqINJ/6f 01moel5ngrXtUz3B5D/ospJ/yZjetTkpDt+uAS6BusbXBe7HSf87i1/KhteS24mQ bnyO7pP4OnnPNQ3wGgY1gpQry6uatTXMXNisTJWsKT74/ryX8HO44/xV22rfCsrC BgbeK1VHuyisoIvfWzsF+eYfCOdfrYtzHaYR+V6aVS7b1XaDBkQrVKE4o+/A31cU jMHUJGiqD4G8ML+G4XoL3HsN/EtckoutIBJ1LywJMRETN9n2374kc1VBMhfjZ0Kj XyoPhk1Qf8xPslAMZlkjc9lDPM94Su+VzM8xNNHioA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugddvjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 6 Mar 2024 06:31:44 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 614662ae (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 6 Mar 2024 11:27:15 +0000 (UTC) Date: Wed, 6 Mar 2024 12:31:42 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 3/8] builtin/config: use `OPT_CMDMODE()` to specify modes Message-ID: <41e5bf1d6aa35a32f961b7f9d82a70781674eed0.1709724089.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The git-config(1) command has various different modes which are accessible via e.g. `--get-urlmatch` or `--unset-all`. These modes are declared with `OPT_BIT()`, which causes two minor issues: - The respective modes also have a negated form `--no-get-urlmatch`, which is unintended. - We have to manually handle exclusiveness of the modes. Switch these options to instead use `OPT_CMDMODE()`, which is made exactly for this usecase. Remove the now-unneeded check that only a single mode is given, which is now handled by the parse-options interface. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 32 ++++++++++++++------------------ t/t1300-config.sh | 13 +++++++++++++ 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index fcd6190f12..8a2d1a5de7 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -631,20 +631,20 @@ static struct option builtin_config_options[] = { OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")), OPT_GROUP(N_("Action")), - OPT_BIT(0, "get", &actions, N_("get value: name [value-pattern]"), ACTION_GET), - OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-pattern]"), ACTION_GET_ALL), - OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP), - OPT_BIT(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), - OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL), - OPT_BIT(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), - OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-pattern]"), ACTION_UNSET), - OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL), - OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), - OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), - OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST), - OPT_BIT('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), - OPT_BIT(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), - OPT_BIT(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), + OPT_CMDMODE(0, "get", &actions, N_("get value: name [value-pattern]"), ACTION_GET), + OPT_CMDMODE(0, "get-all", &actions, N_("get all values: key [value-pattern]"), ACTION_GET_ALL), + OPT_CMDMODE(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP), + OPT_CMDMODE(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), + OPT_CMDMODE(0, "replace-all", &actions, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL), + OPT_CMDMODE(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), + OPT_CMDMODE(0, "unset", &actions, N_("remove a variable: name [value-pattern]"), ACTION_UNSET), + OPT_CMDMODE(0, "unset-all", &actions, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL), + OPT_CMDMODE(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), + OPT_CMDMODE(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), + OPT_CMDMODE('l', "list", &actions, N_("list all"), ACTION_LIST), + OPT_CMDMODE('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), + OPT_CMDMODE(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), + OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), OPT_GROUP(N_("Type")), OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), @@ -767,10 +767,6 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_builtin_config(); } - if (HAS_MULTI_BITS(actions)) { - error(_("only one action at a time")); - usage_builtin_config(); - } if (actions == 0) switch (argc) { case 1: actions = ACTION_GET; break; diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 31c3878687..2d1bc1e27e 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -2612,4 +2612,17 @@ test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such grep "fatal: remote URLs cannot be configured in file directly or indirectly included by includeIf.hasconfig:remote.*.url" err ' +test_expect_success 'negated mode causes failure' ' + test_must_fail git config --no-get 2>err && + grep "unknown option \`no-get${SQ}" err +' + +test_expect_success 'specifying multiple modes causes failure' ' + cat >expect <<-EOF && + error: options ${SQ}--get-all${SQ} and ${SQ}--get${SQ} cannot be used together + EOF + test_must_fail git config --get --get-all 2>err && + test_cmp expect err +' + test_done From patchwork Wed Mar 6 11:31:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13583957 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D1DD5763FC for ; Wed, 6 Mar 2024 11:31:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724711; cv=none; b=Ubv3Vf3jAYgK8uI+C1wAYWQMVnYPgIF6LF2XBqDjZL4bXwyGtuq631oplkWArlr54elE9jMOr2gkUFT0MzEUC5kR4FvkWf83yND0/YJez9lel1ukcHWXcEAzmskuAWIpJvNBs82CpNzslbF6Zbgj1BFoQ2DQUgASJe49cMpHWSM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724711; c=relaxed/simple; bh=WXThz9gaAYjRePvHBXPpZJlPe7/LpRzeBnRjEZkm8RQ=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cOrfWhGN69ciwhaoN866MB/AehsBMbW2L76hRy26qvfzvl8qFVh//K+bMBW1r2Isg8nVgGjwAuSV7TWlcfY5h4ioOgbSNYwrx3OvZ7Ho8zbLxVX9mOg2CTFrwP1VxhbTrQ93ieYxKErKN1PhDoQ901Kvl/1JYMjQ3kjla9Yc6K8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=LTjlqjMT; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=iaW5kaG8; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="LTjlqjMT"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="iaW5kaG8" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id DB07111400D9 for ; Wed, 6 Mar 2024 06:31:48 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 06 Mar 2024 06:31:48 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1709724708; x=1709811108; bh=tXtGp0beN8 zvPqLmF7sjQupDSF79Lvqfk2DL9pRoED4=; b=LTjlqjMTX0E0HGdq4de9o+RRzL 3Bl7ZENw6xXL4RzHo7re3O6S5lT9u0CSMfHI/nyHXsV245b/SVixdkrOXt1FWRSw /giZ+MHtQqwbfOLq0uDOhx3oOjq5k9+OZjA/mjKZjWUCnQQZUE4TNA1KaMYoHPjZ yOcWGWXVJNlPAEtuOceqlGZgazaMAUQFhBxi5Tm8jc6uekg+vHC+6uA0QQ/6kMhP IqBIWUqTNHrLT3QW6v+kttObS6RFWBJnbZc5YVb4m5LQFMetkMWfsFfkU7zknS2K 8NxRPoUBcAsUPGVXd1ZzjZobbfBQ84JUac0a+TsKWF2NasalrST6q+A2+CNw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1709724708; x=1709811108; bh=tXtGp0beN8zvPqLmF7sjQupDSF79 Lvqfk2DL9pRoED4=; b=iaW5kaG8nrtCuhHtHghcK+Tlj32MfttJFZK7CLqERRn9 yHs5v4ChwC82eMWkdWrUczTjNIqkvbmrb8GUOukHL0j1MhpuP0XE92VJjE9m94QJ 8LwoeHOK1N/Z7o0aQz9g+XHXFMgX6UAFksLJXcwoANII2AUDXm+UghylcpE1gJKJ Kq9lC4OeD6WLsR6eVXqk2jLw6F/qteIdlQ4/AFmGAzPWb2XVFNGr5y7QyDs7UlB6 5fL2Uvc6xSHvpC05Beyu1tQ0V6oTd9KefSLKQcZuoCCfJZZyy7cwMbamIWK658Uy LrIl1oAGWPgL+mbmHimCACzGtu90zFmfuFR1i1fSmw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugddvjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 6 Mar 2024 06:31:48 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7269e439 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 6 Mar 2024 11:27:19 +0000 (UTC) Date: Wed, 6 Mar 2024 12:31:46 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 4/8] builtin/config: move modes into separate functions Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: The git-config(1) command has several different modes which cause it to do different things. The logic for each of these modes is hosted in a giant switch in `cmd_config()` itself. For one, this is hard to read. But second, we're about to introduce proper subcommands to git-config(1) that will require separate functions for each of the modes. Refactor the code and move each mode into its own function to prepare for this. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 410 +++++++++++++++++++++++++++++------------------ 1 file changed, 255 insertions(+), 155 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 8a2d1a5de7..a6ab9b8204 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -44,6 +44,7 @@ static struct config_options config_options; static int show_origin; static int show_scope; static int fixed_value; +static int config_flags; #define ACTION_GET (1<<0) #define ACTION_GET_ALL (1<<1) @@ -622,6 +623,225 @@ static char *default_user_config(void) return strbuf_detach(&buf, NULL); } +static int cmd_config_list(int argc, const char **argv, const char *prefix) +{ + check_argc(argc, 0, 0); + if (config_with_options(show_all_config, NULL, + &given_config_source, the_repository, + &config_options) < 0) { + if (given_config_source.file) + die_errno(_("unable to read config file '%s'"), + given_config_source.file); + else + die(_("error processing config file(s)")); + } + + return 0; +} + +static int cmd_config_edit(int argc, const char **argv, const char *prefix) +{ + char *config_file; + + check_argc(argc, 0, 0); + if (!given_config_source.file && !startup_info->have_repository) + die(_("not in a git directory")); + if (given_config_source.use_stdin) + die(_("editing stdin is not supported")); + if (given_config_source.blob) + die(_("editing blobs is not supported")); + git_config(git_default_config, NULL); + config_file = given_config_source.file ? + xstrdup(given_config_source.file) : + git_pathdup("config"); + if (use_global_config) { + int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666); + if (fd >= 0) { + char *content = default_user_config(); + write_str_in_full(fd, content); + free(content); + close(fd); + } + else if (errno != EEXIST) + die_errno(_("cannot create configuration file %s"), config_file); + } + launch_editor(config_file, NULL, NULL); + free(config_file); + + return 0; +} + +static int cmd_config_set(int argc, const char **argv, const char *prefix) +{ + struct key_value_info default_kvi = KVI_INIT; + char *value = NULL; + int ret; + + check_write(); + check_argc(argc, 2, 2); + value = normalize_value(argv[0], argv[1], &default_kvi); + ret = git_config_set_in_file_gently(given_config_source.file, argv[0], value); + if (ret == CONFIG_NOTHING_SET) + error(_("cannot overwrite multiple values with a single value\n" + " Use a regexp, --add or --replace-all to change %s."), argv[0]); + + free(value); + return ret; +} + +static int cmd_config_set_all(int argc, const char **argv, const char *prefix) +{ + struct key_value_info default_kvi = KVI_INIT; + char *value = NULL; + int ret; + + check_write(); + check_argc(argc, 2, 3); + value = normalize_value(argv[0], argv[1], &default_kvi); + ret = git_config_set_multivar_in_file_gently(given_config_source.file, + argv[0], value, argv[2], + config_flags); + + free(value); + return ret; +} + +static int cmd_config_add(int argc, const char **argv, const char *prefix) +{ + struct key_value_info default_kvi = KVI_INIT; + char *value = NULL; + int ret; + + check_write(); + check_argc(argc, 2, 2); + value = normalize_value(argv[0], argv[1], &default_kvi); + ret = git_config_set_multivar_in_file_gently(given_config_source.file, + argv[0], value, + CONFIG_REGEX_NONE, + config_flags); + + free(value); + return ret; +} + +static int cmd_config_replace_all(int argc, const char **argv, const char *prefix) +{ + struct key_value_info default_kvi = KVI_INIT; + char *value = NULL; + int ret; + + check_write(); + check_argc(argc, 2, 3); + value = normalize_value(argv[0], argv[1], &default_kvi); + ret = git_config_set_multivar_in_file_gently(given_config_source.file, + argv[0], value, argv[2], + config_flags | CONFIG_FLAGS_MULTI_REPLACE); + + free(value); + return ret; +} + +static int cmd_config_get(int argc, const char **argv, const char *prefix) +{ + check_argc(argc, 1, 2); + return get_value(argv[0], argv[1], config_flags); +} + +static int cmd_config_get_all(int argc, const char **argv, const char *prefix) +{ + do_all = 1; + check_argc(argc, 1, 2); + return get_value(argv[0], argv[1], config_flags); +} + +static int cmd_config_get_regexp(int argc, const char **argv, const char *prefix) +{ + show_keys = 1; + use_key_regexp = 1; + do_all = 1; + check_argc(argc, 1, 2); + return get_value(argv[0], argv[1], config_flags); +} + +static int cmd_config_get_urlmatch(int argc, const char **argv, const char *prefix) +{ + check_argc(argc, 2, 2); + return get_urlmatch(argv[0], argv[1]); +} + +static int cmd_config_unset(int argc, const char **argv, const char *prefix) +{ + check_write(); + check_argc(argc, 1, 2); + if (argc == 2) + return git_config_set_multivar_in_file_gently(given_config_source.file, + argv[0], NULL, argv[1], + config_flags); + else + return git_config_set_in_file_gently(given_config_source.file, + argv[0], NULL); +} + +static int cmd_config_unset_all(int argc, const char **argv, const char *prefix) +{ + check_write(); + check_argc(argc, 1, 2); + return git_config_set_multivar_in_file_gently(given_config_source.file, + argv[0], NULL, argv[1], + config_flags | CONFIG_FLAGS_MULTI_REPLACE); +} + +static int cmd_config_rename_section(int argc, const char **argv, const char *prefix) +{ + int ret; + + check_write(); + check_argc(argc, 2, 2); + ret = git_config_rename_section_in_file(given_config_source.file, + argv[0], argv[1]); + if (ret < 0) + return ret; + else if (!ret) + die(_("no such section: %s"), argv[0]); + else + ret = 0; + + return ret; +} + +static int cmd_config_remove_section(int argc, const char **argv, const char *prefix) +{ + int ret; + + check_write(); + check_argc(argc, 1, 1); + ret = git_config_rename_section_in_file(given_config_source.file, + argv[0], NULL); + if (ret < 0) + return ret; + else if (!ret) + die(_("no such section: %s"), argv[0]); + else + ret = 0; + + return ret; +} + +static int cmd_config_get_color(int argc, const char **argv, const char *prefix) +{ + check_argc(argc, 1, 2); + get_color(argv[0], argv[1]); + return 0; +} + +static int cmd_config_get_colorbool(int argc, const char **argv, const char *prefix) +{ + check_argc(argc, 1, 2); + if (argc == 2) + color_stdout_is_tty = git_config_bool("command line", argv[1]); + return get_colorbool(argv[0], argc == 2); +} + static struct option builtin_config_options[] = { OPT_GROUP(N_("Config file location")), OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), @@ -671,12 +891,6 @@ static NORETURN void usage_builtin_config(void) int cmd_config(int argc, const char **argv, const char *prefix) { - int nongit = !startup_info->have_repository; - char *value = NULL; - int flags = 0; - int ret = 0; - struct key_value_info default_kvi = KVI_INIT; - given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); argc = parse_options(argc, argv, prefix, builtin_config_options, @@ -690,7 +904,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_builtin_config(); } - if (nongit) { + if (!startup_info->have_repository) { if (use_local_config) die(_("--local can only be used inside a git repository")); if (given_config_source.blob) @@ -751,7 +965,7 @@ int cmd_config(int argc, const char **argv, const char *prefix) config_options.respect_includes = !given_config_source.file; else config_options.respect_includes = respect_includes_opt; - if (!nongit) { + if (startup_info->have_repository) { config_options.commondir = get_git_common_dir(); config_options.git_dir = get_git_dir(); } @@ -826,159 +1040,45 @@ int cmd_config(int argc, const char **argv, const char *prefix) usage_builtin_config(); } - flags |= CONFIG_FLAGS_FIXED_VALUE; + config_flags |= CONFIG_FLAGS_FIXED_VALUE; } if (actions & PAGING_ACTIONS) setup_auto_pager("config", 1); if (actions == ACTION_LIST) { - check_argc(argc, 0, 0); - if (config_with_options(show_all_config, NULL, - &given_config_source, the_repository, - &config_options) < 0) { - if (given_config_source.file) - die_errno(_("unable to read config file '%s'"), - given_config_source.file); - else - die(_("error processing config file(s)")); - } + return cmd_config_list(argc, argv, prefix); + } else if (actions == ACTION_EDIT) { + return cmd_config_edit(argc, argv, prefix); + } else if (actions == ACTION_SET) { + return cmd_config_set(argc, argv, prefix); + } else if (actions == ACTION_SET_ALL) { + return cmd_config_set_all(argc, argv, prefix); + } else if (actions == ACTION_ADD) { + return cmd_config_add(argc, argv, prefix); + } else if (actions == ACTION_REPLACE_ALL) { + return cmd_config_replace_all(argc, argv, prefix); + } else if (actions == ACTION_GET) { + return cmd_config_get(argc, argv, prefix); + } else if (actions == ACTION_GET_ALL) { + return cmd_config_get_all(argc, argv, prefix); + } else if (actions == ACTION_GET_REGEXP) { + return cmd_config_get_regexp(argc, argv, prefix); + } else if (actions == ACTION_GET_URLMATCH) { + return cmd_config_get_urlmatch(argc, argv, prefix); + } else if (actions == ACTION_UNSET) { + return cmd_config_unset(argc, argv, prefix); + } else if (actions == ACTION_UNSET_ALL) { + return cmd_config_unset_all(argc, argv, prefix); + } else if (actions == ACTION_RENAME_SECTION) { + return cmd_config_rename_section(argc, argv, prefix); + } else if (actions == ACTION_REMOVE_SECTION) { + return cmd_config_remove_section(argc, argv, prefix); + } else if (actions == ACTION_GET_COLOR) { + return cmd_config_get_color(argc, argv, prefix); + } else if (actions == ACTION_GET_COLORBOOL) { + return cmd_config_get_colorbool(argc, argv, prefix); } - else if (actions == ACTION_EDIT) { - char *config_file; - check_argc(argc, 0, 0); - if (!given_config_source.file && nongit) - die(_("not in a git directory")); - if (given_config_source.use_stdin) - die(_("editing stdin is not supported")); - if (given_config_source.blob) - die(_("editing blobs is not supported")); - git_config(git_default_config, NULL); - config_file = given_config_source.file ? - xstrdup(given_config_source.file) : - git_pathdup("config"); - if (use_global_config) { - int fd = open(config_file, O_CREAT | O_EXCL | O_WRONLY, 0666); - if (fd >= 0) { - char *content = default_user_config(); - write_str_in_full(fd, content); - free(content); - close(fd); - } - else if (errno != EEXIST) - die_errno(_("cannot create configuration file %s"), config_file); - } - launch_editor(config_file, NULL, NULL); - free(config_file); - } - else if (actions == ACTION_SET) { - check_write(); - check_argc(argc, 2, 2); - value = normalize_value(argv[0], argv[1], &default_kvi); - ret = git_config_set_in_file_gently(given_config_source.file, argv[0], value); - if (ret == CONFIG_NOTHING_SET) - error(_("cannot overwrite multiple values with a single value\n" - " Use a regexp, --add or --replace-all to change %s."), argv[0]); - } - else if (actions == ACTION_SET_ALL) { - check_write(); - check_argc(argc, 2, 3); - value = normalize_value(argv[0], argv[1], &default_kvi); - ret = git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], value, argv[2], - flags); - } - else if (actions == ACTION_ADD) { - check_write(); - check_argc(argc, 2, 2); - value = normalize_value(argv[0], argv[1], &default_kvi); - ret = git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], value, - CONFIG_REGEX_NONE, - flags); - } - else if (actions == ACTION_REPLACE_ALL) { - check_write(); - check_argc(argc, 2, 3); - value = normalize_value(argv[0], argv[1], &default_kvi); - ret = git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], value, argv[2], - flags | CONFIG_FLAGS_MULTI_REPLACE); - } - else if (actions == ACTION_GET) { - check_argc(argc, 1, 2); - return get_value(argv[0], argv[1], flags); - } - else if (actions == ACTION_GET_ALL) { - do_all = 1; - check_argc(argc, 1, 2); - return get_value(argv[0], argv[1], flags); - } - else if (actions == ACTION_GET_REGEXP) { - show_keys = 1; - use_key_regexp = 1; - do_all = 1; - check_argc(argc, 1, 2); - return get_value(argv[0], argv[1], flags); - } - else if (actions == ACTION_GET_URLMATCH) { - check_argc(argc, 2, 2); - return get_urlmatch(argv[0], argv[1]); - } - else if (actions == ACTION_UNSET) { - check_write(); - check_argc(argc, 1, 2); - if (argc == 2) - return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], NULL, argv[1], - flags); - else - return git_config_set_in_file_gently(given_config_source.file, - argv[0], NULL); - } - else if (actions == ACTION_UNSET_ALL) { - check_write(); - check_argc(argc, 1, 2); - return git_config_set_multivar_in_file_gently(given_config_source.file, - argv[0], NULL, argv[1], - flags | CONFIG_FLAGS_MULTI_REPLACE); - } - else if (actions == ACTION_RENAME_SECTION) { - check_write(); - check_argc(argc, 2, 2); - ret = git_config_rename_section_in_file(given_config_source.file, - argv[0], argv[1]); - if (ret < 0) - return ret; - else if (!ret) - die(_("no such section: %s"), argv[0]); - else - ret = 0; - } - else if (actions == ACTION_REMOVE_SECTION) { - check_write(); - check_argc(argc, 1, 1); - ret = git_config_rename_section_in_file(given_config_source.file, - argv[0], NULL); - if (ret < 0) - return ret; - else if (!ret) - die(_("no such section: %s"), argv[0]); - else - ret = 0; - } - else if (actions == ACTION_GET_COLOR) { - check_argc(argc, 1, 2); - get_color(argv[0], argv[1]); - } - else if (actions == ACTION_GET_COLORBOOL) { - check_argc(argc, 1, 2); - if (argc == 2) - color_stdout_is_tty = git_config_bool("command line", argv[1]); - return get_colorbool(argv[0], argc == 2); - } - - free(value); - return ret; + BUG("invalid action"); } From patchwork Wed Mar 6 11:31:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13583958 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9F0B0763FC for ; Wed, 6 Mar 2024 11:31:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724715; cv=none; b=sq+LZqohl+49dg7zI1Ub/Oao6V6PBvrgtO9wJFKuHsyg0Xlgi5I7fNMABAV7AgjIgAaSoWgLEY7tBu/ZtHB1v6CuKn9nPTmJjubPLZqW/29mA7702HNB3Kjwoud/82S70Z/S16fkkKLPRId+8C3hx3sh5PwZy2U+SqpAY1g2rHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724715; c=relaxed/simple; bh=WslLQBtU0zyG6UecKpzYQ5W1L7PXL7MfUdwvsslWFgo=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=czu8G85d7S0C5ho2zXhhl/g2ZgOvtvG/pQRvgfE/iau4bNIZ9TGgJBzen5lEcGKmORUSMQWClZgNAJOMnJEch8pmIFggqELAf2nhABfgpwCzZkFtN65tV/seRJDXf5CST3N6dnN36sY0tacQQj/OeGCIg5i5gWEDvzL/Iz7wc7E= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=s/4ja3/J; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=bG/srSqU; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="s/4ja3/J"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="bG/srSqU" Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailfhigh.nyi.internal (Postfix) with ESMTP id AE50111400B3 for ; Wed, 6 Mar 2024 06:31:52 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute5.internal (MEProxy); Wed, 06 Mar 2024 06:31:52 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1709724712; x=1709811112; bh=tvRA2uqLRs 1GolxBY3XEM7xmQT8gJUNn9j++HcHTSVo=; b=s/4ja3/J/Ff/AgYGAsYlzft1GK DfkCCL8dy8G1bFoa5jMC1WFOYOj5bScQpdreOECB8O39/gYL+WxB9Zts8xoFyYoC InWdMDVr88H3GIE/ojLMchAKs8LXRXAJ33JZarVEKvVBy6uRL12zdzaRiRjpwwAm ma0QXtWd/vOLs+qvSvPbEB8Y4ZGowy8opse5SI+Dowk46mrIlOpo/PmyOUb7ypW0 Be8+RNHeke62LkOu5Rfqsb5ENbmxphkpVSHhrknJI87Tf9YE0/6pq+cpcCqYhHT/ U4JUSMJA28kfbpQ1wCp2E5LH4cNPwa1CfzcerYVWQlp/9EenQDuerhi+qC9w== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1709724712; x=1709811112; bh=tvRA2uqLRs1GolxBY3XEM7xmQT8g JUNn9j++HcHTSVo=; b=bG/srSqUAd8CjjfvNwYQ1lVmVf0CwcG6sjb3V6HKCIGE ofqxsefZwC2oUQMEn4yWCPwD2h/TYGo0zJwRH6K9NcY5Fo+4E/kAhjbjEn7aIplr EzwPqprhITq9lQIiZmzdlrLpzqNzryYZkk5gi8Vc8kwm/3bgYcP6P4xHUJlr0RyY 7IH42PSdQ6eGXTXXQx1x89fpbsMj0csw13Kvflz8E6ItUBbQ8eH0Kjql7O/HuzRX KzWxyBdbPo9nuRijXKTb5xXklY6QdwGctHACjacLWAc62GbYUhXvY7t8lfYuCx5j wGHoWv2PMzK0Vq5A/3vGVzbYslOy9+FIURhSS9pilA== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugddviecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpedunecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 6 Mar 2024 06:31:52 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 7c68d29d (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 6 Mar 2024 11:27:23 +0000 (UTC) Date: Wed, 6 Mar 2024 12:31:50 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 5/8] builtin/config: track subcommands by action Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Part of `cmd_config()` is a rather unwieldy switch statement that invokes the correct subcommand function based on which action has been requested by the user. Now that we have converted actions to be tracked via a `OPT_CMDMODE()`, we know that the `actions` variable will only ever have at most one bit set. This allows us to convert the variable to use an `enum` instead, and thus to create an array that maps from this newly introduced `enum` to the corresponding subcommand function. Refactor the code to do so. Besides allowing us to get rid of the giant switch statement, this refactoring will also make it easier to introduce proper subcommands to git-config(1). Signed-off-by: Patrick Steinhardt --- builtin/config.c | 207 +++++++++++++++++++++++------------------------ 1 file changed, 99 insertions(+), 108 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index a6ab9b8204..0d58397ef5 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -20,6 +20,26 @@ static const char *const builtin_config_usage[] = { NULL }; +enum config_action { + ACTION_NONE, + ACTION_GET, + ACTION_GET_ALL, + ACTION_GET_REGEXP, + ACTION_REPLACE_ALL, + ACTION_ADD, + ACTION_UNSET, + ACTION_UNSET_ALL, + ACTION_RENAME_SECTION, + ACTION_REMOVE_SECTION, + ACTION_LIST, + ACTION_EDIT, + ACTION_SET, + ACTION_SET_ALL, + ACTION_GET_COLOR, + ACTION_GET_COLORBOOL, + ACTION_GET_URLMATCH, +}; + static char *key; static regex_t *key_regexp; static const char *value_pattern; @@ -33,10 +53,12 @@ static char delim = '='; static char key_delim = ' '; static char term = '\n'; +static parse_opt_subcommand_fn *subcommand; +static enum config_action action = ACTION_NONE; static int use_global_config, use_system_config, use_local_config; static int use_worktree_config; static struct git_config_source given_config_source; -static int actions, type; +static int type; static char *default_value; static int end_nul; static int respect_includes_opt = -1; @@ -46,30 +68,6 @@ static int show_scope; static int fixed_value; static int config_flags; -#define ACTION_GET (1<<0) -#define ACTION_GET_ALL (1<<1) -#define ACTION_GET_REGEXP (1<<2) -#define ACTION_REPLACE_ALL (1<<3) -#define ACTION_ADD (1<<4) -#define ACTION_UNSET (1<<5) -#define ACTION_UNSET_ALL (1<<6) -#define ACTION_RENAME_SECTION (1<<7) -#define ACTION_REMOVE_SECTION (1<<8) -#define ACTION_LIST (1<<9) -#define ACTION_EDIT (1<<10) -#define ACTION_SET (1<<11) -#define ACTION_SET_ALL (1<<12) -#define ACTION_GET_COLOR (1<<13) -#define ACTION_GET_COLORBOOL (1<<14) -#define ACTION_GET_URLMATCH (1<<15) - -/* - * The actions "ACTION_LIST | ACTION_GET_*" which may produce more than - * one line of output and which should therefore be paged. - */ -#define PAGING_ACTIONS (ACTION_LIST | ACTION_GET_ALL | \ - ACTION_GET_REGEXP | ACTION_GET_URLMATCH) - #define TYPE_BOOL 1 #define TYPE_INT 2 #define TYPE_BOOL_OR_INT 3 @@ -842,6 +840,25 @@ static int cmd_config_get_colorbool(int argc, const char **argv, const char *pre return get_colorbool(argv[0], argc == 2); } +static parse_opt_subcommand_fn *subcommands_by_action[] = { + [ACTION_LIST] = cmd_config_list, + [ACTION_EDIT] = cmd_config_edit, + [ACTION_SET] = cmd_config_set, + [ACTION_SET_ALL] = cmd_config_set_all, + [ACTION_ADD] = cmd_config_add, + [ACTION_REPLACE_ALL] = cmd_config_replace_all, + [ACTION_GET] = cmd_config_get, + [ACTION_GET_ALL] = cmd_config_get_all, + [ACTION_GET_REGEXP] = cmd_config_get_regexp, + [ACTION_GET_URLMATCH] = cmd_config_get_urlmatch, + [ACTION_UNSET] = cmd_config_unset, + [ACTION_UNSET_ALL] = cmd_config_unset_all, + [ACTION_RENAME_SECTION] = cmd_config_rename_section, + [ACTION_REMOVE_SECTION] = cmd_config_remove_section, + [ACTION_GET_COLOR] = cmd_config_get_color, + [ACTION_GET_COLORBOOL] = cmd_config_get_colorbool, +}; + static struct option builtin_config_options[] = { OPT_GROUP(N_("Config file location")), OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), @@ -851,20 +868,20 @@ static struct option builtin_config_options[] = { OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")), OPT_GROUP(N_("Action")), - OPT_CMDMODE(0, "get", &actions, N_("get value: name [value-pattern]"), ACTION_GET), - OPT_CMDMODE(0, "get-all", &actions, N_("get all values: key [value-pattern]"), ACTION_GET_ALL), - OPT_CMDMODE(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP), - OPT_CMDMODE(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), - OPT_CMDMODE(0, "replace-all", &actions, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL), - OPT_CMDMODE(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD), - OPT_CMDMODE(0, "unset", &actions, N_("remove a variable: name [value-pattern]"), ACTION_UNSET), - OPT_CMDMODE(0, "unset-all", &actions, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL), - OPT_CMDMODE(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), - OPT_CMDMODE(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION), - OPT_CMDMODE('l', "list", &actions, N_("list all"), ACTION_LIST), - OPT_CMDMODE('e', "edit", &actions, N_("open an editor"), ACTION_EDIT), - OPT_CMDMODE(0, "get-color", &actions, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), - OPT_CMDMODE(0, "get-colorbool", &actions, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), + OPT_CMDMODE(0, "get", &action, N_("get value: name [value-pattern]"), ACTION_GET), + OPT_CMDMODE(0, "get-all", &action, N_("get all values: key [value-pattern]"), ACTION_GET_ALL), + OPT_CMDMODE(0, "get-regexp", &action, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP), + OPT_CMDMODE(0, "get-urlmatch", &action, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), + OPT_CMDMODE(0, "replace-all", &action, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL), + OPT_CMDMODE(0, "add", &action, N_("add a new variable: name value"), ACTION_ADD), + OPT_CMDMODE(0, "unset", &action, N_("remove a variable: name [value-pattern]"), ACTION_UNSET), + OPT_CMDMODE(0, "unset-all", &action, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL), + OPT_CMDMODE(0, "rename-section", &action, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), + OPT_CMDMODE(0, "remove-section", &action, N_("remove a section: name"), ACTION_REMOVE_SECTION), + OPT_CMDMODE('l', "list", &action, N_("list all"), ACTION_LIST), + OPT_CMDMODE('e', "edit", &action, N_("open an editor"), ACTION_EDIT), + OPT_CMDMODE(0, "get-color", &action, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), + OPT_CMDMODE(0, "get-colorbool", &action, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), OPT_GROUP(N_("Type")), OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), @@ -976,33 +993,43 @@ int cmd_config(int argc, const char **argv, const char *prefix) key_delim = '\n'; } - if ((actions & (ACTION_GET_COLOR|ACTION_GET_COLORBOOL)) && type) { - error(_("--get-color and variable type are incoherent")); - usage_builtin_config(); - } - - if (actions == 0) + if (action == ACTION_NONE) { switch (argc) { - case 1: actions = ACTION_GET; break; - case 2: actions = ACTION_SET; break; - case 3: actions = ACTION_SET_ALL; break; + case 1: action = ACTION_GET; break; + case 2: action = ACTION_SET; break; + case 3: action = ACTION_SET_ALL; break; default: usage_builtin_config(); } + } + if (action <= ACTION_NONE || action >= ARRAY_SIZE(subcommands_by_action)) + BUG("invalid action %d", action); + subcommand = subcommands_by_action[action]; + + if (type && (subcommand == cmd_config_get_color || + subcommand == cmd_config_get_colorbool)) { + error(_("--get-color and variable type are incoherent")); + usage_builtin_config(); + } + if (omit_values && - !(actions == ACTION_LIST || actions == ACTION_GET_REGEXP)) { + subcommand != cmd_config_list && + subcommand != cmd_config_get_regexp) { error(_("--name-only is only applicable to --list or --get-regexp")); usage_builtin_config(); } - if (show_origin && !(actions & - (ACTION_GET|ACTION_GET_ALL|ACTION_GET_REGEXP|ACTION_LIST))) { + if (show_origin && + subcommand != cmd_config_get && + subcommand != cmd_config_get_all && + subcommand != cmd_config_get_regexp && + subcommand != cmd_config_list) { error(_("--show-origin is only applicable to --get, --get-all, " "--get-regexp, and --list")); usage_builtin_config(); } - if (default_value && !(actions & ACTION_GET)) { + if (default_value && subcommand != cmd_config_get) { error(_("--default is only applicable to --get")); usage_builtin_config(); } @@ -1011,28 +1038,19 @@ int cmd_config(int argc, const char **argv, const char *prefix) if (fixed_value) { int allowed_usage = 0; - switch (actions) { - /* git config --get */ - case ACTION_GET: - /* git config --get-all */ - case ACTION_GET_ALL: - /* git config --get-regexp */ - case ACTION_GET_REGEXP: - /* git config --unset */ - case ACTION_UNSET: - /* git config --unset-all */ - case ACTION_UNSET_ALL: + if (subcommand == cmd_config_get || + subcommand == cmd_config_get_all || + subcommand == cmd_config_get_regexp || + subcommand == cmd_config_unset || + subcommand == cmd_config_unset_all) { + /* git config -- */ allowed_usage = argc > 1 && !!argv[1]; - break; - - /* git config */ - case ACTION_SET_ALL: - /* git config --replace-all */ - case ACTION_REPLACE_ALL: + } else if (subcommand == cmd_config_set_all || + subcommand == cmd_config_replace_all) { + /* git config -- */ allowed_usage = argc > 2 && !!argv[2]; - break; - - /* other options don't allow --fixed-value */ + } else { + /* other options don't allow --fixed-value */ } if (!allowed_usage) { @@ -1043,42 +1061,15 @@ int cmd_config(int argc, const char **argv, const char *prefix) config_flags |= CONFIG_FLAGS_FIXED_VALUE; } - if (actions & PAGING_ACTIONS) + /* + * The actions "ACTION_LIST | ACTION_GET_*" which may produce more than + * one line of output and which should therefore be paged. + */ + if (subcommand == cmd_config_list || + subcommand == cmd_config_get_all || + subcommand == cmd_config_get_regexp || + subcommand == cmd_config_get_urlmatch) setup_auto_pager("config", 1); - if (actions == ACTION_LIST) { - return cmd_config_list(argc, argv, prefix); - } else if (actions == ACTION_EDIT) { - return cmd_config_edit(argc, argv, prefix); - } else if (actions == ACTION_SET) { - return cmd_config_set(argc, argv, prefix); - } else if (actions == ACTION_SET_ALL) { - return cmd_config_set_all(argc, argv, prefix); - } else if (actions == ACTION_ADD) { - return cmd_config_add(argc, argv, prefix); - } else if (actions == ACTION_REPLACE_ALL) { - return cmd_config_replace_all(argc, argv, prefix); - } else if (actions == ACTION_GET) { - return cmd_config_get(argc, argv, prefix); - } else if (actions == ACTION_GET_ALL) { - return cmd_config_get_all(argc, argv, prefix); - } else if (actions == ACTION_GET_REGEXP) { - return cmd_config_get_regexp(argc, argv, prefix); - } else if (actions == ACTION_GET_URLMATCH) { - return cmd_config_get_urlmatch(argc, argv, prefix); - } else if (actions == ACTION_UNSET) { - return cmd_config_unset(argc, argv, prefix); - } else if (actions == ACTION_UNSET_ALL) { - return cmd_config_unset_all(argc, argv, prefix); - } else if (actions == ACTION_RENAME_SECTION) { - return cmd_config_rename_section(argc, argv, prefix); - } else if (actions == ACTION_REMOVE_SECTION) { - return cmd_config_remove_section(argc, argv, prefix); - } else if (actions == ACTION_GET_COLOR) { - return cmd_config_get_color(argc, argv, prefix); - } else if (actions == ACTION_GET_COLORBOOL) { - return cmd_config_get_colorbool(argc, argv, prefix); - } - - BUG("invalid action"); + return subcommand(argc, argv, prefix); } From patchwork Wed Mar 6 11:31:54 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13583959 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7AEEC7FBBD for ; Wed, 6 Mar 2024 11:31:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724720; cv=none; b=uuVTHS/wEcNSJABD2dMzzDjVTLB25QZKZkP0ZJIbYAK8wflVrCGLjQgqNkQznxIYxTi3qX6Zwpm+cyV6Il1HfMHKWfvyyCoQmpxQOjj1qtDxJw32kH6lJbP2/wLcPRnkeXOhN097bSylG2LhzSJt30N64ngHFdzePxR7zNudP94= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724720; c=relaxed/simple; bh=XeC6FDg3t7iebnAP5OI0bfKSTj9kiglaVr0mgpsCUc0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=U+yugFE1SwYcHCNO5H1+5F+Z5AazhTBqxjqhygPboGxBVFW+hCRz7yomJtvnGvbiJI7x1Y7hsto8Dyvs2gRUYoyeoOufGcAnRnJMVQ80CyRiS/Mt55Zzv9YUFYkCwADd2N+zRLWoJ8+8yQNNqtuayZN0q6DM4LmUvujnzEHyJhk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=BlWPZZ97; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=W118BxIC; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="BlWPZZ97"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="W118BxIC" Received: from compute1.internal (compute1.nyi.internal [10.202.2.41]) by mailfhigh.nyi.internal (Postfix) with ESMTP id 90410114008B for ; Wed, 6 Mar 2024 06:31:57 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute1.internal (MEProxy); Wed, 06 Mar 2024 06:31:57 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1709724717; x=1709811117; bh=nscnYRK0fr 48ef1IrNLBpCOFekbF94OX9yxHf93wvxw=; b=BlWPZZ97O2MGYRpmvXxtsQ24WP S1/D68UIDyqopfLp8ct7rsjcSnu649fwvyGzoahfiS+ZHfglHIsdnCOgSFMTHe1b PLUfExs78r6/tPkpGQJsqjr7RQLsbaj/pUK2rK/b186u2tsysM5cfXOUNt3xtMkp 22NWDP1evSLMFGhNod4TDM0zAx35FyxJPzyoeUIDSPcL+sZPf2Bo7vQCct7khsLa qTSh+eRpaT4X6Abbhb4dSvcHijA9JjqKG5XO6/q+RlDGa48c0O+m/g5wb0WH4orX PCvEru5YXYjyNTzkHL01mlxvG1Dew45wbk2wrjYqn7wsZg9+yECv0K0hlwVA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1709724717; x=1709811117; bh=nscnYRK0fr48ef1IrNLBpCOFekbF 94OX9yxHf93wvxw=; b=W118BxICfdDE89miIq/gCuTfhkPoDnQb3+uj9029QwUk p9wi6IECBpsfHY+lqs276enIjayrkolQiNjDfnT09+JoWDJtXHtPvYAFHsuxNlPo T/dC5tqwGFJalQoqqq2o4rGpZcmJ4rH8l7tdPbb2F1j3ne1h70dFk0h6Mvzn0GAm aXPZp6kesLda4+IVHfczLkEhNb9bzplnRZvGRd9ndEGDWNaCS7veLFrsp+osYOaP NInS1Qlt2vELA+rSW1Mhek4RKgyEgg2T9ZSsDrqsaCibOeS20DoXpIu2gt/a30WJ SpfXmsnOp24NjLDdNYWSwYUX0WyR/PgC33o8rf/Vuw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugddvjecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtdfhvd ejkedthfehvdelgfetgfdvtedthfenucevlhhushhtvghrufhiiigvpeefnecurfgrrhgr mhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 6 Mar 2024 06:31:56 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id bf38db61 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 6 Mar 2024 11:27:27 +0000 (UTC) Date: Wed, 6 Mar 2024 12:31:54 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 6/8] builtin/config: introduce subcommands Message-ID: References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: While git-config(1) has several modes, those modes are not exposed with subcommands but instead by specifying e.g. `--unset` or `--list`. This user interface is not really in line with how our more modern commands work, where it is a lot more customary to say e.g. `git remote list`. Furthermore, to add to the confusion, git-config(1) also allows the user to request modes implicitly by just specifying the correct number of arguments. Thus, `git config foo.bar` will retrieve the value of "foo.bar" while `git config foo.bar baz` will set it to "baz". Overall, this makes for a confusing interface that could really use a makeover. It hurts discoverability of what you can do with git-config(1) and is comparatively easy to get wrong. Modernize git-config(1) so that it understands proper subcommands like "list" or "unset". Like this, a user can say "git config get foo.bar" to retrieve the config key's value and "git config set foo.bar baz" to set it. One concern in this context is backwards compatibility. Luckily, we can introduce subcommands without breaking backwards compatibility at all. This is because all the implicit modes of git-config(1) require that the first argument is a properly formatted config key. And as config keys _must_ have a dot in their name, any value without a dot would have been discarded by git-config(1) previous to this change. Thus, given that none of the subcommands do have a dot, they are unambiguous. Consequently, we introduce subcommands in such a way that git-config(1) understands both the old and the new syntax at the same time. This should help to transition to the new-style syntax until we eventually deprecate and remove the old-style syntax. Signed-off-by: Patrick Steinhardt --- builtin/config.c | 52 +++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 45 insertions(+), 7 deletions(-) diff --git a/builtin/config.c b/builtin/config.c index 0d58397ef5..10fa933931 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -859,6 +859,26 @@ static parse_opt_subcommand_fn *subcommands_by_action[] = { [ACTION_GET_COLORBOOL] = cmd_config_get_colorbool, }; +static struct option builtin_subcommand_options[] = { + OPT_SUBCOMMAND("list", &subcommand, cmd_config_list), + OPT_SUBCOMMAND("get", &subcommand, cmd_config_get), + OPT_SUBCOMMAND("get-all", &subcommand, cmd_config_get_all), + OPT_SUBCOMMAND("get-color", &subcommand, cmd_config_get_color), + OPT_SUBCOMMAND("get-colorbool", &subcommand, cmd_config_get_colorbool), + OPT_SUBCOMMAND("get-regexp", &subcommand, cmd_config_get_regexp), + OPT_SUBCOMMAND("get-urlmatch", &subcommand, cmd_config_get_urlmatch), + OPT_SUBCOMMAND("add", &subcommand, cmd_config_add), + OPT_SUBCOMMAND("set", &subcommand, cmd_config_set), + OPT_SUBCOMMAND("set-all", &subcommand, cmd_config_set_all), + OPT_SUBCOMMAND("unset", &subcommand, cmd_config_unset), + OPT_SUBCOMMAND("unset-all", &subcommand, cmd_config_unset_all), + OPT_SUBCOMMAND("replace-all", &subcommand, cmd_config_replace_all), + OPT_SUBCOMMAND("rename-section", &subcommand, cmd_config_rename_section), + OPT_SUBCOMMAND("remove-section", &subcommand, cmd_config_remove_section), + OPT_SUBCOMMAND("edit", &subcommand, cmd_config_edit), + OPT_END(), +}; + static struct option builtin_config_options[] = { OPT_GROUP(N_("Config file location")), OPT_BOOL(0, "global", &use_global_config, N_("use global config file")), @@ -910,6 +930,20 @@ int cmd_config(int argc, const char **argv, const char *prefix) { given_config_source.file = xstrdup_or_null(getenv(CONFIG_ENVIRONMENT)); + /* + * This is somewhat hacky: we first parse the command line while + * keeping all args intact in order to determine whether a subcommand + * has been specified. If so, we re-parse it a second time, but this + * time we drop KEEP_ARGV0. This is so that we don't munge the command + * line in case no subcommand was given, which would otherwise confuse + * us when parsing the implicit modes. + */ + argc = parse_options(argc, argv, prefix, builtin_subcommand_options, builtin_config_usage, + PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_ARGV0|PARSE_OPT_KEEP_UNKNOWN_OPT); + if (subcommand) + argc = parse_options(argc, argv, prefix, builtin_subcommand_options, builtin_config_usage, + PARSE_OPT_SUBCOMMAND_OPTIONAL|PARSE_OPT_KEEP_UNKNOWN_OPT); + argc = parse_options(argc, argv, prefix, builtin_config_options, builtin_config_usage, PARSE_OPT_STOP_AT_NON_OPTION); @@ -993,18 +1027,22 @@ int cmd_config(int argc, const char **argv, const char *prefix) key_delim = '\n'; } - if (action == ACTION_NONE) { + if (action != ACTION_NONE && subcommand) { + error(_("subcommand and action modes are incompatible")); + usage_builtin_config(); + } else if (action == ACTION_NONE && !subcommand) { switch (argc) { - case 1: action = ACTION_GET; break; - case 2: action = ACTION_SET; break; - case 3: action = ACTION_SET_ALL; break; + case 1: subcommand = cmd_config_get; break; + case 2: subcommand = cmd_config_set; break; + case 3: subcommand = cmd_config_set_all; break; default: usage_builtin_config(); } + } else if (action != ACTION_NONE) { + if (action < ACTION_NONE || action >= ARRAY_SIZE(subcommands_by_action)) + BUG("invalid action %d", action); + subcommand = subcommands_by_action[action]; } - if (action <= ACTION_NONE || action >= ARRAY_SIZE(subcommands_by_action)) - BUG("invalid action %d", action); - subcommand = subcommands_by_action[action]; if (type && (subcommand == cmd_config_get_color || subcommand == cmd_config_get_colorbool)) { From patchwork Wed Mar 6 11:31:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13583960 Received: from fhigh4-smtp.messagingengine.com (fhigh4-smtp.messagingengine.com [103.168.172.155]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B7CC678682 for ; Wed, 6 Mar 2024 11:32:02 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.155 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724727; cv=none; b=SLxu1IBzFpBPymiuJurATv+iEskHxjJ2DxNVAon59E4q1Pt3ZLt6BWerUREZZp8MiaOpKRRx/4FXlDFUf4c+UETHJ/202nQPngUi9nrQCCUksNmuiYg9U3fOLbHS9fYfXc6wh6K4FJy7AZpcAHjDncrAsA3pgSxRONxvYqf4IIE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724727; c=relaxed/simple; bh=MAH7nMaDfoC+tuE7RLGuSbDBqZkgrzNoisf/RxNB600=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QsiG7KETOia6YU8mrg+iyEY9RAB0vRgaEi3wPiKvo7srMUdM02ux3ST2A71gRvzyHXip9Owq04ffBuDjrb1oXPQf2C8G0k104hncqv7GbWqQm0gZVG7oJasGWidr4VQKkPH85l6iJLdP4nGA6gaWQJlFG4/c6qXkLRuj69BlVng= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=CyL5XPnz; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=Jahr4AQ3; arc=none smtp.client-ip=103.168.172.155 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="CyL5XPnz"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="Jahr4AQ3" Received: from compute7.internal (compute7.nyi.internal [10.202.2.48]) by mailfhigh.nyi.internal (Postfix) with ESMTP id D01D61140098 for ; Wed, 6 Mar 2024 06:32:01 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute7.internal (MEProxy); Wed, 06 Mar 2024 06:32:01 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1709724721; x=1709811121; bh=Z4qG4epX/U n2UO8UTnbvWv353f1aU5hgiM1PqZ1IozA=; b=CyL5XPnz8MimS1ctbhKQMK1fLh lILU5xyNr65YpXcZ5JhBwokQPlvALnC5nM1ZTXMICSeGNG5qVhJBaZdhbF267E/6 EQwSPGUHUUvJcqF4VGp58Hy5SpLX85sPHYxypX/7TPNUWe7wwEmeuobh0zt11i58 e2blXBsCM5vjsRdeuy2LqZMj9iWM5sdt2YhwBSahVYSUz19yg5+8DcBrjUnUwZpQ AW6Zx+2OiaHIaaqn6MJ/qD9dE5cFaFOVPxYH2bCU4/9Z2+9UbXwaRz5V2nq0Xcu1 pIBIj9IZC4b8YH8h84IXoWdo/oq1k7sS1Gr3BDAYAgTiYPB7qbYk33S11yCQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1709724721; x=1709811121; bh=Z4qG4epX/Un2UO8UTnbvWv353f1a U5hgiM1PqZ1IozA=; b=Jahr4AQ3BQ6JbUAiFLjhF0v6qF1lQt8/PtGEdWDti+Ub i7Pd8wPO7mIV0xgiXK1lo513xFMJJ0FfD8JqnysI1WaWCEamAC5CzxCh5JPgOCPg 2zUyLTA1l8vH2Hay+Fz+zpBWKIvmoKW4VVsDvwhSHWdl8yOYFxh5u8Dw+eDPgjis BiEqG1MHDS9m+r8DUwAmIyMkFHZq7wHxNEX316B/XtGccPQ6hBo1nigR4xiYBS5A XDkjNQVVIxlqSRx3oLb4C9UkxtHFb1d1GCWvTnaivI6DgcrD2rW2NWghASW9m8Mv /ChXbkXfJyWS2+J7hDkcyZR+Ar1idh4xkvC8Sx573w== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugddviecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecuuhhsvghruchinhculhhinhhkucdliedtmdenucfjug hrpeffhffvuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhrihgtkhcu ufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvghrnhepie ekvddvkeeileekhfdvhfekheefteevtdejhfeffeeltedvgedvlefhheetgeejnecuffho mhgrihhnpehunhhithdrihhnpdgvgigrmhhplhgvrdgtohhmpdgvgigrmhhplhgvrdhorh hgpdhgohhougdqvgigrghmphhlvgdrtghomhdpvgigrghmphhlvgdrtghomhdrrghunecu vehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepphhssehpkh hsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 6 Mar 2024 06:32:00 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 5b24e2d2 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 6 Mar 2024 11:27:31 +0000 (UTC) Date: Wed, 6 Mar 2024 12:31:59 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 7/8] t1300: exercise both old- and new-style modes Message-ID: <4ad65cb8d6e325d8a14f8d81d0904f7819c76155.1709724089.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Convert t1300 so that tests exercise both the old and new-style way to specify the mode. Signed-off-by: Patrick Steinhardt --- t/t1300-config.sh | 721 ++++++++++++++++++++++++---------------------- 1 file changed, 375 insertions(+), 346 deletions(-) diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 2d1bc1e27e..705c17a1fb 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -11,6 +11,24 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME TEST_PASSES_SANITIZE_LEAK=true . ./test-lib.sh +for style in old new +do + +case "$style" in +old) + mode_prefix="--" + mode_get="" + mode_set="" + mode_set_all="" + ;; +new) + mode_prefix="" + mode_get="get" + mode_set="set" + mode_set_all="set-all" + ;; +esac + test_expect_success 'clear default config' ' rm -f .git/config ' @@ -20,7 +38,7 @@ cat > expect << EOF penguin = little blue EOF test_expect_success 'initial' ' - git config section.penguin "little blue" && + git config ${mode_set} section.penguin "little blue" && test_cmp expect .git/config ' @@ -30,7 +48,7 @@ cat > expect << EOF Movie = BadPhysics EOF test_expect_success 'mixed case' ' - git config Section.Movie BadPhysics && + git config ${mode_set} Section.Movie BadPhysics && test_cmp expect .git/config ' @@ -42,7 +60,7 @@ cat > expect << EOF WhatEver = Second EOF test_expect_success 'similar section' ' - git config Sections.WhatEver Second && + git config ${mode_set} Sections.WhatEver Second && test_cmp expect .git/config ' @@ -55,16 +73,16 @@ cat > expect << EOF WhatEver = Second EOF test_expect_success 'uppercase section' ' - git config SECTION.UPPERCASE true && + git config ${mode_set} SECTION.UPPERCASE true && test_cmp expect .git/config ' test_expect_success 'replace with non-match' ' - git config section.penguin kingpin !blue + git config ${mode_set_all} section.penguin kingpin !blue ' test_expect_success 'replace with non-match (actually matching)' ' - git config section.penguin "very blue" !kingpin + git config ${mode_set_all} section.penguin "very blue" !kingpin ' cat > expect << EOF @@ -102,7 +120,7 @@ test_missing_key () { local key="$1" && local title="$2" && test_expect_success "value for $title is not printed" ' - test_must_fail git config "$key" >out 2>err && + test_must_fail git config ${mode_get} "$key" >out 2>err && test_must_be_empty out && test_must_be_empty err ' @@ -125,7 +143,7 @@ foo = bar EOF test_expect_success 'unset with cont. lines' ' - git config --unset beta.baz + git config ${mode_prefix}unset beta.baz ' cat > expect <<\EOF @@ -152,7 +170,7 @@ EOF cp .git/config .git/config2 test_expect_success 'multiple unset' ' - git config --unset-all beta.haha + git config ${mode_prefix}unset-all beta.haha ' cat > expect << EOF @@ -178,7 +196,7 @@ test_expect_success '--replace-all missing value' ' rm .git/config2 test_expect_success '--replace-all' ' - git config --replace-all beta.haha gamma + git config ${mode_prefix}replace-all beta.haha gamma ' cat > expect << EOF @@ -220,7 +238,7 @@ noIndent= sillyValue ; 'nother silly comment nonewline = wow EOF test_expect_success 'really really mean test' ' - git config nextsection.nonewline wow && + git config ${mode_set} nextsection.nonewline wow && test_cmp expect .git/config ' @@ -238,7 +256,7 @@ noIndent= sillyValue ; 'nother silly comment nonewline = wow EOF test_expect_success 'unset' ' - git config --unset beta.haha && + git config ${mode_prefix}unset beta.haha && test_cmp expect .git/config ' @@ -258,15 +276,15 @@ test_expect_success 'multivar' ' ' test_expect_success 'non-match' ' - git config --get nextsection.nonewline !for + git config ${mode_prefix}get nextsection.nonewline !for ' test_expect_success 'non-match value' ' - test_cmp_config wow --get nextsection.nonewline !for + test_cmp_config wow ${mode_prefix}get nextsection.nonewline !for ' test_expect_success 'multi-valued get returns final one' ' - test_cmp_config "wow2 for me" --get nextsection.nonewline + test_cmp_config "wow2 for me" ${mode_prefix}get nextsection.nonewline ' test_expect_success 'multi-valued get-all returns all' ' @@ -274,7 +292,7 @@ test_expect_success 'multi-valued get-all returns all' ' wow wow2 for me EOF - git config --get-all nextsection.nonewline >actual && + git config ${mode_prefix}get-all nextsection.nonewline >actual && test_cmp expect actual ' @@ -289,16 +307,16 @@ noIndent= sillyValue ; 'nother silly comment NoNewLine = wow2 for me EOF test_expect_success 'multivar replace' ' - git config nextsection.nonewline "wow3" "wow$" && + git config ${mode_set_all} nextsection.nonewline "wow3" "wow$" && test_cmp expect .git/config ' test_expect_success 'ambiguous unset' ' - test_must_fail git config --unset nextsection.nonewline + test_must_fail git config ${mode_prefix}unset nextsection.nonewline ' test_expect_success 'invalid unset' ' - test_must_fail git config --unset somesection.nonewline + test_must_fail git config ${mode_prefix}unset somesection.nonewline ' cat > expect << EOF @@ -312,16 +330,16 @@ noIndent= sillyValue ; 'nother silly comment EOF test_expect_success 'multivar unset' ' - git config --unset nextsection.nonewline "wow3$" && + git config ${mode_prefix}unset nextsection.nonewline "wow3$" && test_cmp expect .git/config ' -test_expect_success 'invalid key' 'test_must_fail git config inval.2key blabla' +test_expect_success 'invalid key' 'test_must_fail git config ${mode_set} inval.2key blabla' -test_expect_success 'correct key' 'git config 123456.a123 987' +test_expect_success 'correct key' 'git config ${mode_set} 123456.a123 987' test_expect_success 'hierarchical section' ' - git config Version.1.2.3eX.Alpha beta + git config ${mode_set} Version.1.2.3eX.Alpha beta ' cat > expect << EOF @@ -350,11 +368,11 @@ version.1.2.3eX.alpha=beta EOF test_expect_success 'working --list' ' - git config --list > output && + git config ${mode_prefix}list > output && test_cmp expect output ' test_expect_success '--list without repo produces empty output' ' - git --git-dir=nonexistent config --list >output && + git --git-dir=nonexistent config ${mode_prefix}list >output && test_must_be_empty output ' @@ -366,7 +384,7 @@ version.1.2.3eX.alpha EOF test_expect_success '--name-only --list' ' - git config --name-only --list >output && + git config ${mode_prefix}list --name-only >output && test_cmp expect output ' @@ -376,7 +394,7 @@ nextsection.nonewline wow2 for me EOF test_expect_success '--get-regexp' ' - git config --get-regexp in >output && + git config ${mode_prefix}get-regexp in >output && test_cmp expect output ' @@ -386,7 +404,7 @@ nextsection.nonewline EOF test_expect_success '--name-only --get-regexp' ' - git config --name-only --get-regexp in >output && + git config ${mode_prefix}get-regexp --name-only in >output && test_cmp expect output ' @@ -396,8 +414,8 @@ wow4 for you EOF test_expect_success '--add' ' - git config --add nextsection.nonewline "wow4 for you" && - git config --get-all nextsection.nonewline > output && + git config ${mode_prefix}add nextsection.nonewline "wow4 for you" && + git config ${mode_prefix}get-all nextsection.nonewline > output && test_cmp expect output ' @@ -409,45 +427,45 @@ cat > .git/config << EOF EOF test_expect_success 'get variable with no value' ' - git config --get novalue.variable ^$ + git config ${mode_prefix}get novalue.variable ^$ ' test_expect_success 'get variable with empty value' ' - git config --get emptyvalue.variable ^$ + git config ${mode_prefix}get emptyvalue.variable ^$ ' echo novalue.variable > expect test_expect_success 'get-regexp variable with no value' ' - git config --get-regexp novalue > output && + git config ${mode_prefix}get-regexp novalue > output && test_cmp expect output ' echo 'novalue.variable true' > expect test_expect_success 'get-regexp --bool variable with no value' ' - git config --bool --get-regexp novalue > output && + git config ${mode_prefix}get-regexp --bool novalue > output && test_cmp expect output ' echo 'emptyvalue.variable ' > expect test_expect_success 'get-regexp variable with empty value' ' - git config --get-regexp emptyvalue > output && + git config ${mode_prefix}get-regexp emptyvalue > output && test_cmp expect output ' echo true > expect test_expect_success 'get bool variable with no value' ' - git config --bool novalue.variable > output && + git config ${mode_get} --bool novalue.variable > output && test_cmp expect output ' echo false > expect test_expect_success 'get bool variable with empty value' ' - git config --bool emptyvalue.variable > output && + git config ${mode_get} --bool emptyvalue.variable > output && test_cmp expect output ' @@ -469,7 +487,7 @@ cat > expect << EOF EOF test_expect_success 'new section is partial match of another' ' - git config a.x y && + git config ${mode_set} a.x y && test_cmp expect .git/config ' @@ -484,14 +502,14 @@ cat > expect << EOF EOF test_expect_success 'new variable inserts into proper section' ' - git config b.x y && - git config a.b c && + git config ${mode_set} b.x y && + git config ${mode_set} a.b c && test_cmp expect .git/config ' test_expect_success 'alternative --file (non-existing file should fail)' ' - test_must_fail git config --file non-existing-config -l && - test_must_fail git config --file non-existing-config test.xyzzy + test_must_fail git config ${mode_prefix}list --file non-existing-config && + test_must_fail git config ${mode_get} --file non-existing-config test.xyzzy ' cat > other-config << EOF @@ -504,29 +522,30 @@ ein.bahn=strasse EOF test_expect_success 'alternative GIT_CONFIG' ' - GIT_CONFIG=other-config git config --list >output && + GIT_CONFIG=other-config git config ${mode_prefix}list >output && test_cmp expect output ' test_expect_success 'alternative GIT_CONFIG (--file)' ' - git config --file other-config --list >output && + git config ${mode_prefix}list --file other-config >output && test_cmp expect output ' test_expect_success 'alternative GIT_CONFIG (--file=-)' ' - git config --file - --list output && + git config ${mode_prefix}list --file - output && test_cmp expect output ' test_expect_success 'setting a value in stdin is an error' ' - test_must_fail git config --file - some.value foo + test_must_fail git config ${mode_set} --file - some.value foo ' test_expect_success 'editing stdin is an error' ' - test_must_fail git config --file - --edit + test_must_fail git config ${mode_prefix}edit --file - ' test_expect_success 'refer config from subdirectory' ' + test_when_finished "rm -r x" && mkdir x && test_cmp_config -C x strasse --file=../other-config --get ein.bahn ' @@ -539,7 +558,7 @@ cat > expect << EOF EOF test_expect_success '--set in alternative file' ' - git config --file=other-config anwohner.park ausweis && + git config ${mode_set} --file=other-config anwohner.park ausweis && test_cmp expect other-config ' @@ -555,7 +574,7 @@ weird EOF test_expect_success 'rename section' ' - git config --rename-section branch.eins branch.zwei + git config ${mode_prefix}rename-section branch.eins branch.zwei ' cat > expect << EOF @@ -574,7 +593,7 @@ test_expect_success 'rename succeeded' ' ' test_expect_success 'rename non-existing section' ' - test_must_fail git config --rename-section \ + test_must_fail git config ${mode_prefix}rename-section \ branch."world domination" branch.drei ' @@ -583,7 +602,7 @@ test_expect_success 'rename succeeded' ' ' test_expect_success 'rename another section' ' - git config --rename-section branch."1 234 blabl/a" branch.drei + git config ${mode_prefix}rename-section branch."1 234 blabl/a" branch.drei ' cat > expect << EOF @@ -606,7 +625,7 @@ cat >> .git/config << EOF EOF test_expect_success 'rename a section with a var on the same line' ' - git config --rename-section branch.vier branch.zwei + git config ${mode_prefix}rename-section branch.vier branch.zwei ' cat > expect << EOF @@ -627,11 +646,11 @@ test_expect_success 'rename succeeded' ' ' test_expect_success 'renaming empty section name is rejected' ' - test_must_fail git config --rename-section branch.zwei "" + test_must_fail git config ${mode_prefix}rename-section branch.zwei "" ' test_expect_success 'renaming to bogus section is rejected' ' - test_must_fail git config --rename-section branch.zwei "bogus name" + test_must_fail git config ${mode_prefix}rename-section branch.zwei "bogus name" ' test_expect_success 'renaming a section with a long line' ' @@ -640,7 +659,7 @@ test_expect_success 'renaming a section with a long line' ' printf " c = d %1024s [a] e = f\\n" " " && printf "[a] g = h\\n" } >y && - git config -f y --rename-section a xyz && + git config ${mode_prefix}rename-section -f y a xyz && test_must_fail git config -f y b.e ' @@ -650,7 +669,7 @@ test_expect_success 'renaming an embedded section with a long line' ' printf " c = d %1024s [a] [foo] e = f\\n" " " && printf "[a] g = h\\n" } >y && - git config -f y --rename-section a xyz && + git config ${mode_prefix}rename-section -f y a xyz && test_must_fail git config -f y foo.e ' @@ -660,7 +679,7 @@ test_expect_success 'renaming a section with an overly-long line' ' printf " c = d %525000s e" " " && printf "[a] g = h\\n" } >y && - test_must_fail git config -f y --rename-section a xyz 2>err && + test_must_fail git config ${mode_prefix}rename-section -f y a xyz 2>err && grep "refusing to work with overly long line in .y. on line 2" err ' @@ -669,7 +688,7 @@ cat >> .git/config << EOF EOF test_expect_success 'remove section' ' - git config --remove-section branch.zwei + git config ${mode_prefix}remove-section branch.zwei ' cat > expect << EOF @@ -693,20 +712,20 @@ EOF test_expect_success 'section ending' ' rm -f .git/config && - git config gitcvs.enabled true && - git config gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite && - git config gitcvs.dbname %Ggitcvs2.%a.%m.sqlite && + git config ${mode_set} gitcvs.enabled true && + git config ${mode_set} gitcvs.ext.dbname %Ggitcvs1.%a.%m.sqlite && + git config ${mode_set} gitcvs.dbname %Ggitcvs2.%a.%m.sqlite && test_cmp expect .git/config ' test_expect_success numbers ' - git config kilo.gram 1k && - git config mega.ton 1m && + git config ${mode_set} kilo.gram 1k && + git config ${mode_set} mega.ton 1m && echo 1024 >expect && echo 1048576 >>expect && - git config --int --get kilo.gram >actual && - git config --int --get mega.ton >>actual && + git config ${mode_prefix}get --int kilo.gram >actual && + git config ${mode_prefix}get --int mega.ton >>actual && test_cmp expect actual ' @@ -719,25 +738,25 @@ test_expect_success '--int is at least 64 bits' ' test_expect_success 'invalid unit' ' git config aninvalid.unit "1auto" && test_cmp_config 1auto aninvalid.unit && - test_must_fail git config --int --get aninvalid.unit 2>actual && + test_must_fail git config ${mode_prefix}get --int aninvalid.unit 2>actual && test_grep "bad numeric config value .1auto. for .aninvalid.unit. in file .git/config: invalid unit" actual ' test_expect_success 'invalid unit boolean' ' git config commit.gpgsign "1true" && test_cmp_config 1true commit.gpgsign && - test_must_fail git config --bool --get commit.gpgsign 2>actual && + test_must_fail git config ${mode_prefix}get --bool commit.gpgsign 2>actual && test_grep "bad boolean config value .1true. for .commit.gpgsign." actual ' test_expect_success 'line number is reported correctly' ' printf "[bool]\n\tvar\n" >invalid && - test_must_fail git config -f invalid --path bool.var 2>actual && + test_must_fail git config ${mode_get} -f invalid --path bool.var 2>actual && test_grep "line 2" actual ' test_expect_success 'invalid stdin config' ' - echo "[broken" | test_must_fail git config --list --file - >output 2>&1 && + echo "[broken" | test_must_fail git config ${mode_prefix}list --file - >output 2>&1 && test_grep "bad config line 1 in standard input" output ' @@ -765,19 +784,19 @@ test_expect_success bool ' rm -f result && for i in 1 2 3 4 do - git config --bool --get bool.true$i >>result && - git config --bool --get bool.false$i >>result || return 1 + git config ${mode_prefix}get --bool bool.true$i >>result && + git config ${mode_prefix}get --bool bool.false$i >>result || return 1 done && test_cmp expect result' test_expect_success 'invalid bool (--get)' ' git config bool.nobool foobar && - test_must_fail git config --bool --get bool.nobool' + test_must_fail git config ${mode_prefix}get --bool bool.nobool' test_expect_success 'invalid bool (set)' ' - test_must_fail git config --bool bool.nobool foobar' + test_must_fail git config ${mode_set} --bool bool.nobool foobar' cat > expect <<\EOF [bool] @@ -794,14 +813,14 @@ EOF test_expect_success 'set --bool' ' rm -f .git/config && - git config --bool bool.true1 01 && - git config --bool bool.true2 -1 && - git config --bool bool.true3 YeS && - git config --bool bool.true4 true && - git config --bool bool.false1 000 && - git config --bool bool.false2 "" && - git config --bool bool.false3 nO && - git config --bool bool.false4 FALSE && + git config ${mode_set} --bool bool.true1 01 && + git config ${mode_set} --bool bool.true2 -1 && + git config ${mode_set} --bool bool.true3 YeS && + git config ${mode_set} --bool bool.true4 true && + git config ${mode_set} --bool bool.false1 000 && + git config ${mode_set} --bool bool.false2 "" && + git config ${mode_set} --bool bool.false3 nO && + git config ${mode_set} --bool bool.false4 FALSE && test_cmp expect .git/config' cat > expect <<\EOF @@ -814,9 +833,9 @@ EOF test_expect_success 'set --int' ' rm -f .git/config && - git config --int int.val1 01 && - git config --int int.val2 -1 && - git config --int int.val3 5m && + git config ${mode_set} --int int.val1 01 && + git config ${mode_set} --int int.val2 -1 && + git config ${mode_set} --int int.val3 5m && test_cmp expect .git/config ' @@ -840,12 +859,12 @@ test_expect_success 'get --bool-or-int' ' -1 EOF { - git config --bool-or-int bool.true1 && - git config --bool-or-int bool.true2 && - git config --bool-or-int bool.false && - git config --bool-or-int int.int1 && - git config --bool-or-int int.int2 && - git config --bool-or-int int.int3 + git config ${mode_get} --bool-or-int bool.true1 && + git config ${mode_get} --bool-or-int bool.true2 && + git config ${mode_get} --bool-or-int bool.false && + git config ${mode_get} --bool-or-int int.int1 && + git config ${mode_get} --bool-or-int int.int2 && + git config ${mode_get} --bool-or-int int.int3 } >actual && test_cmp expect actual ' @@ -864,13 +883,13 @@ EOF test_expect_success 'set --bool-or-int' ' rm -f .git/config && - git config --bool-or-int bool.true1 true && - git config --bool-or-int bool.false1 false && - git config --bool-or-int bool.true2 yes && - git config --bool-or-int bool.false2 no && - git config --bool-or-int int.int1 0 && - git config --bool-or-int int.int2 1 && - git config --bool-or-int int.int3 -1 && + git config ${mode_set} --bool-or-int bool.true1 true && + git config ${mode_set} --bool-or-int bool.false1 false && + git config ${mode_set} --bool-or-int bool.true2 yes && + git config ${mode_set} --bool-or-int bool.false2 no && + git config ${mode_set} --bool-or-int int.int1 0 && + git config ${mode_set} --bool-or-int int.int2 1 && + git config ${mode_set} --bool-or-int int.int3 -1 && test_cmp expect .git/config ' @@ -883,9 +902,9 @@ EOF test_expect_success !MINGW 'set --path' ' rm -f .git/config && - git config --path path.home "~/" && - git config --path path.normal "/dev/null" && - git config --path path.trailingtilde "foo~" && + git config ${mode_set} --path path.home "~/" && + git config ${mode_set} --path path.normal "/dev/null" && + git config ${mode_set} --path path.trailingtilde "foo~" && test_cmp expect .git/config' if test_have_prereq !MINGW && test "${HOME+set}" @@ -900,9 +919,9 @@ foo~ EOF test_expect_success HOMEVAR 'get --path' ' - git config --get --path path.home > result && - git config --get --path path.normal >> result && - git config --get --path path.trailingtilde >> result && + git config ${mode_prefix}get --path path.home > result && + git config ${mode_prefix}get --path path.normal >> result && + git config ${mode_prefix}get --path path.trailingtilde >> result && test_cmp expect result ' @@ -914,10 +933,10 @@ EOF test_expect_success !MINGW 'get --path copes with unset $HOME' ' ( sane_unset HOME && - test_must_fail git config --get --path path.home \ + test_must_fail git config ${mode_prefix}get --path path.home \ >result 2>msg && - git config --get --path path.normal >>result && - git config --get --path path.trailingtilde >>result + git config ${mode_prefix}get --path path.normal >>result && + git config ${mode_prefix}get --path path.trailingtilde >>result ) && test_grep "[Ff]ailed to expand.*~/" msg && test_cmp expect result @@ -925,7 +944,7 @@ test_expect_success !MINGW 'get --path copes with unset $HOME' ' test_expect_success 'get --path barfs on boolean variable' ' echo "[path]bool" >.git/config && - test_must_fail git config --get --path path.bool + test_must_fail git config ${mode_prefix}get --path path.bool ' test_expect_success 'get --expiry-date' ' @@ -949,20 +968,20 @@ test_expect_success 'get --expiry-date' ' EOF : "work around heredoc parsing bug fixed in dash 0.5.7 (in ec2c84d)" && { - echo "$rel_out $(git config --expiry-date date.valid1)" && - git config --expiry-date date.valid2 && - git config --expiry-date date.valid3 && - git config --expiry-date date.valid4 && - git config --expiry-date date.valid5 + echo "$rel_out $(git config ${mode_get} --expiry-date date.valid1)" && + git config ${mode_get} --expiry-date date.valid2 && + git config ${mode_get} --expiry-date date.valid3 && + git config ${mode_get} --expiry-date date.valid4 && + git config ${mode_get} --expiry-date date.valid5 } >actual && test_cmp expect actual && - test_must_fail git config --expiry-date date.invalid1 + test_must_fail git config ${mode_get} --expiry-date date.invalid1 ' test_expect_success 'get --type=color' ' rm .git/config && git config foo.color "red" && - git config --get --type=color foo.color >actual.raw && + git config ${mode_prefix}get --type=color foo.color >actual.raw && test_decode_color actual && echo "" >expect && test_cmp expect actual @@ -975,17 +994,17 @@ EOF test_expect_success 'set --type=color' ' rm .git/config && - git config --type=color foo.color "red" && + git config ${mode_set} --type=color foo.color "red" && test_cmp expect .git/config ' test_expect_success 'get --type=color barfs on non-color' ' echo "[foo]bar=not-a-color" >.git/config && - test_must_fail git config --get --type=color foo.bar + test_must_fail git config ${mode_prefix}get --type=color foo.bar ' test_expect_success 'set --type=color barfs on non-color' ' - test_must_fail git config --type=color foo.color "not-a-color" 2>error && + test_must_fail git config ${mode_set} --type=color foo.color "not-a-color" 2>error && test_grep "cannot parse color" error ' @@ -998,18 +1017,18 @@ cat > expect << EOF EOF test_expect_success 'quoting' ' rm -f .git/config && - git config quote.leading " test" && - git config quote.ending "test " && - git config quote.semicolon "test;test" && - git config quote.hash "test#test" && + git config ${mode_set} quote.leading " test" && + git config ${mode_set} quote.ending "test " && + git config ${mode_set} quote.semicolon "test;test" && + git config ${mode_set} quote.hash "test#test" && test_cmp expect .git/config ' test_expect_success 'key with newline' ' - test_must_fail git config "key.with + test_must_fail git config ${mode_set} "key.with newline" 123' -test_expect_success 'value with newline' 'git config key.sub value.with\\\ +test_expect_success 'value with newline' 'git config ${mode_set} key.sub value.with\\\ newline' cat > .git/config <<\EOF @@ -1029,7 +1048,7 @@ section.quotecont=cont;inued EOF test_expect_success 'value continued on next line' ' - git config --list > result && + git config ${mode_prefix}list > result && test_cmp expect result ' @@ -1053,14 +1072,14 @@ Qsection.sub=section.val4 Qsection.sub=section.val5Q EOF test_expect_success '--null --list' ' - git config --null --list >result.raw && + git config ${mode_prefix}list --null >result.raw && nul_to_q result && echo >>result && test_cmp expect result ' test_expect_success '--null --get-regexp' ' - git config --null --get-regexp "val[0-9]" >result.raw && + git config ${mode_prefix}get-regexp --null "val[0-9]" >result.raw && nul_to_q result && echo >>result && test_cmp expect result @@ -1072,12 +1091,13 @@ test_expect_success 'inner whitespace kept verbatim' ' ' test_expect_success SYMLINKS 'symlinked configuration' ' + test_when_finished "rm myconfig" && ln -s notyet myconfig && - git config --file=myconfig test.frotz nitfol && + git config ${mode_set} --file=myconfig test.frotz nitfol && test -h myconfig && test -f notyet && - test "z$(git config --file=notyet test.frotz)" = znitfol && - git config --file=myconfig test.xyzzy rezrov && + test "z$(git config ${mode_get} --file=notyet test.frotz)" = znitfol && + git config ${mode_set} --file=myconfig test.xyzzy rezrov && test -h myconfig && test -f notyet && cat >expect <<-\EOF && @@ -1085,17 +1105,18 @@ test_expect_success SYMLINKS 'symlinked configuration' ' rezrov EOF { - git config --file=notyet test.frotz && - git config --file=notyet test.xyzzy + git config ${mode_get} --file=notyet test.frotz && + git config ${mode_get} --file=notyet test.xyzzy } >actual && test_cmp expect actual ' test_expect_success SYMLINKS 'symlink to nonexistent configuration' ' + test_when_finished "rm linktonada linktolinktonada" && ln -s doesnotexist linktonada && ln -s linktonada linktolinktonada && - test_must_fail git config --file=linktonada --list && - test_must_fail git config --file=linktolinktonada --list + test_must_fail git config ${mode_prefix}list --file=linktonada && + test_must_fail git config ${mode_prefix}list --file=linktolinktonada ' test_expect_success 'check split_cmdline return' ' @@ -1103,12 +1124,12 @@ test_expect_success 'check split_cmdline return' ' git init repo && ( cd repo && - git config alias.split-cmdline-fix "echo \"" && + git config ${mode_set} alias.split-cmdline-fix "echo \"" && test_must_fail git split-cmdline-fix && echo foo >foo && git add foo && git commit -m "initial commit" && - git config branch.main.mergeoptions "echo \"" && + git config ${mode_set} branch.main.mergeoptions "echo \"" && test_must_fail git merge main ) ' @@ -1122,10 +1143,10 @@ test_expect_success 'git -c "key=value" support' ' { git -c section.name=value config section.name && git -c foo.CamelCase=value config foo.camelcase && - git -c foo.flag config --bool foo.flag + git -c foo.flag config ${mode_get} --bool foo.flag } >actual && test_cmp expect actual && - test_must_fail git -c name=value config section.name + test_must_fail git -c name=value config ${mode_get} section.name ' # We just need a type-specifier here that cares about the @@ -1135,27 +1156,27 @@ test_expect_success 'git -c "key=value" support' ' # its semantics. test_expect_success 'git -c can represent empty string' ' echo >expect && - git -c foo.empty= config --path foo.empty >actual && + git -c foo.empty= config ${mode_get} --path foo.empty >actual && test_cmp expect actual ' test_expect_success 'key sanity-checking' ' - test_must_fail git config foo=bar && - test_must_fail git config foo=.bar && - test_must_fail git config foo.ba=r && - test_must_fail git config foo.1bar && - test_must_fail git config foo."ba + test_must_fail git config ${mode_get} foo=bar && + test_must_fail git config ${mode_get} foo=.bar && + test_must_fail git config ${mode_get} foo.ba=r && + test_must_fail git config ${mode_get} foo.1bar && + test_must_fail git config ${mode_get} foo."ba z".bar && - test_must_fail git config . false && - test_must_fail git config .foo false && - test_must_fail git config foo. false && - test_must_fail git config .foo. false && - git config foo.bar true && - git config foo."ba =z".bar false + test_must_fail git config ${mode_set} . false && + test_must_fail git config ${mode_set} .foo false && + test_must_fail git config ${mode_set} foo. false && + test_must_fail git config ${mode_set} .foo. false && + git config ${mode_set} foo.bar true && + git config ${mode_set} foo."ba =z".bar false ' test_expect_success 'git -c works with aliases of builtins' ' - git config alias.checkconfig "-c foo.check=bar config foo.check" && + git config ${mode_set} alias.checkconfig "-c foo.check=bar config foo.check" && echo bar >expect && git checkconfig >actual && test_cmp expect actual @@ -1167,7 +1188,7 @@ test_expect_success 'aliases can be CamelCased' ' ( cd repo && test_commit A && - git config alias.CamelCased "rev-parse HEAD" && + git config ${mode_set} alias.CamelCased "rev-parse HEAD" && git CamelCased >out && git rev-parse HEAD >expect && test_cmp expect out @@ -1176,7 +1197,7 @@ test_expect_success 'aliases can be CamelCased' ' test_expect_success 'git -c does not split values on equals' ' echo "value with = in it" >expect && - git -c section.foo="value with = in it" config section.foo >actual && + git -c section.foo="value with = in it" config ${mode_get} section.foo >actual && test_cmp expect actual ' @@ -1193,7 +1214,7 @@ test_expect_success 'git -c complains about empty key and value' ' ' test_expect_success 'multiple git -c appends config' ' - test_config alias.x "!git -c x.two=2 config --get-regexp ^x\.*" && + test_config alias.x "!git -c x.two=2 config ${mode_prefix}get-regexp ^x\.*" && cat >expect <<-\EOF && x.one 1 x.two 2 @@ -1210,14 +1231,14 @@ test_expect_success 'last one wins: two level vars' ' echo VAL >expect && - git -c sec.var=val -c sec.VAR=VAL config --get sec.var >actual && + git -c sec.var=val -c sec.VAR=VAL config ${mode_prefix}get sec.var >actual && test_cmp expect actual && - git -c SEC.var=val -c sec.var=VAL config --get sec.var >actual && + git -c SEC.var=val -c sec.var=VAL config ${mode_prefix}get sec.var >actual && test_cmp expect actual && - git -c sec.var=val -c sec.VAR=VAL config --get SEC.var >actual && + git -c sec.var=val -c sec.VAR=VAL config ${mode_prefix}get SEC.var >actual && test_cmp expect actual && - git -c SEC.var=val -c sec.var=VAL config --get sec.VAR >actual && + git -c SEC.var=val -c sec.var=VAL config ${mode_prefix}get sec.VAR >actual && test_cmp expect actual ' @@ -1228,9 +1249,9 @@ test_expect_success 'last one wins: three level vars' ' # case sensitive. echo val >expect && - git -c v.a.r=val -c v.A.r=VAL config --get v.a.r >actual && + git -c v.a.r=val -c v.A.r=VAL config ${mode_prefix}get v.a.r >actual && test_cmp expect actual && - git -c v.a.r=val -c v.A.r=VAL config --get V.a.R >actual && + git -c v.a.r=val -c v.A.r=VAL config ${mode_prefix}get V.a.R >actual && test_cmp expect actual && # v.a.r and V.a.R are the same variable, as the first @@ -1238,13 +1259,13 @@ test_expect_success 'last one wins: three level vars' ' # case insensitive. echo VAL >expect && - git -c v.a.r=val -c v.a.R=VAL config --get v.a.r >actual && + git -c v.a.r=val -c v.a.R=VAL config ${mode_prefix}get v.a.r >actual && test_cmp expect actual && - git -c v.a.r=val -c V.a.r=VAL config --get v.a.r >actual && + git -c v.a.r=val -c V.a.r=VAL config ${mode_prefix}get v.a.r >actual && test_cmp expect actual && - git -c v.a.r=val -c v.a.R=VAL config --get V.a.R >actual && + git -c v.a.r=val -c v.a.R=VAL config ${mode_prefix}get V.a.R >actual && test_cmp expect actual && - git -c v.a.r=val -c V.a.r=VAL config --get V.a.R >actual && + git -c v.a.r=val -c V.a.r=VAL config ${mode_prefix}get V.a.R >actual && test_cmp expect actual ' @@ -1259,7 +1280,7 @@ test_expect_success 'old-fashioned settings are case insensitive' ' [V.A] Qr = value2 EOF - git config -f testConfig_actual "v.a.r" value2 && + git config ${mode_set} -f testConfig_actual "v.a.r" value2 && test_cmp testConfig_expect testConfig_actual && cat >testConfig_actual <<-EOF && @@ -1270,7 +1291,7 @@ test_expect_success 'old-fashioned settings are case insensitive' ' [V.A] QR = value2 EOF - git config -f testConfig_actual "V.a.R" value2 && + git config ${mode_set} -f testConfig_actual "V.a.R" value2 && test_cmp testConfig_expect testConfig_actual && cat >testConfig_actual <<-EOF && @@ -1282,7 +1303,7 @@ test_expect_success 'old-fashioned settings are case insensitive' ' r = value1 Qr = value2 EOF - git config -f testConfig_actual "V.A.r" value2 && + git config ${mode_set} -f testConfig_actual "V.A.r" value2 && test_cmp testConfig_expect testConfig_actual && cat >testConfig_actual <<-EOF && @@ -1294,7 +1315,7 @@ test_expect_success 'old-fashioned settings are case insensitive' ' r = value1 Qr = value2 EOF - git config -f testConfig_actual "v.A.r" value2 && + git config ${mode_set} -f testConfig_actual "v.A.r" value2 && test_cmp testConfig_expect testConfig_actual ' @@ -1324,21 +1345,21 @@ test_expect_success 'setting different case sensitive subsections ' ' Qf = v2 EOF # exact match - git config -f testConfig_actual a.b.c v2 && + git config ${mode_set} -f testConfig_actual a.b.c v2 && # match section and subsection, key is cased differently. - git config -f testConfig_actual K.E.y v2 && + git config ${mode_set} -f testConfig_actual K.E.y v2 && # section and key are matched case insensitive, but subsection needs # to match; When writing out new values only the key is adjusted - git config -f testConfig_actual v.A.r v2 && + git config ${mode_set} -f testConfig_actual v.A.r v2 && # subsection is not matched: - git config -f testConfig_actual d.E.f v2 && + git config ${mode_set} -f testConfig_actual d.E.f v2 && test_cmp testConfig_expect testConfig_actual ' for VAR in a .a a. a.0b a."b c". a."b c".0d do test_expect_success "git -c $VAR=VAL rejects invalid '$VAR'" ' - test_must_fail git -c "$VAR=VAL" config -l + test_must_fail git -c "$VAR=VAL" config ${mode_prefix}list ' done @@ -1346,20 +1367,20 @@ for VAR in a.b a."b c".d do test_expect_success "git -c $VAR=VAL works with valid '$VAR'" ' echo VAL >expect && - git -c "$VAR=VAL" config --get "$VAR" >actual && + git -c "$VAR=VAL" config ${mode_prefix}get "$VAR" >actual && test_cmp expect actual ' done test_expect_success 'git -c is not confused by empty environment' ' - GIT_CONFIG_PARAMETERS="" git -c x.one=1 config --list + GIT_CONFIG_PARAMETERS="" git -c x.one=1 config ${mode_prefix}list ' test_expect_success 'GIT_CONFIG_PARAMETERS handles old-style entries' ' v="${SQ}key.one=foo${SQ}" && v="$v ${SQ}key.two=bar${SQ}" && v="$v ${SQ}key.ambiguous=section.whatever=value${SQ}" && - GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual && + GIT_CONFIG_PARAMETERS=$v git config ${mode_prefix}get-regexp "key.*" >actual && cat >expect <<-EOF && key.one foo key.two bar @@ -1372,7 +1393,7 @@ test_expect_success 'GIT_CONFIG_PARAMETERS handles new-style entries' ' v="${SQ}key.one${SQ}=${SQ}foo${SQ}" && v="$v ${SQ}key.two${SQ}=${SQ}bar${SQ}" && v="$v ${SQ}key.ambiguous=section.whatever${SQ}=${SQ}value${SQ}" && - GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual && + GIT_CONFIG_PARAMETERS=$v git config ${mode_prefix}get-regexp "key.*" >actual && cat >expect <<-EOF && key.one foo key.two bar @@ -1386,7 +1407,7 @@ test_expect_success 'old and new-style entries can mix' ' v="$v ${SQ}key.newone${SQ}=${SQ}newfoo${SQ}" && v="$v ${SQ}key.oldtwo=oldbar${SQ}" && v="$v ${SQ}key.newtwo${SQ}=${SQ}newbar${SQ}" && - GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual && + GIT_CONFIG_PARAMETERS=$v git config ${mode_prefix}get-regexp "key.*" >actual && cat >expect <<-EOF && key.oldone oldfoo key.newone newfoo @@ -1399,7 +1420,7 @@ test_expect_success 'old and new-style entries can mix' ' test_expect_success 'old and new bools with ambiguous subsection' ' v="${SQ}key.with=equals.oldbool${SQ}" && v="$v ${SQ}key.with=equals.newbool${SQ}=" && - GIT_CONFIG_PARAMETERS=$v git config --get-regexp "key.*" >actual && + GIT_CONFIG_PARAMETERS=$v git config ${mode_prefix}get-regexp "key.*" >actual && cat >expect <<-EOF && key.with equals.oldbool key.with=equals.newbool @@ -1413,7 +1434,7 @@ test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' ' env.two two EOF GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ} ${SQ}env.two=two${SQ}" \ - git config --get-regexp "env.*" >actual && + git config ${mode_prefix}get-regexp "env.*" >actual && test_cmp expect actual && cat >expect <<-EOF && @@ -1421,12 +1442,12 @@ test_expect_success 'detect bogus GIT_CONFIG_PARAMETERS' ' env.two two EOF GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ$SQ$SQ ${SQ}env.two=two${SQ}" \ - git config --get-regexp "env.*" >actual && + git config ${mode_prefix}get-regexp "env.*" >actual && test_cmp expect actual && test_must_fail env \ GIT_CONFIG_PARAMETERS="${SQ}env.one=one${SQ}\\$SQ ${SQ}env.two=two${SQ}" \ - git config --get-regexp "env.*" + git config ${mode_prefix}get-regexp "env.*" ' test_expect_success 'git --config-env=key=envvar support' ' @@ -1439,12 +1460,12 @@ test_expect_success 'git --config-env=key=envvar support' ' false EOF { - ENVVAR=value git --config-env=core.name=ENVVAR config core.name && - ENVVAR=value git --config-env core.name=ENVVAR config core.name && - ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config foo.camelcase && - ENVVAR=value git --config-env foo.CamelCase=ENVVAR config foo.camelcase && - ENVVAR= git --config-env=foo.flag=ENVVAR config --bool foo.flag && - ENVVAR= git --config-env foo.flag=ENVVAR config --bool foo.flag + ENVVAR=value git --config-env=core.name=ENVVAR config ${mode_get} core.name && + ENVVAR=value git --config-env core.name=ENVVAR config ${mode_get} core.name && + ENVVAR=value git --config-env=foo.CamelCase=ENVVAR config ${mode_get} foo.camelcase && + ENVVAR=value git --config-env foo.CamelCase=ENVVAR config ${mode_get} foo.camelcase && + ENVVAR= git --config-env=foo.flag=ENVVAR config ${mode_get} --bool foo.flag && + ENVVAR= git --config-env foo.flag=ENVVAR config ${mode_get} --bool foo.flag } >actual && test_cmp expect actual ' @@ -1452,17 +1473,17 @@ test_expect_success 'git --config-env=key=envvar support' ' test_expect_success 'git --config-env with missing value' ' test_must_fail env ENVVAR=value git --config-env 2>error && grep "no config key given for --config-env" error && - test_must_fail env ENVVAR=value git --config-env config core.name 2>error && + test_must_fail env ENVVAR=value git --config-env config ${mode_get} core.name 2>error && grep "invalid config format: config" error ' test_expect_success 'git --config-env fails with invalid parameters' ' - test_must_fail git --config-env=foo.flag config --bool foo.flag 2>error && + test_must_fail git --config-env=foo.flag config ${mode_get} --bool foo.flag 2>error && test_grep "invalid config format: foo.flag" error && - test_must_fail git --config-env=foo.flag= config --bool foo.flag 2>error && + test_must_fail git --config-env=foo.flag= config ${mode_get} --bool foo.flag 2>error && test_grep "missing environment variable name for configuration ${SQ}foo.flag${SQ}" error && sane_unset NONEXISTENT && - test_must_fail git --config-env=foo.flag=NONEXISTENT config --bool foo.flag 2>error && + test_must_fail git --config-env=foo.flag=NONEXISTENT config ${mode_get} --bool foo.flag 2>error && test_grep "missing environment variable ${SQ}NONEXISTENT${SQ} for configuration ${SQ}foo.flag${SQ}" error ' @@ -1474,7 +1495,7 @@ test_expect_success 'git -c and --config-env work together' ' ENVVAR=env-value git \ -c bar.cmd=cmd-value \ --config-env=bar.env=ENVVAR \ - config --get-regexp "^bar.*" >actual && + config ${mode_prefix}get-regexp "^bar.*" >actual && test_cmp expect actual ' @@ -1484,8 +1505,8 @@ test_expect_success 'git -c and --config-env override each other' ' cmd EOF { - ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config bar.bar && - ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config bar.bar + ENVVAR=env git -c bar.bar=cmd --config-env=bar.bar=ENVVAR config ${config_get} bar.bar && + ENVVAR=env git --config-env=bar.bar=ENVVAR -c bar.bar=cmd config ${config_get} bar.bar } >actual && test_cmp expect actual ' @@ -1494,7 +1515,7 @@ test_expect_success '--config-env handles keys with equals' ' echo value=with=equals >expect && ENVVAR=value=with=equals git \ --config-env=section.subsection=with=equals.key=ENVVAR \ - config section.subsection=with=equals.key >actual && + config ${config_get} section.subsection=with=equals.key >actual && test_cmp expect actual ' @@ -1502,7 +1523,7 @@ test_expect_success 'git config handles environment config pairs' ' GIT_CONFIG_COUNT=2 \ GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="foo" \ GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="bar" \ - git config --get-regexp "pair.*" >actual && + git config ${mode_prefix}get-regexp "pair.*" >actual && cat >expect <<-EOF && pair.one foo pair.two bar @@ -1520,7 +1541,7 @@ test_expect_success 'git config ignores pairs exceeding count' ' GIT_CONFIG_COUNT=1 \ GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \ GIT_CONFIG_KEY_1="pair.two" GIT_CONFIG_VALUE_1="value" \ - git config --get-regexp "pair.*" >actual 2>error && + git config ${mode_prefix}get-regexp "pair.*" >actual 2>error && cat >expect <<-EOF && pair.one value EOF @@ -1531,43 +1552,43 @@ test_expect_success 'git config ignores pairs exceeding count' ' test_expect_success 'git config ignores pairs with zero count' ' test_must_fail env \ GIT_CONFIG_COUNT=0 GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \ - git config pair.one 2>error && + git config ${config_get} pair.one 2>error && test_must_be_empty error ' test_expect_success 'git config ignores pairs with empty count' ' test_must_fail env \ GIT_CONFIG_COUNT= GIT_CONFIG_KEY_0="pair.one" GIT_CONFIG_VALUE_0="value" \ - git config pair.one 2>error && + git config ${config_get} pair.one 2>error && test_must_be_empty error ' test_expect_success 'git config fails with invalid count' ' - test_must_fail env GIT_CONFIG_COUNT=10a git config --list 2>error && + test_must_fail env GIT_CONFIG_COUNT=10a git config ${mode_prefix}list 2>error && test_grep "bogus count" error && - test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config --list 2>error && + test_must_fail env GIT_CONFIG_COUNT=9999999999999999 git config ${mode_prefix}list 2>error && test_grep "too many entries" error ' test_expect_success 'git config fails with missing config key' ' test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_VALUE_0="value" \ - git config --list 2>error && + git config ${mode_prefix}list 2>error && test_grep "missing config key" error ' test_expect_success 'git config fails with missing config value' ' test_must_fail env GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0="pair.one" \ - git config --list 2>error && + git config ${mode_prefix}list 2>error && test_grep "missing config value" error ' test_expect_success 'git config fails with invalid config pair key' ' test_must_fail env GIT_CONFIG_COUNT=1 \ GIT_CONFIG_KEY_0= GIT_CONFIG_VALUE_0=value \ - git config --list && + git config ${mode_prefix}list && test_must_fail env GIT_CONFIG_COUNT=1 \ GIT_CONFIG_KEY_0=missing-section GIT_CONFIG_VALUE_0=value \ - git config --list + git config ${mode_prefix}list ' test_expect_success 'environment overrides config file' ' @@ -1577,7 +1598,7 @@ test_expect_success 'environment overrides config file' ' one = value EOF GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=override \ - git config pair.one >actual && + git config ${mode_get} pair.one >actual && cat >expect <<-EOF && override EOF @@ -1587,7 +1608,7 @@ test_expect_success 'environment overrides config file' ' test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' ' GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \ GIT_CONFIG_PARAMETERS="${SQ}pair.one=override${SQ}" \ - git config pair.one >actual && + git config ${mode_get} pair.one >actual && cat >expect <<-EOF && override EOF @@ -1596,7 +1617,7 @@ test_expect_success 'GIT_CONFIG_PARAMETERS overrides environment config' ' test_expect_success 'command line overrides environment config' ' GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=pair.one GIT_CONFIG_VALUE_0=value \ - git -c pair.one=override config pair.one >actual && + git -c pair.one=override config ${mode_get} pair.one >actual && cat >expect <<-EOF && override EOF @@ -1606,8 +1627,8 @@ test_expect_success 'command line overrides environment config' ' test_expect_success 'git config --edit works' ' git config -f tmp test.value no && echo test.value=yes >expect && - GIT_EDITOR="echo [test]value=yes >" git config -f tmp --edit && - git config -f tmp --list >actual && + GIT_EDITOR="echo [test]value=yes >" git config ${mode_prefix}edit -f tmp && + git config ${mode_prefix}list -f tmp >actual && test_cmp expect actual ' @@ -1615,8 +1636,8 @@ test_expect_success 'git config --edit respects core.editor' ' git config -f tmp test.value no && echo test.value=yes >expect && test_config core.editor "echo [test]value=yes >" && - git config -f tmp --edit && - git config -f tmp --list >actual && + git config ${mode_prefix}edit -f tmp && + git config ${mode_prefix}list -f tmp >actual && test_cmp expect actual ' @@ -1627,7 +1648,7 @@ test_expect_success 'barf on syntax error' ' [section] key garbage EOF - test_must_fail git config --get section.key 2>error && + test_must_fail git config ${mode_prefix}get section.key 2>error && test_grep " line 3 " error ' @@ -1637,7 +1658,7 @@ test_expect_success 'barf on incomplete section header' ' [section key = value EOF - test_must_fail git config --get section.key 2>error && + test_must_fail git config ${mode_prefix}get section.key 2>error && test_grep " line 2 " error ' @@ -1647,7 +1668,7 @@ test_expect_success 'barf on incomplete string' ' [section] key = "value string EOF - test_must_fail git config --get section.key 2>error && + test_must_fail git config ${mode_prefix}get section.key 2>error && test_grep " line 3 " error ' @@ -1660,22 +1681,22 @@ test_expect_success 'urlmatch' ' cookieFile = /tmp/cookie.txt EOF - test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual && + test_expect_code 1 git config ${mode_prefix}get-urlmatch --bool doesnt.exist https://good.example.com >actual && test_must_be_empty actual && echo true >expect && - git config --bool --get-urlmatch http.SSLverify https://good.example.com >actual && + git config ${mode_prefix}get-urlmatch --bool http.SSLverify https://good.example.com >actual && test_cmp expect actual && echo false >expect && - git config --bool --get-urlmatch http.sslverify https://weak.example.com >actual && + git config ${mode_prefix}get-urlmatch --bool http.sslverify https://weak.example.com >actual && test_cmp expect actual && { echo http.cookiefile /tmp/cookie.txt && echo http.sslverify false } >expect && - git config --get-urlmatch HTTP https://weak.example.com >actual && + git config ${mode_prefix}get-urlmatch HTTP https://weak.example.com >actual && test_cmp expect actual ' @@ -1690,7 +1711,7 @@ test_expect_success 'urlmatch with --show-scope' ' local http.cookiefile /tmp/cookie.txt local http.sslverify false EOF - git config --get-urlmatch --show-scope HTTP https://weak.example.com >actual && + git config ${mode_prefix}get-urlmatch --show-scope HTTP https://weak.example.com >actual && test_cmp expect actual ' @@ -1721,47 +1742,47 @@ test_expect_success 'urlmatch favors more specific URLs' ' EOF echo http.cookiefile /tmp/root.txt >expect && - git config --get-urlmatch HTTP https://example.com >actual && + git config ${mode_prefix}get-urlmatch HTTP https://example.com >actual && test_cmp expect actual && echo http.cookiefile /tmp/subdirectory.txt >expect && - git config --get-urlmatch HTTP https://example.com/subdirectory >actual && + git config ${mode_prefix}get-urlmatch HTTP https://example.com/subdirectory >actual && test_cmp expect actual && echo http.cookiefile /tmp/subdirectory.txt >expect && - git config --get-urlmatch HTTP https://example.com/subdirectory/nested >actual && + git config ${mode_prefix}get-urlmatch HTTP https://example.com/subdirectory/nested >actual && test_cmp expect actual && echo http.cookiefile /tmp/user.txt >expect && - git config --get-urlmatch HTTP https://user@example.com/ >actual && + git config ${mode_prefix}get-urlmatch HTTP https://user@example.com/ >actual && test_cmp expect actual && echo http.cookiefile /tmp/subdirectory.txt >expect && - git config --get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual && + git config ${mode_prefix}get-urlmatch HTTP https://averylonguser@example.com/subdirectory >actual && test_cmp expect actual && echo http.cookiefile /tmp/preceding.txt >expect && - git config --get-urlmatch HTTP https://preceding.example.com >actual && + git config ${mode_prefix}get-urlmatch HTTP https://preceding.example.com >actual && test_cmp expect actual && echo http.cookiefile /tmp/wildcard.txt >expect && - git config --get-urlmatch HTTP https://wildcard.example.com >actual && + git config ${mode_prefix}get-urlmatch HTTP https://wildcard.example.com >actual && test_cmp expect actual && echo http.cookiefile /tmp/sub.txt >expect && - git config --get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual && + git config ${mode_prefix}get-urlmatch HTTP https://sub.example.com/wildcardwithsubdomain >actual && test_cmp expect actual && echo http.cookiefile /tmp/trailing.txt >expect && - git config --get-urlmatch HTTP https://trailing.example.com >actual && + git config ${mode_prefix}get-urlmatch HTTP https://trailing.example.com >actual && test_cmp expect actual && echo http.cookiefile /tmp/sub.txt >expect && - git config --get-urlmatch HTTP https://user@sub.example.com >actual && + git config ${mode_prefix}get-urlmatch HTTP https://user@sub.example.com >actual && test_cmp expect actual && echo http.cookiefile /tmp/multiwildcard.txt >expect && - git config --get-urlmatch HTTP https://wildcard.example.org >actual && + git config ${mode_prefix}get-urlmatch HTTP https://wildcard.example.org >actual && test_cmp expect actual ' @@ -1774,34 +1795,34 @@ test_expect_success 'urlmatch with wildcard' ' cookieFile = /tmp/cookie.txt EOF - test_expect_code 1 git config --bool --get-urlmatch doesnt.exist https://good.example.com >actual && + test_expect_code 1 git config ${mode_prefix}get-urlmatch --bool doesnt.exist https://good.example.com >actual && test_must_be_empty actual && echo true >expect && - git config --bool --get-urlmatch http.SSLverify https://example.com >actual && + git config ${mode_prefix}get-urlmatch --bool http.SSLverify https://example.com >actual && test_cmp expect actual && echo true >expect && - git config --bool --get-urlmatch http.SSLverify https://good-example.com >actual && + git config ${mode_prefix}get-urlmatch --bool http.SSLverify https://good-example.com >actual && test_cmp expect actual && echo true >expect && - git config --bool --get-urlmatch http.sslverify https://deep.nested.example.com >actual && + git config ${mode_prefix}get-urlmatch --bool http.sslverify https://deep.nested.example.com >actual && test_cmp expect actual && echo false >expect && - git config --bool --get-urlmatch http.sslverify https://good.example.com >actual && + git config ${mode_prefix}get-urlmatch --bool http.sslverify https://good.example.com >actual && test_cmp expect actual && { echo http.cookiefile /tmp/cookie.txt && echo http.sslverify false } >expect && - git config --get-urlmatch HTTP https://good.example.com >actual && + git config ${mode_prefix}get-urlmatch HTTP https://good.example.com >actual && test_cmp expect actual && echo http.sslverify >expect && - git config --get-urlmatch HTTP https://more.example.com.au >actual && + git config ${mode_prefix}get-urlmatch HTTP https://more.example.com.au >actual && test_cmp expect actual ' @@ -1828,7 +1849,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' # please be careful when you update the above variable EOF - git config --unset section.key && + git config ${mode_prefix}unset section.key && test_cmp expect .git/config && cat >.git/config <<-\EOF && @@ -1841,7 +1862,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' [next-section] EOF - git config --unset section.key && + git config ${mode_prefix}unset section.key && test_cmp expect .git/config && q_to_tab >.git/config <<-\EOF && @@ -1851,7 +1872,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' [two] key = true EOF - git config --unset two.key && + git config ${mode_prefix}unset two.key && ! grep two .git/config && q_to_tab >.git/config <<-\EOF && @@ -1861,7 +1882,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' [one] key = true EOF - git config --unset-all one.key && + git config ${mode_prefix}unset-all one.key && test_line_count = 0 .git/config && q_to_tab >.git/config <<-\EOF && @@ -1871,7 +1892,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' [two] Qkey = true EOF - git config --unset two.key && + git config ${mode_prefix}unset two.key && grep two .git/config && q_to_tab >.git/config <<-\EOF && @@ -1883,7 +1904,7 @@ test_expect_success '--unset last key removes section (except if commented)' ' [TWO "subsection"] [one] EOF - git config --unset two.subsection.key && + git config ${mode_prefix}unset two.subsection.key && test "not [two subsection]" = "$(git config one.key)" && test_line_count = 3 .git/config ' @@ -1895,7 +1916,7 @@ test_expect_success '--unset-all removes section if empty & uncommented' ' key = value2 EOF - git config --unset-all section.key && + git config ${mode_prefix}unset-all section.key && test_line_count = 0 .git/config ' @@ -1909,7 +1930,7 @@ test_expect_success 'adding a key into an empty section reuses header' ' Qkey = value EOF - git config section.key value && + git config ${mode_set} section.key value && test_cmp expect .git/config ' @@ -1918,7 +1939,7 @@ test_expect_success POSIXPERM,PERL 'preserves existing permissions' ' git config imap.pass Hunter2 && perl -e \ "die q(badset) if ((stat(q(.git/config)))[2] & 07777) != 0600" && - git config --rename-section imap pop && + git config ${mode_prefix}rename-section imap pop && perl -e \ "die q(badrename) if ((stat(q(.git/config)))[2] & 07777) != 0600" ' @@ -1967,7 +1988,7 @@ test_expect_success '--show-origin with --list' ' command line: user.cmdline=true EOF GIT_CONFIG_COUNT=1 GIT_CONFIG_KEY_0=user.environ GIT_CONFIG_VALUE_0=true\ - git -c user.cmdline=true config --list --show-origin >output && + git -c user.cmdline=true config ${mode_prefix}list --show-origin >output && test_cmp expect output ' @@ -1984,7 +2005,7 @@ test_expect_success '--show-origin with --list --null' ' includeQcommand line:Quser.cmdline trueQ EOF - git -c user.cmdline=true config --null --list --show-origin >output.raw && + git -c user.cmdline=true config ${mode_prefix}list --null --show-origin >output.raw && nul_to_q output && # The here-doc above adds a newline that the --null output would not # include. Add it here to make the two comparable. @@ -1998,7 +2019,7 @@ test_expect_success '--show-origin with single file' ' file:.git/config user.override=local file:.git/config include.path=../include/relative.include EOF - git config --local --list --show-origin >output && + git config ${mode_prefix}list --local --show-origin >output && test_cmp expect output ' @@ -2007,7 +2028,7 @@ test_expect_success '--show-origin with --get-regexp' ' file:$HOME/.gitconfig user.global true file:.git/config user.local true EOF - git config --show-origin --get-regexp "user\.[g|l].*" >output && + git config ${mode_prefix}get-regexp --show-origin "user\.[g|l].*" >output && test_cmp expect output ' @@ -2015,7 +2036,7 @@ test_expect_success '--show-origin getting a single key' ' cat >expect <<-\EOF && file:.git/config local EOF - git config --show-origin user.override >output && + git config ${mode_get} --show-origin user.override >output && test_cmp expect output ' @@ -2036,7 +2057,7 @@ test_expect_success !MINGW '--show-origin escape special file name characters' ' cat >expect <<-\EOF && file:"file\" (dq) and spaces.conf" user.custom=true EOF - git config --file "$WEIRDLY_NAMED_FILE" --show-origin --list >output && + git config ${mode_prefix}list --file "$WEIRDLY_NAMED_FILE" --show-origin >output && test_cmp expect output ' @@ -2044,7 +2065,7 @@ test_expect_success '--show-origin stdin' ' cat >expect <<-\EOF && standard input: user.custom=true EOF - git config --file - --show-origin --list <"$CUSTOM_CONFIG_FILE" >output && + git config ${mode_prefix}list --file - --show-origin <"$CUSTOM_CONFIG_FILE" >output && test_cmp expect output ' @@ -2057,7 +2078,7 @@ test_expect_success '--show-origin stdin with file include' ' file:$INCLUDE_DIR/stdin.include include EOF echo "[include]path=\"$INCLUDE_DIR\"/stdin.include" | - git config --show-origin --includes --file - user.stdin >output && + git config ${mode_get} --show-origin --includes --file - user.stdin >output && test_cmp expect output ' @@ -2071,7 +2092,7 @@ test_expect_success '--show-origin blob' ' cat >expect <<-EOF && blob:$blob user.custom=true EOF - git config --blob=$blob --show-origin --list >output && + git config ${mode_prefix}list --blob=$blob --show-origin >output && test_cmp expect output ) ' @@ -2087,13 +2108,13 @@ test_expect_success '--show-origin blob ref' ' cp "$CUSTOM_CONFIG_FILE" custom.conf && git add custom.conf && git commit -m "new config file" && - git config --blob=main:custom.conf --show-origin --list >output && + git config ${mode_prefix}list --blob=main:custom.conf --show-origin >output && test_cmp expect output ) ' test_expect_success '--show-origin with --default' ' - git config --show-origin --default foo some.key >actual && + git config ${mode_get} --show-origin --default foo some.key >actual && echo "command line: foo" >expect && test_cmp expect actual ' @@ -2113,13 +2134,14 @@ test_expect_success '--show-scope with --list' ' worktree user.worktree=true command user.cmdline=true EOF + test_when_finished "git worktree remove wt1" && git worktree add wt1 && # We need these to test for worktree scope, but outside of this # test, this is just noise test_config core.repositoryformatversion 1 && test_config extensions.worktreeConfig true && - git config --worktree user.worktree true && - git -c user.cmdline=true config --list --show-scope >output && + git config ${mode_get} --worktree user.worktree true && + git -c user.cmdline=true config ${mode_prefix}list --show-scope >output && test_cmp expect output ' @@ -2128,7 +2150,7 @@ test_expect_success !MINGW '--show-scope with --blob' ' cat >expect <<-EOF && command user.custom=true EOF - git config --blob=$blob --show-scope --list >output && + git config ${mode_prefix}list --blob=$blob --show-scope >output && test_cmp expect output ' @@ -2138,7 +2160,7 @@ test_expect_success '--show-scope with --local' ' local user.override=local local include.path=../include/relative.include EOF - git config --local --list --show-scope >output && + git config ${mode_prefix}list --local --show-scope >output && test_cmp expect output ' @@ -2146,7 +2168,7 @@ test_expect_success '--show-scope getting a single value' ' cat >expect <<-\EOF && local true EOF - git config --show-scope --get user.local >output && + git config ${mode_prefix}get --show-scope user.local >output && test_cmp expect output ' @@ -2162,12 +2184,12 @@ test_expect_success '--show-scope with --show-origin' ' local file:.git/../include/relative.include user.relative=include command command line: user.cmdline=true EOF - git -c user.cmdline=true config --list --show-origin --show-scope >output && + git -c user.cmdline=true config ${mode_prefix}list --show-origin --show-scope >output && test_cmp expect output ' test_expect_success '--show-scope with --default' ' - git config --show-scope --default foo some.key >actual && + git config ${mode_get} --show-scope --default foo some.key >actual && echo "command foo" >expect && test_cmp expect actual ' @@ -2203,7 +2225,7 @@ test_expect_success 'override global and system config' ' global home.config=true local local.config=true EOF - git config --show-scope --list >output && + git config ${mode_prefix}list --show-scope >output && test_cmp expect output && cat >expect <<-EOF && @@ -2212,20 +2234,20 @@ test_expect_success 'override global and system config' ' local local.config=true EOF GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=custom-system-config GIT_CONFIG_GLOBAL=custom-global-config \ - git config --show-scope --list >output && + git config ${mode_prefix}list --show-scope >output && test_cmp expect output && cat >expect <<-EOF && local local.config=true EOF GIT_CONFIG_NOSYSTEM=false GIT_CONFIG_SYSTEM=/dev/null GIT_CONFIG_GLOBAL=/dev/null \ - git config --show-scope --list >output && + git config ${mode_prefix}list --show-scope >output && test_cmp expect output ' test_expect_success 'override global and system config with missing file' ' - test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config --global --list && - test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config --system --list && + test_must_fail env GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=/dev/null git config ${mode_prefix}list --global && + test_must_fail env GIT_CONFIG_GLOBAL=/dev/null GIT_CONFIG_SYSTEM=does-not-exist git config ${mode_prefix}list --system && GIT_CONFIG_GLOBAL=does-not-exist GIT_CONFIG_SYSTEM=does-not-exist git version ' @@ -2251,10 +2273,10 @@ test_expect_success 'write to overridden global and system config' ' key = value EOF - GIT_CONFIG_GLOBAL=write-to-global git config --global config.key value && + GIT_CONFIG_GLOBAL=write-to-global git config ${mode_set} --global config.key value && test_cmp expect write-to-global && - GIT_CONFIG_SYSTEM=write-to-system git config --system config.key value && + GIT_CONFIG_SYSTEM=write-to-system git config ${mode_set} --system config.key value && test_cmp expect write-to-system ' @@ -2263,7 +2285,7 @@ do test_expect_success "$opt requires a repo" ' # we expect 128 to ensure that we do not simply # fail to find anything and return code "1" - test_expect_code 128 nongit git config $opt foo.bar + test_expect_code 128 nongit git config ${mode_get} $opt foo.bar ' done @@ -2287,17 +2309,17 @@ test_expect_success 'identical mixed --type specifiers are allowed' ' ' test_expect_success 'non-identical modern --type specifiers are not allowed' ' - test_must_fail git config --type=int --type=bool section.big 2>error && + test_must_fail git config ${mode_get} --type=int --type=bool section.big 2>error && test_grep "only one type at a time" error ' test_expect_success 'non-identical legacy --type specifiers are not allowed' ' - test_must_fail git config --int --bool section.big 2>error && + test_must_fail git config ${mode_get} --int --bool section.big 2>error && test_grep "only one type at a time" error ' test_expect_success 'non-identical mixed --type specifiers are not allowed' ' - test_must_fail git config --type=int --bool section.big 2>error && + test_must_fail git config ${mode_get} --type=int --bool section.big 2>error && test_grep "only one type at a time" error ' @@ -2314,12 +2336,12 @@ test_expect_success 'unset type specifiers may be reset to conflicting ones' ' ' test_expect_success '--type rejects unknown specifiers' ' - test_must_fail git config --type=nonsense section.foo 2>error && + test_must_fail git config ${mode_get} --type=nonsense section.foo 2>error && test_grep "unrecognized --type argument" error ' test_expect_success '--type=int requires at least one digit' ' - test_must_fail git config --type int --default m some.key >out 2>error && + test_must_fail git config ${mode_get} --type int --default m some.key >out 2>error && grep "bad numeric config value" error && test_must_be_empty out ' @@ -2341,18 +2363,18 @@ test_expect_success '--replace-all does not invent newlines' ' [abc] Qkey = b EOF - git config --replace-all abc.key b && + git config ${mode_prefix}replace-all abc.key b && test_cmp expect .git/config ' test_expect_success 'set all config with value-pattern' ' test_when_finished rm -f config initial && - git config --file=initial abc.key one && + git config ${mode_set} --file=initial abc.key one && # no match => add new entry cp initial config && - git config --file=config abc.key two a+ && - git config --file=config --list >actual && + git config ${mode_set_all} --file=config abc.key two a+ && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-\EOF && abc.key=one abc.key=two @@ -2360,12 +2382,12 @@ test_expect_success 'set all config with value-pattern' ' test_cmp expect actual && # multiple matches => failure - test_must_fail git config --file=config abc.key three o+ 2>err && + test_must_fail git config ${mode_set_all} --file=config abc.key three o+ 2>err && test_grep "has multiple values" err && # multiple values, no match => add - git config --file=config abc.key three a+ && - git config --file=config --list >actual && + git config ${mode_set_all} --file=config abc.key three a+ && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-\EOF && abc.key=one abc.key=two @@ -2374,8 +2396,8 @@ test_expect_success 'set all config with value-pattern' ' test_cmp expect actual && # single match => replace - git config --file=config abc.key four h+ && - git config --file=config --list >actual && + git config ${mode_set_all} --file=config abc.key four h+ && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-\EOF && abc.key=one abc.key=two @@ -2386,11 +2408,11 @@ test_expect_success 'set all config with value-pattern' ' test_expect_success '--replace-all and value-pattern' ' test_when_finished rm -f config && - git config --file=config --add abc.key one && - git config --file=config --add abc.key two && - git config --file=config --add abc.key three && - git config --file=config --replace-all abc.key four "o+" && - git config --file=config --list >actual && + git config ${mode_prefix}add --file=config abc.key one && + git config ${mode_prefix}add --file=config abc.key two && + git config ${mode_prefix}add --file=config abc.key three && + git config ${mode_prefix}replace-all --file=config abc.key four "o+" && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-\EOF && abc.key=four abc.key=three @@ -2403,33 +2425,33 @@ test_expect_success 'refuse --fixed-value for incompatible actions' ' git config --file=config dev.null bogus && # These modes do not allow --fixed-value at all - test_must_fail git config --file=config --fixed-value --add dev.null bogus && - test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && - test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus && - test_must_fail git config --file=config --fixed-value --rename-section dev null && - test_must_fail git config --file=config --fixed-value --remove-section dev && - test_must_fail git config --file=config --fixed-value --list && - test_must_fail git config --file=config --fixed-value --get-color dev.null && - test_must_fail git config --file=config --fixed-value --get-colorbool dev.null && + test_must_fail git config ${mode_prefix}add --file=config --fixed-value dev.null bogus && + test_must_fail git config ${mode_prefix}get-urlmatch --file=config --fixed-value dev.null bogus && + test_must_fail git config ${mode_prefix}get-urlmatch --file=config --fixed-value dev.null bogus && + test_must_fail git config ${mode_prefix}rename-section --file=config --fixed-value dev null && + test_must_fail git config ${mode_prefix}remove-section --file=config --fixed-value dev && + test_must_fail git config ${mode_prefix}list --file=config --fixed-value && + test_must_fail git config ${mode_prefix}get-color --file=config --fixed-value dev.null && + test_must_fail git config ${mode_prefix}get-colorbool --file=config --fixed-value dev.null && # These modes complain when --fixed-value has no value-pattern - test_must_fail git config --file=config --fixed-value dev.null bogus && - test_must_fail git config --file=config --fixed-value --replace-all dev.null bogus && - test_must_fail git config --file=config --fixed-value --get dev.null && - test_must_fail git config --file=config --fixed-value --get-all dev.null && - test_must_fail git config --file=config --fixed-value --get-regexp "dev.*" && - test_must_fail git config --file=config --fixed-value --unset dev.null && - test_must_fail git config --file=config --fixed-value --unset-all dev.null + test_must_fail git config ${mode_set} --file=config --fixed-value dev.null bogus && + test_must_fail git config ${mode_prefix}replace-all --file=config --fixed-value dev.null bogus && + test_must_fail git config ${mode_prefix}get --file=config --fixed-value dev.null && + test_must_fail git config ${mode_prefix}get-all --file=config --fixed-value dev.null && + test_must_fail git config ${mode_prefix}get-regexp --file=config --fixed-value "dev.*" && + test_must_fail git config ${mode_prefix}unset --file=config --fixed-value dev.null && + test_must_fail git config ${mode_prefix}unset-all --file=config --fixed-value dev.null ' test_expect_success '--fixed-value uses exact string matching' ' test_when_finished rm -f config initial && META="a+b*c?d[e]f.g" && - git config --file=initial fixed.test "$META" && + git config ${mode_set} --file=initial fixed.test "$META" && cp initial config && - git config --file=config fixed.test bogus "$META" && - git config --file=config --list >actual && + git config ${mode_set_all} --file=config fixed.test bogus "$META" && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-EOF && fixed.test=$META fixed.test=bogus @@ -2437,34 +2459,34 @@ test_expect_success '--fixed-value uses exact string matching' ' test_cmp expect actual && cp initial config && - git config --file=config --fixed-value fixed.test bogus "$META" && - git config --file=config --list >actual && + git config ${mode_set_all} --file=config --fixed-value fixed.test bogus "$META" && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-\EOF && fixed.test=bogus EOF test_cmp expect actual && cp initial config && - test_must_fail git config --file=config --unset fixed.test "$META" && - git config --file=config --fixed-value --unset fixed.test "$META" && - test_must_fail git config --file=config fixed.test && + test_must_fail git config ${mode_prefix}unset --file=config fixed.test "$META" && + git config ${mode_prefix}unset --file=config --fixed-value fixed.test "$META" && + test_must_fail git config ${mode_get} --file=config fixed.test && cp initial config && - test_must_fail git config --file=config --unset-all fixed.test "$META" && - git config --file=config --fixed-value --unset-all fixed.test "$META" && - test_must_fail git config --file=config fixed.test && + test_must_fail git config ${mode_prefix}unset-all --file=config fixed.test "$META" && + git config ${mode_prefix}unset-all --file=config --fixed-value fixed.test "$META" && + test_must_fail git config ${mode_get} --file=config fixed.test && cp initial config && - git config --file=config --replace-all fixed.test bogus "$META" && - git config --file=config --list >actual && + git config ${mode_prefix}replace-all --file=config fixed.test bogus "$META" && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-EOF && fixed.test=$META fixed.test=bogus EOF test_cmp expect actual && - git config --file=config --fixed-value --replace-all fixed.test bogus "$META" && - git config --file=config --list >actual && + git config ${mode_prefix}replace-all --file=config --fixed-value fixed.test bogus "$META" && + git config ${mode_prefix}list --file=config >actual && cat >expect <<-EOF && fixed.test=bogus fixed.test=bogus @@ -2475,23 +2497,23 @@ test_expect_success '--fixed-value uses exact string matching' ' test_expect_success '--get and --get-all with --fixed-value' ' test_when_finished rm -f config && META="a+b*c?d[e]f.g" && - git config --file=config fixed.test bogus && - git config --file=config --add fixed.test "$META" && + git config ${mode_set} --file=config fixed.test bogus && + git config ${mode_prefix}add --file=config fixed.test "$META" && - git config --file=config --get fixed.test bogus && - test_must_fail git config --file=config --get fixed.test "$META" && - git config --file=config --get --fixed-value fixed.test "$META" && - test_must_fail git config --file=config --get --fixed-value fixed.test non-existent && + git config ${mode_prefix}get --file=config fixed.test bogus && + test_must_fail git config ${mode_prefix}get --file=config fixed.test "$META" && + git config ${mode_prefix}get --file=config --fixed-value fixed.test "$META" && + test_must_fail git config ${mode_prefix}get --file=config --fixed-value fixed.test non-existent && - git config --file=config --get-all fixed.test bogus && - test_must_fail git config --file=config --get-all fixed.test "$META" && - git config --file=config --get-all --fixed-value fixed.test "$META" && - test_must_fail git config --file=config --get-all --fixed-value fixed.test non-existent && + git config ${mode_prefix}get-all --file=config fixed.test bogus && + test_must_fail git config ${mode_prefix}get-all --file=config fixed.test "$META" && + git config ${mode_prefix}get-all --file=config --fixed-value fixed.test "$META" && + test_must_fail git config ${mode_prefix}get-all --file=config --fixed-value fixed.test non-existent && - git config --file=config --get-regexp fixed+ bogus && - test_must_fail git config --file=config --get-regexp fixed+ "$META" && - git config --file=config --get-regexp --fixed-value fixed+ "$META" && - test_must_fail git config --file=config --get-regexp --fixed-value fixed+ non-existent + git config ${mode_prefix}get-regexp --file=config fixed+ bogus && + test_must_fail git config ${mode_prefix}get-regexp --file=config fixed+ "$META" && + git config ${mode_prefix}get-regexp --file=config --fixed-value fixed+ "$META" && + test_must_fail git config ${mode_prefix}get-regexp --file=config --fixed-value fixed+ non-existent ' test_expect_success 'includeIf.hasconfig:remote.*.url' ' @@ -2516,10 +2538,10 @@ test_expect_success 'includeIf.hasconfig:remote.*.url' ' EOF echo this-is-included >expect-this && - git -C hasremoteurlTest config --get user.this >actual-this && + git -C hasremoteurlTest config ${mode_prefix}get user.this >actual-this && test_cmp expect-this actual-this && - test_must_fail git -C hasremoteurlTest config --get user.that + test_must_fail git -C hasremoteurlTest config ${mode_prefix}get user.that ' test_expect_success 'includeIf.hasconfig:remote.*.url respects last-config-wins' ' @@ -2546,13 +2568,13 @@ test_expect_success 'includeIf.hasconfig:remote.*.url respects last-config-wins' echo main-config >expect-main-config && echo included-config >expect-included-config && - git -C hasremoteurlTest config --get user.one >actual && + git -C hasremoteurlTest config ${mode_prefix}get user.one >actual && test_cmp expect-main-config actual && - git -C hasremoteurlTest config --get user.two >actual && + git -C hasremoteurlTest config ${mode_prefix}get user.two >actual && test_cmp expect-included-config actual && - git -C hasremoteurlTest config --get user.three >actual && + git -C hasremoteurlTest config ${mode_prefix}get user.three >actual && test_cmp expect-main-config actual ' @@ -2587,11 +2609,11 @@ test_expect_success 'includeIf.hasconfig:remote.*.url globs' ' path = "$(pwd)/no" EOF - git -C hasremoteurlTest config --get user.dss && - git -C hasremoteurlTest config --get user.dse && - git -C hasremoteurlTest config --get user.dsm && - git -C hasremoteurlTest config --get user.ssm && - test_must_fail git -C hasremoteurlTest config --get user.no + git -C hasremoteurlTest config ${mode_prefix}get user.dss && + git -C hasremoteurlTest config ${mode_prefix}get user.dse && + git -C hasremoteurlTest config ${mode_prefix}get user.dsm && + git -C hasremoteurlTest config ${mode_prefix}get user.ssm && + test_must_fail git -C hasremoteurlTest config ${mode_prefix}get user.no ' test_expect_success 'includeIf.hasconfig:remote.*.url forbids remote url in such included files' ' @@ -2625,4 +2647,11 @@ test_expect_success 'specifying multiple modes causes failure' ' test_cmp expect err ' +test_expect_success 'specifying mode and subcommand causes failure' ' + test_must_fail git config get --get 2>err && + grep "subcommand and action modes are incompatible" err +' + +done + test_done From patchwork Wed Mar 6 11:32:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 13583961 Received: from fout1-smtp.messagingengine.com (fout1-smtp.messagingengine.com [103.168.172.144]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 953FB7F7EF for ; Wed, 6 Mar 2024 11:32:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=103.168.172.144 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724728; cv=none; b=I92//YVFG3hDvHCTOlX63XnF0B0j2JT9KwfmsirZxygTAIWyomIeYmmF714ZjDoM8Rzr/rYOhgzd1/521Skr4x5Np56BsRCKPTS1VdsJYL4fsvakxdIG27moL2vOH/N9OkNvAVpSHD6L2IUfCU2r9uyZ1VRwZdlKWs0Nmg7LOaA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709724728; c=relaxed/simple; bh=E6SAwy5b9BdK8x75A5x71LQkkWb06GpwGLi8Dd+jHZw=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Zg94DMSp3cNPzq0CsJom7rUAEkZdnw4Zs4jgvzDa7vW1iuM2XOiWwsKi4SqQgwX4ZH68CaFOvXvW2oFBKtoKPPpPNpbLLJlx6JWw/yf1tqy0ZG0JGQ1ssg2b2ve6C1jpnqfb2SdCMK/ANFqXRh+Rh68YfwhU80vazUmdtQPEsDE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im; spf=pass smtp.mailfrom=pks.im; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b=jzsJHkqb; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=R2R6Cd7H; arc=none smtp.client-ip=103.168.172.144 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=pks.im Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=pks.im Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=pks.im header.i=@pks.im header.b="jzsJHkqb"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="R2R6Cd7H" Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailfout.nyi.internal (Postfix) with ESMTP id C1414138013B for ; Wed, 6 Mar 2024 06:32:05 -0500 (EST) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Wed, 06 Mar 2024 06:32:05 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc :content-type:content-type:date:date:from:from:in-reply-to :in-reply-to:message-id:mime-version:references:reply-to:subject :subject:to:to; s=fm1; t=1709724725; x=1709811125; bh=aDn9jp0ydO nITE61NItouuP4rIFJ0/kXfSafXSAV8Xg=; b=jzsJHkqbMiHZWIq29Gv+ebk79u ZCViboQibIeRxbaZhchCANn7ln3CakAMbtm+RvyO0qvlfMLm6EWlK+wsYABvz5pc fUtmGwgr/CWlTvsYs3rhb42oca6O6qaypLvZAz0nWpubXoEP/ScdMGcmuK0PcyQK Jdo6cVkqej3YNQMAt3c/zQvxGrBO/wV0za+RLWrEoQyj6pKAe0QoJVTg6ShlGKc/ jfQpwZWqrfwsHlvgAFWyQ8uparyAcnW+kp4sKlhIpQHxOW01aqvZGQjMd6BFO6Gz r0O8Z46FZamF4tWuvg5zAytP86KiuZ8TOCFc8O/yNcVqKhsuygiYkTehVNuA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:content-type:date:date :feedback-id:feedback-id:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:subject:subject:to :to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm1; t=1709724725; x=1709811125; bh=aDn9jp0ydOnITE61NItouuP4rIFJ 0/kXfSafXSAV8Xg=; b=R2R6Cd7HX8RjKbR+o66RfHE772bLTzSDgWQUGSlxTG14 OCmROZnyzdA5Uw0ELg6MMNWmVm6gWes0OTzhVWigD28rCnOPbcExLGr2Rq9F7zpj ClIDqboe5e0ui509e3DCVU3Iq6IZryQBzW3a76eggjvaiF2CgYnTGp+WEOtsUev4 sV6Hz2Z28TdcMI9T0VbWfx3gmBiMtV9Z2bGbBZ0KjkJh4jH/GWj2Wgy6PTVydikr j2MJesE50SCobHKQlM7pWquJxbYymM45PZ4f6hUPX7ThU1KbMnk+QfgG/sWpJoI0 LGNk9TladvbLe8gCT6n+iJTTsJCjsPK+caQcOkOkbg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledriedugddviecutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtderre dttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshesphhk shdrihhmqeenucggtffrrghtthgvrhhnpeduvdfgkeefheeggffhvddvhfefhfeutdevtd ejudfhudejffeiheelffelhfefveenucffohhmrghinhepughifhhfrdhnvgifpdhkvghr nhgvlhdrohhrghdpvgigrghmphhlvgdrtghomhenucevlhhushhtvghrufhiiigvpedtne curfgrrhgrmhepmhgrihhlfhhrohhmpehpshesphhkshdrihhm X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 6 Mar 2024 06:32:04 -0500 (EST) Received: by vm-mail (OpenSMTPD) with ESMTPSA id 85c6a48c (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 6 Mar 2024 11:27:35 +0000 (UTC) Date: Wed, 6 Mar 2024 12:32:03 +0100 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 8/8] Documentation/git-config: update to new-style syntax Message-ID: <5ff2bf4a2286431a3b3048e0ea04d6551006d0d7.1709724089.git.ps@pks.im> References: Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Update our documentation of git-config(1) to stop mentioning the old syntax while starting to mention the new syntax. Remove the help mismatch in t0450 so that we start to ensure that the manpage and builtin synopsis match. Note that there will still be lots of mentions of the old style syntax of git-config(1) throughout our documentation. This documentation will be updated over time. Signed-off-by: Patrick Steinhardt --- Documentation/git-config.txt | 204 ++++++++++++++++++----------------- builtin/config.c | 46 +++++--- t/t0450/txt-help-mismatches | 1 - 3 files changed, 137 insertions(+), 114 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index dff39093b5..edf67c85f7 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -9,21 +9,22 @@ git-config - Get and set repository or global options SYNOPSIS -------- [verse] -'git config' [] [--type=] [--fixed-value] [--show-origin] [--show-scope] [-z|--null] [ []] -'git config' [] [--type=] --add -'git config' [] [--type=] [--fixed-value] --replace-all [] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get [] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] --get-all [] -'git config' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [--name-only] --get-regexp [] -'git config' [] [--type=] [-z|--null] --get-urlmatch -'git config' [] [--fixed-value] --unset [] -'git config' [] [--fixed-value] --unset-all [] -'git config' [] --rename-section -'git config' [] --remove-section -'git config' [] [--show-origin] [--show-scope] [-z|--null] [--name-only] -l | --list -'git config' [] --get-color [] -'git config' [] --get-colorbool [] -'git config' [] -e | --edit +'git config list' [] [--show-origin] [--show-scope] [-z|--null] [--name-only] +'git config get' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [] +'git config get-all' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [] +'git config get-color' [] [] +'git config get-colorbool' [] [] +'git config get-regexp' [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [--name-only] [] +'git config get-urlmatch' [] [--type=] [-z|--null] +'git config add' [] [--type=] +'git config set' [] [--type=] +'git config set-all' [] [--type=] [--fixed-value] [] +'git config unset' [] [--fixed-value] [] +'git config unset-all' [] [--fixed-value] [] +'git config replace-all' [] [--type=] [--fixed-value] [] +'git config rename-section' [] +'git config remove-section' [] +'git config edit' [] DESCRIPTION ----------- @@ -74,35 +75,50 @@ On success, the command returns the exit code 0. A list of all available configuration variables can be obtained using the `git help --config` command. -[[OPTIONS]] -OPTIONS -------- - ---replace-all:: - Default behavior is to replace at most one line. This replaces - all lines matching the key (and optionally the `value-pattern`). +COMMANDS +-------- ---add:: - Adds a new line to the option without altering any existing - values. This is the same as providing '^$' as the `value-pattern` - in `--replace-all`. +list:: + List all variables set in config file, along with their values. ---get:: +get []:: Get the value for a given key (optionally filtered by a regex matching the value). Returns error code 1 if the key was not found and the last value if multiple key values were found. ---get-all:: +get-all []:: Like get, but returns all values for a multi-valued key. ---get-regexp:: - Like --get-all, but interprets the name as a regular expression and +get-color []:: + + Find the color configured for `name` (e.g. `color.diff.new`) and + output it as the ANSI color escape sequence to the standard + output. The optional `default` parameter is used instead, if + there is no color configured for `name`. ++ +`--type=color [--default=]` is preferred over `get-color` +(but note that `get-color` will omit the trailing newline printed by +`--type=color`). + +get-colorbool []:: + + Find the color setting for `` (e.g. `color.diff`) and output + "true" or "false". `` should be either "true" or + "false", and is taken into account when configuration says + "auto". If `` is missing, then checks the standard + output of the command itself, and exits with status 0 if color + is to be used, or exits with status 1 otherwise. + When the color setting for `name` is undefined, the command uses + `color.ui` as fallback. + +get-regex []:: + Like `get-all`, but interprets the name as a regular expression and writes out the key names. Regular expression matching is currently case-sensitive and done against a canonicalized version of the key in which section and variable names are lowercased, but subsection names are not. ---get-urlmatch :: +get-urlmatch :: When given a two-part as
., the value for
.. whose part matches the best to the given URL is returned (if no such key exists, the value for @@ -110,6 +126,43 @@ OPTIONS
as name, do so for all the keys in the section and list them. Returns error code 1 if no value is found. +add :: + Adds a new line to the option without altering any existing + values. This is the same as providing '^$' as the `value-pattern` + in `--replace-all`. + +set :: + Set the config key to the given value. Adds a new key to the + configuration in case it does not yet exist. This subcommand fails when + the key has multiple values. + +set-all []:: + Set all config keys to the given value. + +unset []:: + Remove the line matching the key from config file. + +unset-all []:: + Remove all lines matching the key from config file. + +replace-all []:: + Default behavior is to replace at most one line. This replaces + all lines matching the key (and optionally the `value-pattern`). + +remove-section :: + Remove the given section from the configuration file. + +rename-section :: + Rename the given section to a new name. + +edit:: + Opens an editor to modify the specified config file; either + `--system`, `--global`, or repository (default). + +[[OPTIONS]] +OPTIONS +------- + --global:: For writing options: write to global `~/.gitconfig` file rather than the repository `.git/config`, write to @@ -166,22 +219,6 @@ See also <>. section in linkgit:gitrevisions[7] for a more complete list of ways to spell blob names. ---remove-section:: - Remove the given section from the configuration file. - ---rename-section:: - Rename the given section to a new name. - ---unset:: - Remove the line matching the key from config file. - ---unset-all:: - Remove all lines matching the key from config file. - --l:: ---list:: - List all variables set in config file, along with their values. - --fixed-value:: When used with the `value-pattern` argument, treat `value-pattern` as an exact string instead of a regular expression. This will restrict @@ -236,8 +273,8 @@ Valid ``'s include: contain line breaks. --name-only:: - Output only the names of config variables for `--list` or - `--get-regexp`. + Output only the names of config variables for `list` or + `get-regexp`. --show-origin:: Augment the output of all queried config options with the @@ -250,33 +287,6 @@ Valid ``'s include: all queried config options with the scope of that value (worktree, local, global, system, command). ---get-colorbool []:: - - Find the color setting for `` (e.g. `color.diff`) and output - "true" or "false". `` should be either "true" or - "false", and is taken into account when configuration says - "auto". If `` is missing, then checks the standard - output of the command itself, and exits with status 0 if color - is to be used, or exits with status 1 otherwise. - When the color setting for `name` is undefined, the command uses - `color.ui` as fallback. - ---get-color []:: - - Find the color configured for `name` (e.g. `color.diff.new`) and - output it as the ANSI color escape sequence to the standard - output. The optional `default` parameter is used instead, if - there is no color configured for `name`. -+ -`--type=color [--default=]` is preferred over `--get-color` -(but note that `--get-color` will omit the trailing newline printed by -`--type=color`). - --e:: ---edit:: - Opens an editor to modify the specified config file; either - `--system`, `--global`, or repository (default). - --[no-]includes:: Respect `include.*` directives in config files when looking up values. Defaults to `off` when a specific file is given (e.g., @@ -284,13 +294,13 @@ Valid ``'s include: config files. --default :: - When using `--get`, and the requested variable is not found, behave as if + When using `get`, and the requested variable is not found, behave as if were the value assigned to the that variable. CONFIGURATION ------------- `pager.config` is only respected when listing configuration, i.e., when -using `--list` or any of the `--get-*` which may return multiple results. +using `list` or any of the `get-*` subcommands which may return multiple results. The default is to use a pager. [[FILES]] @@ -333,8 +343,8 @@ precedence over values read earlier. When multiple values are taken then all values of a key from all files will be used. By default, options are only written to the repository specific -configuration file. Note that this also affects options like `--replace-all` -and `--unset`. *'git config' will only ever change one file at a time*. +configuration file. Note that this also affects subcommands like `replace-all` +and `unset`. *'git config' will only ever change one file at a time*. You can limit which configuration sources are read from or written to by specifying the path of a file with the `--file` option, or by specifying a @@ -469,7 +479,7 @@ Given a .git/config like this: you can set the filemode to true with ------------ -% git config core.filemode true +% git config set core.filemode true ------------ The hypothetical proxy command entries actually have a postfix to discern @@ -477,7 +487,7 @@ what URL they apply to. Here is how to change the entry for kernel.org to "ssh". ------------ -% git config core.gitproxy '"ssh" for kernel.org' 'for kernel.org$' +% git config set core.gitproxy '"ssh" for kernel.org' 'for kernel.org$' ------------ This makes sure that only the key/value pair for kernel.org is replaced. @@ -485,7 +495,7 @@ This makes sure that only the key/value pair for kernel.org is replaced. To delete the entry for renames, do ------------ -% git config --unset diff.renames +% git config unset diff.renames ------------ If you want to delete an entry for a multivar (like core.gitproxy above), @@ -494,51 +504,51 @@ you have to provide a regex matching the value of exactly one line. To query the value for a given key, do ------------ -% git config --get core.filemode +% git config get core.filemode ------------ or ------------ -% git config core.filemode +% git config get core.filemode ------------ or, to query a multivar: ------------ -% git config --get core.gitproxy "for kernel.org$" +% git config get core.gitproxy "for kernel.org$" ------------ If you want to know all the values for a multivar, do: ------------ -% git config --get-all core.gitproxy +% git config get-all core.gitproxy ------------ If you like to live dangerously, you can replace *all* core.gitproxy by a new one with ------------ -% git config --replace-all core.gitproxy ssh +% git config replace-all core.gitproxy ssh ------------ However, if you really only want to replace the line for the default proxy, i.e. the one without a "for ..." postfix, do something like this: ------------ -% git config core.gitproxy ssh '! for ' +% git config get core.gitproxy ssh '! for ' ------------ To actually match only values with an exclamation mark, you have to ------------ -% git config section.key value '[!]' +% git config get section.key value '[!]' ------------ To add a new proxy, without altering any of the existing ones, use ------------ -% git config --add core.gitproxy '"proxy-command" for example.com' +% git config add core.gitproxy '"proxy-command" for example.com' ------------ An example to use customized color from the configuration in your @@ -546,8 +556,8 @@ script: ------------ #!/bin/sh -WS=$(git config --get-color color.diff.whitespace "blue reverse") -RESET=$(git config --get-color "" "reset") +WS=$(git config get-color color.diff.whitespace "blue reverse") +RESET=$(git config get-color "" "reset") echo "${WS}your whitespace color or blue reverse${RESET}" ------------ @@ -555,11 +565,11 @@ For URLs in `https://weak.example.com`, `http.sslVerify` is set to false, while it is set to `true` for all others: ------------ -% git config --type=bool --get-urlmatch http.sslverify https://good.example.com +% git config get-urlmatch --type=bool http.sslverify https://good.example.com true -% git config --type=bool --get-urlmatch http.sslverify https://weak.example.com +% git config get-urlmatch --type=bool http.sslverify https://weak.example.com false -% git config --get-urlmatch http https://weak.example.com +% git config get-urlmatch http https://weak.example.com http.cookieFile /tmp/cookie.txt http.sslverify false ------------ @@ -578,7 +588,7 @@ looks like key = value1 -------- -and running `git config section.Subsection.key value2` will result in +and running `git config add section.Subsection.key value2` will result in -------- [section.subsection] diff --git a/builtin/config.c b/builtin/config.c index 10fa933931..61a9ad3eaa 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -16,7 +16,22 @@ #include "worktree.h" static const char *const builtin_config_usage[] = { - N_("git config []"), + N_("git config list [] [--show-origin] [--show-scope] [-z|--null] [--name-only]"), + N_("git config get [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] []"), + N_("git config get-all [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] []"), + N_("git config get-color [] []"), + N_("git config get-colorbool [] []"), + N_("git config get-regexp [] [--type=] [--show-origin] [--show-scope] [-z|--null] [--fixed-value] [--name-only] []"), + N_("git config get-urlmatch [] [--type=] [-z|--null] "), + N_("git config add [] [--type=] "), + N_("git config set [] [--type=] "), + N_("git config set-all [] [--type=] [--fixed-value] []"), + N_("git config unset [] [--fixed-value] []"), + N_("git config unset-all [] [--fixed-value] []"), + N_("git config replace-all [] [--type=] [--fixed-value] []"), + N_("git config rename-section [] "), + N_("git config remove-section [] "), + N_("git config edit []"), NULL }; @@ -887,21 +902,20 @@ static struct option builtin_config_options[] = { OPT_BOOL(0, "worktree", &use_worktree_config, N_("use per-worktree config file")), OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")), OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")), - OPT_GROUP(N_("Action")), - OPT_CMDMODE(0, "get", &action, N_("get value: name [value-pattern]"), ACTION_GET), - OPT_CMDMODE(0, "get-all", &action, N_("get all values: key [value-pattern]"), ACTION_GET_ALL), - OPT_CMDMODE(0, "get-regexp", &action, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP), - OPT_CMDMODE(0, "get-urlmatch", &action, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH), - OPT_CMDMODE(0, "replace-all", &action, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL), - OPT_CMDMODE(0, "add", &action, N_("add a new variable: name value"), ACTION_ADD), - OPT_CMDMODE(0, "unset", &action, N_("remove a variable: name [value-pattern]"), ACTION_UNSET), - OPT_CMDMODE(0, "unset-all", &action, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL), - OPT_CMDMODE(0, "rename-section", &action, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION), - OPT_CMDMODE(0, "remove-section", &action, N_("remove a section: name"), ACTION_REMOVE_SECTION), - OPT_CMDMODE('l', "list", &action, N_("list all"), ACTION_LIST), - OPT_CMDMODE('e', "edit", &action, N_("open an editor"), ACTION_EDIT), - OPT_CMDMODE(0, "get-color", &action, N_("find the color configured: slot [default]"), ACTION_GET_COLOR), - OPT_CMDMODE(0, "get-colorbool", &action, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL), + OPT_CMDMODE_F(0, "get", &action, N_("get value: name [value-pattern]"), ACTION_GET, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F(0, "get-all", &action, N_("get all values: key [value-pattern]"), ACTION_GET_ALL, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F(0, "get-regexp", &action, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F(0, "get-urlmatch", &action, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F(0, "replace-all", &action, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F(0, "add", &action, N_("add a new variable: name value"), ACTION_ADD, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F(0, "unset", &action, N_("remove a variable: name [value-pattern]"), ACTION_UNSET, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F(0, "unset-all", &action, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F(0, "rename-section", &action, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F(0, "remove-section", &action, N_("remove a section: name"), ACTION_REMOVE_SECTION, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F('l', "list", &action, N_("list all"), ACTION_LIST, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F('e', "edit", &action, N_("open an editor"), ACTION_EDIT, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F(0, "get-color", &action, N_("find the color configured: slot [default]"), ACTION_GET_COLOR, PARSE_OPT_HIDDEN), + OPT_CMDMODE_F(0, "get-colorbool", &action, N_("find the color setting: slot [stdout-is-tty]"), ACTION_GET_COLORBOOL, PARSE_OPT_HIDDEN), OPT_GROUP(N_("Type")), OPT_CALLBACK('t', "type", &type, N_("type"), N_("value is given this type"), option_parse_type), OPT_CALLBACK_VALUE(0, "bool", &type, N_("value is \"true\" or \"false\""), TYPE_BOOL), diff --git a/t/t0450/txt-help-mismatches b/t/t0450/txt-help-mismatches index a0777acd66..28003f18c9 100644 --- a/t/t0450/txt-help-mismatches +++ b/t/t0450/txt-help-mismatches @@ -10,7 +10,6 @@ checkout checkout-index clone column -config credential credential-cache credential-store