[GSOC RFC PATCH] builtin/repo: add path.in-worktree field
- From
SoutrikDas <valusoutrik@gmail.com>
- Date
- Feb 25, 2026, 19:03 UTC
- Message-ID
- <20260225190306.39358-1-valusoutrik@gmail.com>
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