git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3] init: show absolute path of (re)initialized repository

From
Matt Hunter <m@lfurio.us>
Date
Oct 28, 2026, 05:16 UTC
Message-ID
<20261028051704.2759358-1-m@lfurio.us>
In-Reply-To
<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.

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>
---
 Changes in v3:
    - expand test to cover the full output of the init command
    - Link to v2: https://patch.msgid.link/20261022120749.3567828-1-m@lfurio.us
 Changes in v2:
    - len type is updated to size_t
    - added a regression test (changed my mind on this)
    - some text is stripped from the patch message
    - Link to v1: https://patch.msgid.link/20261020053932.1274210-1-m@lfurio.us
 builtin/init-db.c | 7 ++++---
 t/t0001-init.sh   | 6 ++++++
 2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/builtin/init-db.c b/builtin/init-db.c
index 374ed3a74706..9612d2b8bfca 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);
+		size_t 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);
diff --git a/t/t0001-init.sh b/t/t0001-init.sh
index f1d227f27167..5d438dcc2804 100755
--- a/t/t0001-init.sh
+++ b/t/t0001-init.sh
@@ -1000,4 +1000,10 @@ test_expect_success 'init honors GIT_OBJECT_DIRECTORY' '
 	test_path_is_dir custom-odb/info
 '
 
+test_expect_success 'init shows absolute path to gitdir' '
+	echo "Initialized empty Git repository in $(pwd)/init-path/.git/" >expect &&
+	git init init-path >actual &&
+	test_cmp expect actual
+'
+
 test_done

Range-diff against v2:
1:  49d220d97aa8 ! 1:  6c9adee7702b init: show absolute path of (re)initialized repository
    @@ t/t0001-init.sh: test_expect_success 'init honors GIT_OBJECT_DIRECTORY' '
      '
      
     +test_expect_success 'init shows absolute path to gitdir' '
    -+	expect="$(pwd)/init-path" &&
    ++	echo "Initialized empty Git repository in $(pwd)/init-path/.git/" >expect &&
     +	git init init-path >actual &&
    -+	test_grep "$expect" actual
    ++	test_cmp expect actual
     +'
     +
      test_done

base-commit: 47fdf2208c5b94c8cc01c106b8f7c85efb91c926
-- 
2.56.0.333.g9ad7b1359b
Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 13 of 15 in “init: show absolute path of (re)initialized repository”
  1. init: show absolute path of (re)initialized repositoryMatt Hunter, Oct 20, 2026
  2. Patrick SteinhardtOct 20, 2026
  3. Matt HunterOct 20, 2026
  4. Patrick SteinhardtOct 20, 2026
  5. Harald NordgrenOct 20, 2026
  6. Patrick SteinhardtOct 20, 2026
  7. Harald NordgrenOct 20, 2026
  8. Junio C HamanoOct 20, 2026
  9. init: show absolute path of (re)initialized repositoryMatt Hunter, Oct 22, 2026
  10. Patrick SteinhardtOct 23, 2026
  11. Matt HunterOct 23, 2026
  12. Patrick SteinhardtOct 26, 2026
  13. init: show absolute path of (re)initialized repositoryMatt Hunter, Oct 28, 2026
  14. Patrick SteinhardtOct 28, 2026
  15. Junio C HamanoOct 28, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.