|
19 | 19 | #include "utf8.h"
|
20 | 20 | #include "dir.h"
|
21 | 21 | #include "color.h"
|
| 22 | +#include "worktree.h" |
22 | 23 |
|
23 | 24 | struct config_source {
|
24 | 25 | struct config_source *prev;
|
@@ -2137,6 +2138,39 @@ int repo_config_get_pathname(struct repository *repo,
|
2137 | 2138 | return ret;
|
2138 | 2139 | }
|
2139 | 2140 |
|
| 2141 | +int repo_config_set_gently(struct repository *r, |
| 2142 | + const char *key, const char *value) |
| 2143 | +{ |
| 2144 | + char *path = repo_git_path(r, "config"); |
| 2145 | + int ret = git_config_set_multivar_in_file_gently(path, key, value, NULL, 0); |
| 2146 | + free(path); |
| 2147 | + return ret; |
| 2148 | +} |
| 2149 | + |
| 2150 | +void repo_config_set(struct repository *r, const char *key, const char *value) |
| 2151 | +{ |
| 2152 | + if (!repo_config_set_gently(r, key, value)) |
| 2153 | + return; |
| 2154 | + if (value) |
| 2155 | + die(_("could not set '%s' to '%s'"), key, value); |
| 2156 | + else |
| 2157 | + die(_("could not unset '%s'"), key); |
| 2158 | +} |
| 2159 | + |
| 2160 | +int repo_config_set_worktree_gently(struct repository *r, |
| 2161 | + const char *key, const char *value) |
| 2162 | +{ |
| 2163 | + char *path; |
| 2164 | + int ret; |
| 2165 | + |
| 2166 | + path = get_worktree_config(r); |
| 2167 | + if (!path) |
| 2168 | + return CONFIG_INVALID_FILE; |
| 2169 | + ret = git_config_set_multivar_in_file_gently(path, key, value, NULL, 0); |
| 2170 | + free(path); |
| 2171 | + return ret; |
| 2172 | +} |
| 2173 | + |
2140 | 2174 | /* Functions used historically to read configuration from 'the_repository' */
|
2141 | 2175 | void git_config(config_fn_t fn, void *data)
|
2142 | 2176 | {
|
@@ -2912,7 +2946,12 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
|
2912 | 2946 |
|
2913 | 2947 | ret = 0;
|
2914 | 2948 |
|
2915 |
| - /* Invalidate the config cache */ |
| 2949 | + /* |
| 2950 | + * Invalidate the config cache |
| 2951 | + * |
| 2952 | + * NEEDSWORK: invalidate _all_ existing config caches, not |
| 2953 | + * just one from the_repository |
| 2954 | + */ |
2916 | 2955 | git_config_clear();
|
2917 | 2956 |
|
2918 | 2957 | out_free:
|
|
0 commit comments