aboutsummaryrefslogtreecommitdiff
path: root/builtin/config.c
diff options
context:
space:
mode:
authorPatrick Steinhardt <ps@pks.im>2024-05-15 08:42:02 +0200
committerJunio C Hamano <gitster@pobox.com>2024-05-15 07:17:52 -0700
commite44b018c5299f2632fcbb079bead00a529546763 (patch)
tree285fe045daf583b3cd18bfa26e1398b643f83883 /builtin/config.c
parent9cab5e8078c314957395ddb4c198c3320c4e5a91 (diff)
downloadgit-e44b018c5299f2632fcbb079bead00a529546763.tar.xz
builtin/config: check for writeability after source is set up
The `check_write()` function verifies that we do not try to write to a config source that cannot be written to, like for example stdin. But while the new subcommands do call this function, they do so before calling `handle_config_location()`. Consequently, we only end up checking the default config location for writeability, not the location that was actually specified by the caller of git-config(1). Fix this by calling `check_write()` after `handle_config_location()`. We will further clarify the relationship between those two functions in a subsequent commit where we remove the global state that both implicitly rely on. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/config.c')
-rw-r--r--builtin/config.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/builtin/config.c b/builtin/config.c
index 0842e4f198..9866d1a055 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -843,7 +843,6 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, opts, builtin_config_set_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
- check_write();
check_argc(argc, 2, 2);
if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern)
@@ -856,6 +855,7 @@ static int cmd_config_set(int argc, const char **argv, const char *prefix)
comment = git_config_prepare_comment_string(comment_arg);
handle_config_location(prefix);
+ check_write();
value = normalize_value(argv[0], argv[1], &default_kvi);
@@ -891,13 +891,13 @@ static int cmd_config_unset(int argc, const char **argv, const char *prefix)
argc = parse_options(argc, argv, prefix, opts, builtin_config_unset_usage,
PARSE_OPT_STOP_AT_NON_OPTION);
- check_write();
check_argc(argc, 1, 1);
if ((flags & CONFIG_FLAGS_FIXED_VALUE) && !value_pattern)
die(_("--fixed-value only applies with 'value-pattern'"));
handle_config_location(prefix);
+ check_write();
if ((flags & CONFIG_FLAGS_MULTI_REPLACE) || value_pattern)
return git_config_set_multivar_in_file_gently(given_config_source.file,
@@ -918,10 +918,10 @@ static int cmd_config_rename_section(int argc, const char **argv, const char *pr
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);
+ check_write();
ret = git_config_rename_section_in_file(given_config_source.file,
argv[0], argv[1]);
@@ -943,10 +943,10 @@ static int cmd_config_remove_section(int argc, const char **argv, const char *pr
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);
+ check_write();
ret = git_config_rename_section_in_file(given_config_source.file,
argv[0], NULL);
@@ -997,10 +997,10 @@ static int cmd_config_edit(int argc, const char **argv, const char *prefix)
};
argc = parse_options(argc, argv, prefix, opts, builtin_config_edit_usage, 0);
- check_write();
check_argc(argc, 0, 0);
handle_config_location(prefix);
+ check_write();
return show_editor();
}