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@xxxxxx> --- 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' [<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 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 [<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(), }; 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 && -- 2.45.0
Attachment:
signature.asc
Description: PGP signature