From patchwork Fri May 3 09:57: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: 13652608 Received: from wfout6-smtp.messagingengine.com (wfout6-smtp.messagingengine.com [64.147.123.149]) (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 6E66814F133 for ; Fri, 3 May 2024 09:57:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=64.147.123.149 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714730265; cv=none; b=kFHApMpzCj746NlDjdvXdjFbul2C+bxQJEoHOFit8R2+H1JtCYnyjK5TFH3W5yMmPFx/qcRqDX2LFeRqI9Xq4xznX+P7SrxrtM/izAhHmdP4OVbeca3PCbm6zvf8MLUlvzK6HEVX5PRj6EPzTLt4t29iDY8yXvgHOYLlGyOnqms= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1714730265; c=relaxed/simple; bh=rUzRwwiXVj8BeLZ0Sw2EMCfT/S3ckOYvPzSwFTEXlt8=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=hZAxwx15ndSarI5eOmwKd5+tsY6JCtqvviKfUSwVO4s4aelonX5gt/M8K6E4W7CDqenGKCfvFN+wkOzlRAlZzU9IwaYa12aQdOTFLFeD9pHcIny0bA52QwiWc3+IebSkAl1jpVSU8QKJ4J8kON8zii6tGvDlgwKnAiOcZ4rjAa0= 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=C2uYRVp8; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b=fhRRlmyT; arc=none smtp.client-ip=64.147.123.149 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="C2uYRVp8"; dkim=pass (2048-bit key) header.d=messagingengine.com header.i=@messagingengine.com header.b="fhRRlmyT" Received: from compute2.internal (compute2.nyi.internal [10.202.2.46]) by mailfout.west.internal (Postfix) with ESMTP id 57AEF1C000CF; Fri, 3 May 2024 05:57:43 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute2.internal (MEProxy); Fri, 03 May 2024 05:57:43 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=cc: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=fm3; t=1714730262; x=1714816662; bh=zE3AhEL0TE uuTeqwRHR0dzgSEjXLngpVS+bqLESoYMY=; b=C2uYRVp8+ovZ8MIDZ+immZH6G8 7wQ0bO+B2GblDUfYNkvCgUNabzp47Ptg4deyQL4dOaifbnvMI38EDxNCaFVZ259u +/7p7XJ6Az/gCevGXpnmq1XWqfS6m5l4tgj1rN8HZ8sR/QAqWxUF7DdDguCGyTA4 HhUOZB73dqgEUZ6WqYu7Qcvj2y+DYDopS/sh7Lf+6DEjwAU47hMr+urfsc1D/dUB 99djo6XCUaPpNAZh0NByBfyn7qJcPdXcWQW2SLRXxxPBH4YdIV5BEud2PGzR+hSK LG/nk/uBXVRP+6J+ISxUiyn7D8FHsnd6+VA/e17LKUUtVtZIQCoF0fWFMTVg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc: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= fm3; t=1714730262; x=1714816662; bh=zE3AhEL0TEuuTeqwRHR0dzgSEjXL ngpVS+bqLESoYMY=; b=fhRRlmyTAzIbRtBaBSUYXoJaCJZHCBQVF9c66zb6O/vZ Q5fPZ3SDfwFJDOHlXApSEtsBlYwOxZ6yDOQkb+zb/NO+CAmXWdkoqkVkkHDvhZWU x7bpmFs0IjZu3f6EZmZhhGn0lrWmkJOkSgqHlPhNsQPpSY+0x1Y9vCXaGAfR/TZ9 Gt2pwJ9IDq0S9rIS/2upt5PHRYiFvVZZqGZFJ0zd+dttUkhYs1L9FaDilJJU8pr1 1Mne9i1o3GYKdmTWrKIjNvCc/LKy+vTI42Jx029qZlNR1tUuVY6F+FCTB0ziIXSS /IBCThh7v0Hcd5FlOl3q4VezOIJ6fE+zZKjMy1Whjw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrvddvtddgvddtucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepfffhvfevuffkfhggtggujgesghdtreertddtvdenucfhrhhomheprfgrthhr ihgtkhcuufhtvghinhhhrghrughtuceophhssehpkhhsrdhimheqnecuggftrfgrthhtvg hrnhepueektdevtdffveeljeetgfehheeigeekleduvdeffeeghefgledttdehjeelffet necuvehluhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepphhsse hpkhhsrdhimh X-ME-Proxy: Feedback-ID: i197146af:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 3 May 2024 05:57:41 -0400 (EDT) Received: by localhost (OpenSMTPD) with ESMTPSA id 207d5656 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO); Fri, 3 May 2024 09:57:13 +0000 (UTC) Date: Fri, 3 May 2024 11:57:38 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Cc: Kristoffer Haugsbakk , Taylor Blau , =?iso-8859-1?q?Jean-No=EBl?= AVILA , Eric Sunshine , Junio C Hamano Subject: [PATCH v4 12/14] builtin/config: introduce "remove-section" subcommand 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: Introduce a new "remove-section" subcommand to git-config(1). Please refer to preceding commits regarding the motivation behind this change. Signed-off-by: Patrick Steinhardt --- Documentation/git-config.txt | 11 +++++++---- builtin/config.c | 32 ++++++++++++++++++++++++++++++++ t/t1300-config.sh | 4 ++-- 3 files changed, 41 insertions(+), 6 deletions(-) diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt index ede86ad085..ef46520c15 100644 --- a/Documentation/git-config.txt +++ b/Documentation/git-config.txt @@ -14,7 +14,7 @@ SYNOPSIS 'git config set' [] [--type=] [--all] [--value=] [--fixed-value] 'git config unset' [] [--all] [--value=] [--fixed-value] 'git config rename-section' [] -'git config' [] --remove-section +'git config remove-section' [] 'git config' [] --get-colorbool [] 'git config' [] -e | --edit @@ -95,6 +95,9 @@ unset:: rename-section:: Rename the given section to a new name. +remove-section:: + Remove the given section from the configuration file. + [[OPTIONS]] OPTIONS ------- @@ -192,9 +195,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. - --fixed-value:: When used with the `value-pattern` argument, treat `value-pattern` as an exact string instead of a regular expression. This will restrict @@ -333,6 +333,9 @@ recommended to migrate to the new syntax. --rename-section :: Replaced by `git config rename-section `. +--remove-section :: + Replaced by `git config remove-section `. + CONFIGURATION ------------- `pager.config` is only respected when listing configuration, i.e., when diff --git a/builtin/config.c b/builtin/config.c index a60dca9b2b..cea03fb517 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -21,6 +21,7 @@ static const char *const builtin_config_usage[] = { N_("git config set [] [--type=] [--all] [--value=] [--fixed-value] "), N_("git config unset [] [--all] [--value=] [--fixed-value] "), N_("git config rename-section [] "), + N_("git config remove-section [] "), NULL }; @@ -49,6 +50,11 @@ static const char *const builtin_config_rename_section_usage[] = { NULL }; +static const char *const builtin_config_remove_section_usage[] = { + N_("git config remove-section [] "), + NULL +}; + static char *key; static regex_t *key_regexp; static const char *value_pattern; @@ -980,12 +986,38 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr return 0; } +static int cmd_config_remove_section(int argc, const char **argv, const char *prefix) +{ + struct option opts[] = { + CONFIG_LOCATION_OPTIONS, + OPT_END(), + }; + int ret; + + argc = parse_options(argc, argv, prefix, opts, builtin_config_remove_section_usage, + PARSE_OPT_STOP_AT_NON_OPTION); + check_write(); + check_argc(argc, 1, 1); + + handle_config_location(prefix); + + 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]); + + return 0; +} + static struct option builtin_subcommand_options[] = { OPT_SUBCOMMAND("list", &subcommand, cmd_config_list), OPT_SUBCOMMAND("get", &subcommand, cmd_config_get), OPT_SUBCOMMAND("set", &subcommand, cmd_config_set), OPT_SUBCOMMAND("unset", &subcommand, cmd_config_unset), OPT_SUBCOMMAND("rename-section", &subcommand, cmd_config_rename_section), + OPT_SUBCOMMAND("remove-section", &subcommand, cmd_config_remove_section), OPT_END(), }; diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 5d7b08fa4c..9d71ec1260 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -813,7 +813,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 @@ -2602,7 +2602,7 @@ test_expect_success 'refuse --fixed-value for incompatible actions' ' 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 ${mode_prefix}rename-section --file=config --fixed-value dev null && - test_must_fail git config --file=config --fixed-value --remove-section dev && + 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 --file=config --fixed-value --get-color dev.null && test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&