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 17, 2026 at 19:00 UTC
c99912d7c8e7602e2a4cce9709bbc22ca431213b
3 files changed
+38
Documentation/git-repo.adoc
+8
@@ -127,6 +127,14 @@ 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.
133
+
134
+`path.index.relative`::
135
+ The path to the repository's current index file relative to the current
136
+ working directory. Respects the `GIT_INDEX_FILE` environment override.
137
+
138
`path.objects.absolute`::
139
The canonical absolute path to the repository's object database directory.
140
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
+6
@@ -219,6 +219,12 @@ 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_repo_info_path 'objects standard' 'objects' '.git/objects'
229
230
test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \