repo: add path.objects with absolute and relative suffix formatting
Tools and deployment hooks frequently query the location of the object database directory. Currently, this relies on legacy parsing methods or manually inspecting `git rev-parse --git-path objects`. Introduce `path.objects.absolute` and `path.objects.relative` keys to `git repo info`. This allows tools to discover the object database location safely while natively adhering to active `GIT_OBJECT_DIRECTORY` environment variable overrides. Mentored-by: Justin Tobler <jltobler@gmail.com> Mentored-by: Lucas Seiki Oshiro <lucasseikioshiro@gmail.com> Signed-off-by: K Jayatheerth <jayatheerthkulkarni2005@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
K Jayatheerth committed
Jul 26, 2026 at 16:13 UTC
b167a461e5803c3250c2e36ae9021652f290766e
3 files changed
+40
Documentation/git-repo.adoc
+9
@@ -119,6 +119,15 @@ values that they return:
119
`path.gitdir.relative`::
120
The path to the Git repository directory relative to the current working directory.
121
122
+`path.objects.absolute`::
123
+ The canonical absolute path to the repository's object database directory.
124
+ Respects the `GIT_OBJECT_DIRECTORY` environment override.
125
+
126
+`path.objects.relative`::
127
+ The path to the repository's object database directory relative to the
128
+ current working directory. Respects the `GIT_OBJECT_DIRECTORY`
129
+ environment override.
130
+
131
`path.superproject-working-tree.absolute`::
132
The canonical absolute path to the working tree root of the superproject
133
if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c
+24
@@ -122,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)
122
return 0;
123
}
124
125
+static int get_path_objects_absolute(struct repository *repo, struct strbuf *buf)
126
+{
127
+ const char *obj_dir = repo_get_object_directory(repo);
128
+
129
+ if (!obj_dir)
130
+ return error(_("unable to get object directory"));
131
+
132
+ format_path(buf, obj_dir, startup_info->prefix, PATH_FORMAT_CANONICAL);
133
+ return 0;
134
+}
135
+
136
+static int get_path_objects_relative(struct repository *repo, struct strbuf *buf)
137
+{
138
+ const char *obj_dir = repo_get_object_directory(repo);
139
+
140
+ if (!obj_dir)
141
+ return error(_("unable to get object directory"));
142
+
143
+ format_path(buf, obj_dir, startup_info->prefix, PATH_FORMAT_RELATIVE);
144
+ return 0;
145
+}
146
+
147
static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf)
148
{
149
struct strbuf superproject = STRBUF_INIT;
@@ -194,6 +216,8 @@ static const struct repo_info_field repo_info_field[] = {
216
{ "path.commondir.relative", get_path_commondir_relative },
217
{ "path.gitdir.absolute", get_path_gitdir_absolute },
218
{ "path.gitdir.relative", get_path_gitdir_relative },
219
+ { "path.objects.absolute", get_path_objects_absolute },
220
+ { "path.objects.relative", get_path_objects_relative },
221
{ "path.superproject-working-tree.absolute", get_path_superproject_absolute },
222
{ "path.superproject-working-tree.relative", get_path_superproject_relative },
223
{ "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh
+7
@@ -213,6 +213,13 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
213
'.git' \
214
'GIT_DIR="../.git" && export GIT_DIR'
215
216
+test_repo_info_path 'objects standard' 'objects' '.git/objects'
217
+
218
+test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \
219
+ 'custom-objects' \
220
+ 'GIT_OBJECT_DIRECTORY="$ROOT/custom-objects" && export GIT_OBJECT_DIRECTORY &&
221
+ mkdir -p "$ROOT/custom-objects"'
222
+
223
test_expect_success 'path.superproject-working-tree absolute and relative' '
224
test_when_finished "rm -rf sub super" &&
225
git init sub &&