public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
From: SoutrikDas <valusoutrik@gmail.com>
To: git@vger.kernel.org
Cc: SoutrikDas <valusoutrik@gmail.com>,
	Christian Couder <christian.couder@gmail.com>,
	Karthik Nayak <karthik.188@gmail.com>,
	Justin Tobler <jltobler@gmail.com>,
	Ayush Chandekar <ayu.chandekar@gmail.com>,
	Siddharth Asthana <siddharthasthana31@gmail.com>,
	Lucas Seiki Oshiro <lucasseikioshiro@gmail.com>
Subject: [GSOC RFC PATCH] builtin/repo: add path.in-worktree field
Date: Thu, 26 Feb 2026 00:33:04 +0530	[thread overview]
Message-ID: <20260225190306.39358-1-valusoutrik@gmail.com> (raw)

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


             reply	other threads:[~2026-02-25 19:03 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-02-25 19:03 SoutrikDas [this message]
2026-02-25 19:37 ` [GSOC RFC PATCH] builtin/repo: add path.in-worktree field 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260225190306.39358-1-valusoutrik@gmail.com \
    --to=valusoutrik@gmail.com \
    --cc=ayu.chandekar@gmail.com \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jltobler@gmail.com \
    --cc=karthik.188@gmail.com \
    --cc=lucasseikioshiro@gmail.com \
    --cc=siddharthasthana31@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox