Skip to content

Commit 5a8165b

Browse files
committed
repo: add paths.git_dir repo info key
Introduce a new repo info key `paths.git_dir` to expose the repository's gitdir path, equivalent to `git rev-parse --git-dir`. This improves consistency and allows tools to retrieve the gitdir path without invoking external commands. The implementation adds support in repo.c and integrates it into the repo info reporting mechanism. Documentation is updated to describe the new key, and tests are added to verify that the value matches the output of `git rev-parse --git-dir`. Signed-off-by: jayesh0104 <jayeshdaga99@gmail.com>
1 parent ca1db8a commit 5a8165b

3 files changed

Lines changed: 22 additions & 0 deletions

File tree

Documentation/git-repo.adoc

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ In order to obtain a set of values from `git repo info`, you should provide
9595
the keys that identify them. Here's a list of the available keys and the
9696
values that they return:
9797

98+
`paths.git_dir`::
99+
The path to the Git directory for the repository (equivalent to
100+
`git rev-parse --git-dir`).
101+
102+
98103
`layout.bare`::
99104
`true` if this is a bare repository, otherwise `false`.
100105

builtin/repo.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,18 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
6666
return 0;
6767
}
6868

69+
static int get_paths_git_dir(struct repository *repo, struct strbuf *buf)
70+
{
71+
strbuf_addstr(buf, repo_get_git_dir(repo));
72+
return 0;
73+
}
74+
6975
/* repo_info_field keys must be in lexicographical order */
7076
static const struct repo_info_field repo_info_field[] = {
7177
{ "layout.bare", get_layout_bare },
7278
{ "layout.shallow", get_layout_shallow },
7379
{ "object.format", get_object_format },
80+
{ "paths.git_dir", get_paths_git_dir },
7481
{ "references.format", get_references_format },
7582
};
7683

t/t1900-repo-info.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,14 @@ test_expect_success 'git repo info --keys uses lines as its default output forma
149149
test_cmp expect actual
150150
'
151151

152+
test_expect_success 'paths.git_dir matches rev-parse --git-dir' '
153+
git init repo &&
154+
(
155+
cd repo &&
156+
git repo info paths.git_dir >actual &&
157+
echo "paths.git_dir=$(git rev-parse --git-dir)" >expect &&
158+
test_cmp expect actual
159+
)
160+
'
161+
152162
test_done

0 commit comments

Comments
 (0)