init-db: die on config errors when initializing empty repo
When creating an empty repository with `git init-db` we do not check for error codes returned by `git_config_set` functions. This may cause the user to end up with an inconsistent repository without any indication for the user. Fix this problem by dying early with an error message when we are unable to write the configuration files to disk. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Feb 22, 2016 at 12:23 UTC
695009bc09a667899d06cda44956fea00ab153ab
1 file changed
+10
-10
builtin/init-db.c
+10
-10
@@ -227,7 +227,7 @@ static int create_default_files(const char *template_path)
227
/* This forces creation of new config file */
228
xsnprintf(repo_version_string, sizeof(repo_version_string),
229
"%d", GIT_REPO_VERSION);
230
- git_config_set("core.repositoryformatversion", repo_version_string);
230
+ git_config_set_or_die("core.repositoryformatversion", repo_version_string);
231
232
/* Check filemode trustability */
233
path = git_path_buf(&buf, "config");
@@ -241,18 +241,18 @@ static int create_default_files(const char *template_path)
241
if (filemode && !reinit && (st1.st_mode & S_IXUSR))
242
filemode = 0;
243
}
244
- git_config_set("core.filemode", filemode ? "true" : "false");
244
+ git_config_set_or_die("core.filemode", filemode ? "true" : "false");
245
246
if (is_bare_repository())
247
- git_config_set("core.bare", "true");
247
+ git_config_set_or_die("core.bare", "true");
248
else {
249
const char *work_tree = get_git_work_tree();
250
- git_config_set("core.bare", "false");
250
+ git_config_set_or_die("core.bare", "false");
251
/* allow template config file to override the default */
252
if (log_all_ref_updates == -1)
253
- git_config_set("core.logallrefupdates", "true");
253
+ git_config_set_or_die("core.logallrefupdates", "true");
254
if (needs_work_tree_config(get_git_dir(), work_tree))
255
- git_config_set("core.worktree", work_tree);
255
+ git_config_set_or_die("core.worktree", work_tree);
256
}
257
258
if (!reinit) {
@@ -265,12 +265,12 @@ static int create_default_files(const char *template_path)
265
S_ISLNK(st1.st_mode))
266
unlink(path); /* good */
267
else
268
- git_config_set("core.symlinks", "false");
268
+ git_config_set_or_die("core.symlinks", "false");
269
270
/* Check if the filesystem is case-insensitive */
271
path = git_path_buf(&buf, "CoNfIg");
272
if (!access(path, F_OK))
273
- git_config_set("core.ignorecase", "true");
273
+ git_config_set_or_die("core.ignorecase", "true");
274
probe_utf8_pathname_composition();
275
}
276
@@ -386,8 +386,8 @@ int init_db(const char *template_dir, unsigned int flags)
386
xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
387
else
388
die("BUG: invalid value for shared_repository");
389
- git_config_set("core.sharedrepository", buf);
390
- git_config_set("receive.denyNonFastforwards", "true");
389
+ git_config_set_or_die("core.sharedrepository", buf);
390
+ git_config_set_or_die("receive.denyNonFastforwards", "true");
391
}
392
393
if (!(flags & INIT_DB_QUIET)) {