builtin/config: introduce "rename-section" subcommand
Introduce a new "rename-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>
This commit is contained in:

committed by
Junio C Hamano

parent
95ea69c67b
commit
3418e96f37
@ -20,6 +20,7 @@ static const char *const builtin_config_usage[] = {
|
||||
N_("git config get [<file-option>] [<display-option>] [--includes] [--all] [--regexp=<regexp>] [--value=<value>] [--fixed-value] [--default=<default>] <name>"),
|
||||
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>"),
|
||||
NULL
|
||||
};
|
||||
|
||||
@ -43,6 +44,11 @@ static const char *const builtin_config_unset_usage[] = {
|
||||
NULL
|
||||
};
|
||||
|
||||
static const char *const builtin_config_rename_section_usage[] = {
|
||||
N_("git config rename-section [<file-option>] <old-name> <new-name>"),
|
||||
NULL
|
||||
};
|
||||
|
||||
static char *key;
|
||||
static regex_t *key_regexp;
|
||||
static const char *value_pattern;
|
||||
@ -949,11 +955,37 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix)
|
||||
NULL, NULL);
|
||||
}
|
||||
|
||||
static int cmd_config_rename_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_rename_section_usage,
|
||||
PARSE_OPT_STOP_AT_NON_OPTION);
|
||||
check_write();
|
||||
check_argc(argc, 2, 2);
|
||||
|
||||
handle_config_location(prefix);
|
||||
|
||||
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]);
|
||||
|
||||
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_END(),
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user