]> git.ipfire.org Git - thirdparty/git.git/commitdiff
builtin/config: introduce "remove-section" subcommand
authorPatrick Steinhardt <ps@pks.im>
Mon, 6 May 2024 08:56:47 +0000 (10:56 +0200)
committerJunio C Hamano <gitster@pobox.com>
Mon, 6 May 2024 18:50:10 +0000 (11:50 -0700)
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 <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-config.txt
builtin/config.c
t/t1300-config.sh

index ede86ad085a7f38fdad4fc794efc078bab0eaf11..ef46520c15fe64576b9bf1a62a159744c8585868 100644 (file)
@@ -14,7 +14,7 @@ SYNOPSIS
 'git config set' [<file-option>] [--type=<type>] [--all] [--value=<value>] [--fixed-value] <name> <value>
 'git config unset' [<file-option>] [--all] [--value=<value>] [--fixed-value] <name> <value>
 'git config rename-section' [<file-option>] <old-name> <new-name>
-'git config' [<file-option>] --remove-section <name>
+'git config remove-section' [<file-option>] <name>
 'git config' [<file-option>] --get-colorbool <name> [<stdout-is-tty>]
 'git config' [<file-option>] -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 <<FILES>>.
        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 <old-name> <new-name>::
        Replaced by `git config rename-section <old-name> <new-name>`.
 
+--remove-section <name>::
+       Replaced by `git config remove-section <name>`.
+
 CONFIGURATION
 -------------
 `pager.config` is only respected when listing configuration, i.e., when
index a60dca9b2bbd92647b8716f0737de6adbd2a754e..cea03fb51700346af606cf6d6470105d1debf52d 100644 (file)
@@ -21,6 +21,7 @@ static const char *const builtin_config_usage[] = {
        N_("git config set [<file-option>] [--type=<type>] [--all] [--value=<value>] [--fixed-value] <name> <value>"),
        N_("git config unset [<file-option>] [--all] [--value=<value>] [--fixed-value] <name> <value>"),
        N_("git config rename-section [<file-option>] <old-name> <new-name>"),
+       N_("git config remove-section [<file-option>] <name>"),
        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 [<file-option>] <name>"),
+       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(),
 };
 
index 5d7b08fa4cea72c1a93d99938c59d09bac644ca2..9d71ec1260b0fb81f035eb62fb9b6b9adbd24fd3 100755 (executable)
@@ -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 &&