Skip to content

Commit 695009b

Browse files
pks-tgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 2ee35c4 commit 695009b

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

builtin/init-db.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ static int create_default_files(const char *template_path)
227227
/* This forces creation of new config file */
228228
xsnprintf(repo_version_string, sizeof(repo_version_string),
229229
"%d", GIT_REPO_VERSION);
230-
git_config_set("core.repositoryformatversion", repo_version_string);
230+
git_config_set_or_die("core.repositoryformatversion", repo_version_string);
231231

232232
/* Check filemode trustability */
233233
path = git_path_buf(&buf, "config");
@@ -241,18 +241,18 @@ static int create_default_files(const char *template_path)
241241
if (filemode && !reinit && (st1.st_mode & S_IXUSR))
242242
filemode = 0;
243243
}
244-
git_config_set("core.filemode", filemode ? "true" : "false");
244+
git_config_set_or_die("core.filemode", filemode ? "true" : "false");
245245

246246
if (is_bare_repository())
247-
git_config_set("core.bare", "true");
247+
git_config_set_or_die("core.bare", "true");
248248
else {
249249
const char *work_tree = get_git_work_tree();
250-
git_config_set("core.bare", "false");
250+
git_config_set_or_die("core.bare", "false");
251251
/* allow template config file to override the default */
252252
if (log_all_ref_updates == -1)
253-
git_config_set("core.logallrefupdates", "true");
253+
git_config_set_or_die("core.logallrefupdates", "true");
254254
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);
256256
}
257257

258258
if (!reinit) {
@@ -265,12 +265,12 @@ static int create_default_files(const char *template_path)
265265
S_ISLNK(st1.st_mode))
266266
unlink(path); /* good */
267267
else
268-
git_config_set("core.symlinks", "false");
268+
git_config_set_or_die("core.symlinks", "false");
269269

270270
/* Check if the filesystem is case-insensitive */
271271
path = git_path_buf(&buf, "CoNfIg");
272272
if (!access(path, F_OK))
273-
git_config_set("core.ignorecase", "true");
273+
git_config_set_or_die("core.ignorecase", "true");
274274
probe_utf8_pathname_composition();
275275
}
276276

@@ -386,8 +386,8 @@ int init_db(const char *template_dir, unsigned int flags)
386386
xsnprintf(buf, sizeof(buf), "%d", OLD_PERM_EVERYBODY);
387387
else
388388
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");
391391
}
392392

393393
if (!(flags & INIT_DB_QUIET)) {

0 commit comments

Comments
 (0)