[PATCH] init: show absolute path of (re)initialized repository
- From
Matt Hunter <m@lfurio.us>
- Date
- Oct 20, 2026, 05:38 UTC
- Message-ID
- <20261020053932.1274210-1-m@lfurio.us>
Since 20e38cba3926 (setup: split up concerns of `init_db()`, 2026-09-10), git-init produces the message:
Initialized empty Git repository in .git/
instead of the previous
Initialized empty Git repository in /full/path/to/repo/.git/
Prior to 20e38cba3926, the code producing this message was in function init_db (renamed at the time to create_repository). In that context, the git_dir variable was updated by 'git_dir = repo_get_git_dir(repo);' earlier in the function, to set the value used in printf.
None of the discussion [1] around the original patch indicates that this change was intentional, so address the regression by similarly using repo_get_git_dir in this code's new location.
In this case, git_dir is referencing owned memory that is later freed, so declare a new variable to hold the used string.
1: https://lore.kernel.org/git/20260825-pks-odb-write-alternates-at-creation-time-v1-0-911513ba95c3@pks.im/
Signed-off-by: Matt Hunter <m@lfurio.us> --- builtin/init-db.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/builtin/init-db.c b/builtin/init-db.c index 374ed3a74706..a2628568ff6a 100644 --- a/builtin/init-db.c +++ b/builtin/init-db.c @@ -248,18 +248,19 @@ int cmd_init_db(int argc, create_object_database(the_repository, NULL); if (!quiet) { - int len = strlen(git_dir); + const char *full_git_dir = repo_get_git_dir(the_repository); + int len = strlen(full_git_dir); if (reinit) printf(repo_settings_get_shared_repository(the_repository) ? _("Reinitialized existing shared Git repository in %s%s\n") : _("Reinitialized existing Git repository in %s%s\n"), - git_dir, len && git_dir[len-1] != '/' ? "/" : ""); + full_git_dir, len && full_git_dir[len-1] != '/' ? "/" : ""); else printf(repo_settings_get_shared_repository(the_repository) ? _("Initialized empty shared Git repository in %s%s\n") : _("Initialized empty Git repository in %s%s\n"), - git_dir, len && git_dir[len-1] != '/' ? "/" : ""); + full_git_dir, len && full_git_dir[len-1] != '/' ? "/" : ""); } free(template_dir_to_free); base-commit: c51408889c3b372814bc20b9431c3b74d0d268eb
-- 2.56.0.257.gf7497c7d27