public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* [GSOC RFC PATCH] builtin/repo: add path.in-worktree field
@ 2026-02-25 19:03 SoutrikDas
  2026-02-25 19:37 ` Lucas Seiki Oshiro
  0 siblings, 1 reply; 8+ messages in thread
From: SoutrikDas @ 2026-02-25 19:03 UTC (permalink / raw)
  To: git
  Cc: SoutrikDas, Christian Couder, Karthik Nayak, Justin Tobler,
	Ayush Chandekar, Siddharth Asthana, Lucas Seiki Oshiro

Hi everyone,

In this patch I am trying to provide the equivalent functionality of
'git rev-parse --is-inside-work-tree'
I found that I could either use the 'is_inside_work_tree' inside setup.h
which does not take anything , or use the 'is_inside_dir' from dir.h
and use the worktree directory in the repo variable that the function
is getting. 

I went with the latter because the former was using 'the_repository'
inside. 

My reason behind adding this is because : [1]

> Add path-related values currently obtained through git rev-parse 
> (see “Options for Files” in git-rev-parse documentation): 
> git-dir, common-dir, toplevel, superproject-working-tree

Since its intended for repo to have more path related values, then 
'--is-inside-work-tree' would also make sense. 


Although I am not sure if 'path.in-worktree' is the best name for it.
Also, I did run t1900-repo.sh and it was failing one test case,
which also ran with an ok when I added the new field to REPO_INFO_KEYS.

[1] : https://git.github.io/SoC-2026-Ideas/

Add a 'path.in-worktree' field to 'git repo info' that indicates
whether the current directory is inside the worktree or not.
Equivalent to 'git rev-parse --is-inside-work-tree'.

Signed-off-by: SoutrikDas <valusoutrik@gmail.com>
---
 builtin/repo.c  | 8 ++++++++
 t/t1900-repo.sh | 1 +
 2 files changed, 9 insertions(+)

diff --git a/builtin/repo.c b/builtin/repo.c
index 0ea045abc1..3eb7115208 100644
--- a/builtin/repo.c
+++ b/builtin/repo.c
@@ -1,6 +1,7 @@
 #define USE_THE_REPOSITORY_VARIABLE
 
 #include "builtin.h"
+#include "dir.h"
 #include "environment.h"
 #include "hex.h"
 #include "odb.h"
@@ -61,11 +62,18 @@ static int get_references_format(struct repository *repo, struct strbuf *buf)
 	return 0;
 }
 
+static int get_path_in_worktree(struct repository *repo, struct strbuf *buf)
+{
+	strbuf_addstr(buf, is_inside_dir(repo->worktree) ? "true" : "false");
+	return 0;
+}
+
 /* repo_info_fields keys must be in lexicographical order */
 static const struct field repo_info_fields[] = {
 	{ "layout.bare", get_layout_bare },
 	{ "layout.shallow", get_layout_shallow },
 	{ "object.format", get_object_format },
+	{ "path.in-worktree", get_path_in_worktree },
 	{ "references.format", get_references_format },
 };
 
diff --git a/t/t1900-repo.sh b/t/t1900-repo.sh
index 51d55f11a5..d793d1b8e2 100755
--- a/t/t1900-repo.sh
+++ b/t/t1900-repo.sh
@@ -10,6 +10,7 @@ REPO_INFO_KEYS='
 	layout.bare
 	layout.shallow
 	object.format
+	path.in-worktree
 	references.format
 '
 
-- 
2.52.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2026-03-02 18:08 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-25 19:03 [GSOC RFC PATCH] builtin/repo: add path.in-worktree field SoutrikDas
2026-02-25 19:37 ` Lucas Seiki Oshiro
2026-02-26 20:16   ` SoutrikDas
2026-02-26 21:26     ` Lucas Seiki Oshiro
2026-02-26 22:33       ` Junio C Hamano
2026-02-26 22:38         ` Lucas Seiki Oshiro
2026-03-02 18:08         ` Kaartic Sivaraam
2026-02-27  3:51       ` SoutrikDas

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox