repo: add path.index with absolute and relative suffix formatting

External script workflows and formatting layers require straightforward access to the location of the index staging file. Currently, tracking this necessitates a legacy call to `git rev-parse --git-path index` or `--show-toplevel` logic abstractions. Introduce `path.index.absolute` and `path.index.relative` keys to `git repo info`. This allows tooling utilities to discover the active index context cleanly while scaling transparently with localized `GIT_INDEX_FILE` environment 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 629ac8ddbbe1a90a5fd38d51c86b4642300cd149
3 files changed +59
Documentation/git-repo.adoc
+12
@@ -127,6 +127,18 @@ values that they return:
127 The path to the repository's hooks directory relative to the current
128 working directory. Respects `core.hooksPath` configuration adjustments.
129
130 +`path.index.absolute`::
131 + The canonical absolute path to the repository's current index file.
132 + Respects the `GIT_INDEX_FILE` environment override. The returned path
133 + reflects the configured/default index location regardless of whether the
134 + repository is bare or whether the file currently exists.
135 +
136 +`path.index.relative`::
137 + The path to the repository's current index file relative to the current
138 + working directory. Respects the `GIT_INDEX_FILE` environment override.
139 + The returned path reflects the configured/default index location regardless
140 + of whether the repository is bare or whether the file currently exists.
141 +
142 `path.objects.absolute`::
143 The canonical absolute path to the repository's object database directory.
144 Respects the `GIT_OBJECT_DIRECTORY` environment override.
builtin/repo.c
+24
@@ -142,6 +142,28 @@ static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf)
142 return 0;
143 }
144
145 +static int get_path_index_absolute(struct repository *repo, struct strbuf *buf)
146 +{
147 + const char *index_file = repo_get_index_file(repo);
148 +
149 + if (!index_file)
150 + return error(_("unable to get index file"));
151 +
152 + format_path(buf, index_file, startup_info->prefix, PATH_FORMAT_CANONICAL);
153 + return 0;
154 +}
155 +
156 +static int get_path_index_relative(struct repository *repo, struct strbuf *buf)
157 +{
158 + const char *index_file = repo_get_index_file(repo);
159 +
160 + if (!index_file)
161 + return error(_("unable to get index file"));
162 +
163 + format_path(buf, index_file, startup_info->prefix, PATH_FORMAT_RELATIVE);
164 + return 0;
165 +}
166 +
167 static int get_path_objects_absolute(struct repository *repo, struct strbuf *buf)
168 {
169 const char *obj_dir = repo_get_object_directory(repo);
@@ -238,6 +260,8 @@ static const struct repo_info_field repo_info_field[] = {
260 { "path.gitdir.relative", get_path_gitdir_relative },
261 { "path.hooks.absolute", get_path_hooks_absolute },
262 { "path.hooks.relative", get_path_hooks_relative },
263 + { "path.index.absolute", get_path_index_absolute },
264 + { "path.index.relative", get_path_index_relative },
265 { "path.objects.absolute", get_path_objects_absolute },
266 { "path.objects.relative", get_path_objects_relative },
267 { "path.superproject-working-tree.absolute", get_path_superproject_absolute },
t/t1900-repo-info.sh
+23
@@ -219,6 +219,29 @@ test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
219 'custom-hooks' \
220 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"'
221
222 +test_repo_info_path 'index standard' 'index' '.git/index'
223 +
224 +test_repo_info_path 'index with GIT_INDEX_FILE override' 'index' \
225 + 'custom-index-file' \
226 + 'GIT_INDEX_FILE="$ROOT/custom-index-file" && export GIT_INDEX_FILE'
227 +
228 +test_expect_success 'path.index in a bare repository returns default index location' '
229 + test_when_finished "rm -rf bare.git" &&
230 + git init --bare bare.git &&
231 + (
232 + cd bare.git &&
233 + ROOT="$(test-tool path-utils real_path .)" &&
234 +
235 + echo "path.index.absolute=$ROOT/index" >expect.abs &&
236 + git repo info path.index.absolute >actual.abs &&
237 + test_cmp expect.abs actual.abs &&
238 +
239 + echo "path.index.relative=index" >expect.rel &&
240 + git repo info path.index.relative >actual.rel &&
241 + test_cmp expect.rel actual.rel
242 + )
243 +'
244 +
245 test_repo_info_path 'objects standard' 'objects' '.git/objects'
246
247 test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \