Skip to contentSkip to conversation

repo: add paths.git_dir repo info key

PATCH In review Jayesh Daga via GitGitGadget 3 participants 3 messages Mar 17 – Mar 22 Documentation

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 repo: add paths.git_dir repo info key

From: jayesh0104 <[email protected]>

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.

---
repo: add paths.git_dir to 'git repo info'

Teach git repo info a new key, paths.git_dir, which reports the repository’s gitdir path (equivalent to git rev-parse --git-dir).

Documentation and tests are included.

Tests:

* make test T=t1900-repo-info.sh

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2242%2Fjayesh0104%2Fmaster-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2242/jayesh0104/master-v1
Pull-Request: https://github.com/git/git/pull/2242

 Documentation/git-repo.adoc |  5 +++++
 builtin/repo.c              |  7 +++++++
 t/t1900-repo-info.sh        | 10 ++++++++++
 3 files changed, 22 insertions(+)
Documentation/git-repo.adoc +5 -0
index 42262c1983..d17d911ec6 100644
@@ -95,6 +95,11 @@ In order to obtain a set of values from `git repo info`, you should provide
 the keys that identify them. Here's a list of the available keys and the
 values that they return:
 
+`paths.git_dir`::
+	The path to the Git directory for the repository (equivalent to
+	`git rev-parse --git-dir`).
+
+
 `layout.bare`::
 	`true` if this is a bare repository, otherwise `false`.
 
builtin/repo.c +7 -0
index 55f9b9095c..3067107cad 100644
@@ -66,11 +66,18 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
 	return 0;
 }
 
+static int get_paths_git_dir(struct repository *repo, struct strbuf *buf)
+{
+	strbuf_addstr(buf, repo_get_git_dir(repo));
+	return 0;
+}
+
 /* repo_info_field keys must be in lexicographical order */
 static const struct repo_info_field repo_info_field[] = {
 	{ "layout.bare", get_layout_bare },
 	{ "layout.shallow", get_layout_shallow },
 	{ "object.format", get_object_format },
+	{ "paths.git_dir", get_paths_git_dir },
 	{ "references.format", get_references_format },
 };
 
t/t1900-repo-info.sh +10 -0
index a9eb07abe8..63be0849c4 100755
@@ -149,4 +149,14 @@ test_expect_success 'git repo info --keys uses lines as its default output forma
 	test_cmp expect actual
 '
 
+test_expect_success 'paths.git_dir matches rev-parse --git-dir' '
+	git init repo &&
+	(
+		cd repo &&
+		git repo info paths.git_dir >actual &&
+		echo "paths.git_dir=$(git rev-parse --git-dir)" >expect &&
+		test_cmp expect actual
+	)
+'
+
 test_done

base-commit: ca1db8a0f7dc0dbea892e99f5b37c5fe5861be71

Signature · 1 line
gitgitgadget
#1 lore raw
Quoted 5 lines · Jayesh Daga via GitGitGadget

From: jayesh0104 <[email protected]>

Introduce a new repo info key paths.git_dir to expose the repository's gitdir path, equivalent to git rev-parse --git-dir.

Quoted 8 lines

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.

Hello Jayesh,

Seeing from the people CC'd I'm assuming that you're interested in applying for the GSoC.

As such, we encourage GSoC contributors to work on micro-projects as listed on our GSoC website and also to read the guidelines we've laid out [1] [2].

I would also mention that we do not recommend getting started on a project, unless you're selected.

Now specifically for this project, there is still no decision made about using relative paths vs absolute paths, I've highlighted this in one of the candidates proposals [3]. I would suggest getting involved in that discussion and coming to a conclusion before starting work on it.

[1]: https://git.github.io/General-Microproject-Information/
[2]: https://git.github.io/General-Application-Information/
[3]: https://lore.kernel.org/git/CAOLa=ZTtNSZ904v0-SN16jAis7gK4=MVj1g_5CGdbmaBopeZkg@mail.gmail.com/#t

Regards,
Karthik

[snip]

#2 lore raw
In reply to Jayesh Daga via GitGitGadget

Hi Jayesh,

Quoted 4 lines · Jayesh Daga via GitGitGadget

From: jayesh0104 <[email protected]>

Introduce a new repo info key paths.git_dir to expose the repository's gitdir path, equivalent to git rev-parse --git-dir.

Here you promise in the commit message that paths.git_dir and git rev-parse --git-dir are equivalent...

Quoted 54 lines
Quoted 1 line

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.

---
repo: add paths.git_dir to 'git repo info'

Teach git repo info a new key, paths.git_dir, which reports the repository’s gitdir path (equivalent to git rev-parse --git-dir).

Documentation and tests are included.

Tests:

* make test T=t1900-repo-info.sh

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2242%2Fjayesh0104%2Fmaster-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2242/jayesh0104/master-v1
Pull-Request: https://github.com/git/git/pull/2242

  Documentation/git-repo.adoc |  5 +++++
  builtin/repo.c              |  7 +++++++
  t/t1900-repo-info.sh        | 10 ++++++++++
  3 files changed, 22 insertions(+)
Documentation/git-repo.adoc +5 -0
index 42262c1983..d17d911ec6 100644
@@ -95,6 +95,11 @@ In order to obtain a set of values from `git repo info`, you should provide
  the keys that identify them. Here's a list of the available keys and the
  values that they return:
 
+`paths.git_dir`::
+	The path to the Git directory for the repository (equivalent to
+	`git rev-parse --git-dir`).
+
+
  `layout.bare`::
  	`true` if this is a bare repository, otherwise `false`.
 
builtin/repo.c +0 -0
index 55f9b9095c..3067107cad 100644
@@ -66,11 +66,18 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
  	return 0;
  }
 

...

builtin/repo.c static int get_references_format(struct repository *repo, struct strbuf *buf) · line 74

Quoted 6 lines
builtin/repo.c +6 -0
+static int get_paths_git_dir(struct repository *repo, struct strbuf *buf)
+{
+	strbuf_addstr(buf, repo_get_git_dir(repo));
+	return 0;
+}
+

...But your implementation here doesn't quite feel right. Check the git-rev-parse documentation: the output of the --git-dir argument is context-aware and depends on your current directory.

If you are in the root directory of the repository, it gives '.git'; And if you are in some subdirectory of the repository , it gives '/home/user/.../repo-root/.../.git'. I don't think simply calling 'repo_get_git_dir(repo)' will achieve this functionality.

Quoted 17 lines

/* repo_info_field keys must be in lexicographical order */ static const struct repo_info_field repo_info_field[] = {
{ "layout.bare", get_layout_bare },
{ "layout.shallow", get_layout_shallow },
{ "object.format", get_object_format },

builtin/repo.c +1 -0
+	{ "paths.git_dir", get_paths_git_dir },
  	{ "references.format", get_references_format },
  };
t/t1900-repo-info.sh +0 -0
index a9eb07abe8..63be0849c4 100755
@@ -149,4 +149,14 @@ test_expect_success 'git repo info --keys uses lines as its default output forma
  	test_cmp expect actual
  '
 

...

t/t1900-repo-info.sh test_expect_success 'git repo info --keys uses lines as its default output forma · line 162

Quoted 11 lines
t/t1900-repo-info.sh +10 -0
+test_expect_success 'paths.git_dir matches rev-parse --git-dir' '
+	git init repo &&
+	(
+		cd repo &&
+		git repo info paths.git_dir >actual &&
+		echo "paths.git_dir=$(git rev-parse --git-dir)" >expect &&
+		test_cmp expect actual
+	)
+'
+
  test_done

And you’ve only provided tests for the root directory here, which I don’t think is sufficient. That said, considering that you’ve likely misunderstood how to use the --git-dir parameter, this is understandable.

Next time you create a similar patch, I think you should take a close look at the documentation and source code first, and try using the existing commands a few times on your own to understand how they work, right? ;)

Regards,

Yuchen