Skip to content

Commit 15dad20

Browse files
pks-tgitster
authored andcommitted
builtin/config: introduce "remove-section" subcommand
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3418e96 commit 15dad20

File tree

3 files changed

+41
-6
lines changed

3 files changed

+41
-6
lines changed

Documentation/git-config.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ SYNOPSIS
1414
'git config set' [<file-option>] [--type=<type>] [--all] [--value=<value>] [--fixed-value] <name> <value>
1515
'git config unset' [<file-option>] [--all] [--value=<value>] [--fixed-value] <name> <value>
1616
'git config rename-section' [<file-option>] <old-name> <new-name>
17-
'git config' [<file-option>] --remove-section <name>
17+
'git config remove-section' [<file-option>] <name>
1818
'git config' [<file-option>] --get-colorbool <name> [<stdout-is-tty>]
1919
'git config' [<file-option>] -e | --edit
2020

@@ -95,6 +95,9 @@ unset::
9595
rename-section::
9696
Rename the given section to a new name.
9797

98+
remove-section::
99+
Remove the given section from the configuration file.
100+
98101
[[OPTIONS]]
99102
OPTIONS
100103
-------
@@ -192,9 +195,6 @@ See also <<FILES>>.
192195
section in linkgit:gitrevisions[7] for a more complete list of
193196
ways to spell blob names.
194197

195-
--remove-section::
196-
Remove the given section from the configuration file.
197-
198198
--fixed-value::
199199
When used with the `value-pattern` argument, treat `value-pattern` as
200200
an exact string instead of a regular expression. This will restrict
@@ -333,6 +333,9 @@ recommended to migrate to the new syntax.
333333
--rename-section <old-name> <new-name>::
334334
Replaced by `git config rename-section <old-name> <new-name>`.
335335

336+
--remove-section <name>::
337+
Replaced by `git config remove-section <name>`.
338+
336339
CONFIGURATION
337340
-------------
338341
`pager.config` is only respected when listing configuration, i.e., when

builtin/config.c

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ static const char *const builtin_config_usage[] = {
2121
N_("git config set [<file-option>] [--type=<type>] [--all] [--value=<value>] [--fixed-value] <name> <value>"),
2222
N_("git config unset [<file-option>] [--all] [--value=<value>] [--fixed-value] <name> <value>"),
2323
N_("git config rename-section [<file-option>] <old-name> <new-name>"),
24+
N_("git config remove-section [<file-option>] <name>"),
2425
NULL
2526
};
2627

@@ -49,6 +50,11 @@ static const char *const builtin_config_rename_section_usage[] = {
4950
NULL
5051
};
5152

53+
static const char *const builtin_config_remove_section_usage[] = {
54+
N_("git config remove-section [<file-option>] <name>"),
55+
NULL
56+
};
57+
5258
static char *key;
5359
static regex_t *key_regexp;
5460
static const char *value_pattern;
@@ -980,12 +986,38 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr
980986
return 0;
981987
}
982988

989+
static int cmd_config_remove_section(int argc, const char **argv, const char *prefix)
990+
{
991+
struct option opts[] = {
992+
CONFIG_LOCATION_OPTIONS,
993+
OPT_END(),
994+
};
995+
int ret;
996+
997+
argc = parse_options(argc, argv, prefix, opts, builtin_config_remove_section_usage,
998+
PARSE_OPT_STOP_AT_NON_OPTION);
999+
check_write();
1000+
check_argc(argc, 1, 1);
1001+
1002+
handle_config_location(prefix);
1003+
1004+
ret = git_config_rename_section_in_file(given_config_source.file,
1005+
argv[0], NULL);
1006+
if (ret < 0)
1007+
return ret;
1008+
else if (!ret)
1009+
die(_("no such section: %s"), argv[0]);
1010+
1011+
return 0;
1012+
}
1013+
9831014
static struct option builtin_subcommand_options[] = {
9841015
OPT_SUBCOMMAND("list", &subcommand, cmd_config_list),
9851016
OPT_SUBCOMMAND("get", &subcommand, cmd_config_get),
9861017
OPT_SUBCOMMAND("set", &subcommand, cmd_config_set),
9871018
OPT_SUBCOMMAND("unset", &subcommand, cmd_config_unset),
9881019
OPT_SUBCOMMAND("rename-section", &subcommand, cmd_config_rename_section),
1020+
OPT_SUBCOMMAND("remove-section", &subcommand, cmd_config_remove_section),
9891021
OPT_END(),
9901022
};
9911023

t/t1300-config.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -813,7 +813,7 @@ cat >> .git/config << EOF
813813
EOF
814814

815815
test_expect_success 'remove section' '
816-
git config --remove-section branch.zwei
816+
git config ${mode_prefix}remove-section branch.zwei
817817
'
818818

819819
cat > expect << EOF
@@ -2602,7 +2602,7 @@ test_expect_success 'refuse --fixed-value for incompatible actions' '
26022602
test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
26032603
test_must_fail git config --file=config --fixed-value --get-urlmatch dev.null bogus &&
26042604
test_must_fail git config ${mode_prefix}rename-section --file=config --fixed-value dev null &&
2605-
test_must_fail git config --file=config --fixed-value --remove-section dev &&
2605+
test_must_fail git config ${mode_prefix}remove-section --file=config --fixed-value dev &&
26062606
test_must_fail git config ${mode_prefix}list --file=config --fixed-value &&
26072607
test_must_fail git config --file=config --fixed-value --get-color dev.null &&
26082608
test_must_fail git config --file=config --fixed-value --get-colorbool dev.null &&

0 commit comments

Comments
 (0)