builtin/init: stop modifying `is_bare_repository_cfg`
We're modifying `is_bare_repository_cfg` in "builtin/init.c" to indicate whether the newly created repository is supposed to be a bare repository or not. This is ultimately unnecessary though: when initializing the repository in `init_db()` we eventually set `is_bare_repository_cfg = !work_tree`, so all that matters is whether or not we have a working tree configured, and the working tree is set up in the non-bare in "builtin/init.c". Stop modifying the global variable in "builtin/init.c" in favor of a local variable. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt committed
Jun 11, 2026 at 08:44 UTC
f12d73132ea23788167a6b21fad63d85c76fa863
1 file changed
+8
-7
builtin/init-db.c
+8
-7
@@ -81,6 +81,7 @@ int cmd_init_db(int argc,
81
const char *template_dir = NULL;
82
char *template_dir_to_free = NULL;
83
unsigned int flags = 0;
84
+ int bare = is_bare_repository_cfg;
85
const char *object_format = NULL;
86
const char *ref_format = NULL;
87
const char *initial_branch = NULL;
@@ -90,7 +91,7 @@ int cmd_init_db(int argc,
91
const struct option init_db_options[] = {
92
OPT_STRING(0, "template", &template_dir, N_("template-directory"),
93
N_("directory from which templates will be used")),
93
- OPT_SET_INT(0, "bare", &is_bare_repository_cfg,
94
+ OPT_SET_INT(0, "bare", &bare,
95
N_("create a bare repository"), 1),
96
{
97
.type = OPTION_CALLBACK,
@@ -116,7 +117,7 @@ int cmd_init_db(int argc,
117
118
argc = parse_options(argc, argv, prefix, init_db_options, init_db_usage, 0);
119
119
- if (real_git_dir && is_bare_repository_cfg == 1)
120
+ if (real_git_dir && bare == 1)
121
die(_("options '%s' and '%s' cannot be used together"), "--separate-git-dir", "--bare");
122
123
if (real_git_dir && !is_absolute_path(real_git_dir))
@@ -160,7 +161,7 @@ int cmd_init_db(int argc,
161
} else if (0 < argc) {
162
usage(init_db_usage[0]);
163
}
163
- if (is_bare_repository_cfg == 1) {
164
+ if (bare == 1) {
165
char *cwd = xgetcwd();
166
setenv(GIT_DIR_ENVIRONMENT, cwd, argc > 0);
167
free(cwd);
@@ -187,7 +188,7 @@ int cmd_init_db(int argc,
188
*/
189
git_dir = xstrdup_or_null(getenv(GIT_DIR_ENVIRONMENT));
190
work_tree = xstrdup_or_null(getenv(GIT_WORK_TREE_ENVIRONMENT));
190
- if ((!git_dir || is_bare_repository_cfg == 1) && work_tree)
191
+ if ((!git_dir || bare == 1) && work_tree)
192
die(_("%s (or --work-tree=<directory>) not allowed without "
193
"specifying %s (or --git-dir=<directory>)"),
194
GIT_WORK_TREE_ENVIRONMENT,
@@ -224,10 +225,10 @@ int cmd_init_db(int argc,
225
strbuf_release(&sb);
226
}
227
227
- if (is_bare_repository_cfg < 0)
228
- is_bare_repository_cfg = guess_repository_type(git_dir);
228
+ if (bare < 0)
229
+ bare = guess_repository_type(git_dir);
230
230
- if (!is_bare_repository_cfg) {
231
+ if (!bare) {
232
const char *git_dir_parent = strrchr(git_dir, '/');
233
234
if (work_tree) {