builtin/repo: add path.in-worktree field
RFC PATCH 1/1 builtin/repo: add path.in-worktree field
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]
Quoted 3 lines
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'.
--- builtin/repo.c | 8 ++++++++ t/t1900-repo.sh | 1 + 2 files changed, 9 insertions(+)
builtin/repo.c +8 -0
@@ -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 }, };
t/t1900-repo.sh +1 -0
@@ -10,6 +10,7 @@ REPO_INFO_KEYS=' layout.bare layout.shallow object.format + path.in-worktree references.format '
Signature · 1 line
2.52.0
Quoted 3 lines
Hi everyone,
Hi!
Quoted 2 lines
In this patch I am trying to provide the equivalent functionality of 'git rev-parse --is-inside-work-tree'
I'm not sure if it should be in git-repo-info. I mean, this information is more related to the current directory than the repository itself.
Quoted 6 lines
I found that I could either use the '
is_inside_work_tree' insidesetup.hwhich does not take anything , or use the 'is_inside_dir' fromdir.hand 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.
Makes sense, but this way you're re-writing is_inside_work_tree inside get_path_in_worktree but without using the is_inside_work_tree variable. I don't know what's the cost of doing this.
Something that I would question here if isn't it possible to make is_inside_work_tree accept a repository as parameter and then use it here.
Quoted 1 line
Although I am not sure if 'path.in-worktree' is the best name for it.
I think 'path.is-in-worktree' would be better.
Quoted 4 lines
Also, I did run
t1900-repo.shand it was failing one test case, which also ran with an ok when I added the new field toREPO_INFO_KEYS.
Everything above is not meant to be a commit message. This way, it should be placed after the scissors mark (---) or in a cover letter.
Quoted 6 lines
builtin/repo.c +6
-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 ; +} +
Quoted 8 lines
/*
repo_info_fieldskeys 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},
};
Ok, the process of adding a new field to repo-info is correct.
Quoted 11 lines
t/t1900-repo.sh +0
-0@@ -10,6 +10,7 @@ REPO_INFO_KEYS='layout.bare
layout.shallow
object.format
+ path.in-worktree
references.format
'
Test missing here.
Thanks for your interest in contributing to git-repo-info!
Quoted 3 lines
Makes sense, but this way you're re-writing
is_inside_work_treeinsideget_path_in_worktreebut without using theis_inside_work_treevariable. I don't know what's the cost of doing this.
I also dont know for sure, but the is_inside_work_tree in setup.c has a lazy cache ie a 'static int inside_work_tree' ... but this lazy cache as far as I understood, does not survive after a command run.
Quoted 2 lines
I'm not sure if it should be in git-repo-info. I mean, this information is more related to the current directory than the repository itself.
I see. Very well, I was searching for something small enough to count as a microproject. If I may ask, can you give some directions ? I though about doing the group key thing :
Quoted 2 lines
Use the category as key (e.g., git repo info layout would return all layout-related values)
But its already on the SoC 2026 Ideas , and I dont know if I should do it.
Quoted 3 lines
Something that I would question here if isn't it possible to make
is_inside_work_treeaccept a repository as parameter and then use it here.
Like change the function in setup.c ? wouldnt that break every call of is_inside_work_tree ? Or make a similar function , along with a lazy cache just for repo.c ?
Quoted 1 line
I think 'path.is-in-worktree' would be better.
Got it.
Quoted 7 lines
Also, I did run
t1900-repo.shand it was failing one test case, which also ran with an ok when I added the new field toREPO_INFO_KEYS.[1] : https://git.github.io/SoC-2026-Ideas/
Everything above is not meant to be a commit message. This way, it should be placed after the scissors mark (---) or in a cover letter.
Got it.
Quoted 1 line
Test missing here.
Yeah ... I missed that. Suppose we were adding this path.is-in-worktree to repo.c , then would the below test be sufficient ?
1: cd .git and then checking if path.is-in-worktree is false 2: cd .. and then checking if path.is-in-worktree is true
Quoted 1 line
Thanks for your interest in contributing to git-repo-info!
Thank you for the feedback and all the encouragement in the other thread as well.
Quoted 3 lines
I see. Very well, I was searching for something small enough to count as a microproject. If I may ask, can you give some directions ?
I don't think this is small enough to count as a microproject. A microproject is something simpler than that. See the microprojects page [1] for suggestions. They are more straightforward things that have more chances of being accepted quickly. And since having an accepted microproject is a mandatory step, you'll probably want it to be merged as soon as possible.
Quoted 7 lines
I though about doing the group key thing :
Quoted 2 lines
Use the category as key (e.g., git repo info layout would return all layout-related values)
But its already on the SoC 2026 Ideas , and I dont know if I should do it.
I think that this seems to be easy to do, but the reviewing process may take some time, so it would be better if you stick to a one of the selected microprojects [1].
Quoted 6 lines
Quoted 3 lines
Something that I would question here if isn't it possible to make
is_inside_work_treeaccept a repository as parameter and then use it here.Like change the function in
setup.c? wouldnt that break every call ofis_inside_work_tree?
Yeah, but then we would need to change all the calls to it, using the_repository at first. But I really don't know, I'll leave this discussion for more experienced people.
Quoted 4 lines
Yeah ... I missed that. Suppose we were adding this path.is-in-worktree to
repo.c, then would the below test be sufficient ?
1: cd .git and then checking if path.is-in-worktree is false 2: cd .. and then checking if path.is-in-worktree is true
You can take a look on how git rev-parse --is-inside-work-tree is being tested today and use it as a base, sincegit repo info path.is-inside-work-tree would return true or false in the same situations.
Quoted 6 lines · Lucas Seiki Oshiro
A
microproject is something simpler than that. See the microprojects page [1] for suggestions. They are more straightforward things that have more chances of being accepted quickly. And since having an accepted microproject is a mandatory step, you'll probably want it to be merged as soon as possible.
Microproject is to serve as a practice session for a new contributor to go through the patch submission + getting reviewed + sending polished version cycle. It does not have to result in a merge to the project, but it is essential to get reviewed and respond to reviews. How well you work with reviewers is the focus of the observation, and how complex the problem you tackle is is of much lessor importance.
Quoted 5 lines
I think that this seems to be easy to do, but the reviewing process may take some time, so it would be better if you stick to a one of the selected microprojects [1].
Is https://git.github.io/SoC-2026-Microprojects/ the latest? The above URL points at one a few years old.
Anyway, this list however might want a bit of updating.
* I personally feel that "run_command*() to internal call" is way too involved for a microproject. All the low-hanging frutis have already been picked in this area, I think. That is why this does not appear in the list of microproject ideas in more recent years.
* People seem to be finding more instances of "test -X" to replace with test_path_is_* helpers, so that would be fine to keep for now.
* Ditto for "do not place git upstream of a pipe".
* "Do not use signed int for collection of flag bits" may have outlived its usefulness, as it seems we are pushing more and more uses of enum for collection of flag bits.
Quoted 9 lines
Microproject is to serve as a practice session for a new contributor to go through the patch submission + getting reviewed + sending polished version cycle. It does not have to result in a merge to the project, but it is essential to get reviewed and respond to reviews. How well you work with reviewers is the focus of the observation, and how complex the problem you tackle is is of much lessor importance.
Quoted 8 lines
Quoted 5 lines
I think that this seems to be easy to do, but the reviewing process may take some time, so it would be better if you stick to a one of the selected microprojects [1].
Is https://git.github.io/SoC-2026-Microprojects/ the latest? The above URL points at one a few years old.
Oops. I've trusted by browser history and pasted the link that I during my application.
Thanks for correcting me.
Quoted 6 lines
I don't think this is small enough to count as a microproject. A microproject is something simpler than that. See the microprojects page [1] for suggestions. They are more straightforward things that have more chances of being accepted quickly. And since having an accepted microproject is a mandatory step, you'll probably want it to be merged as soon as possible.
My bad, by microproject I meant this :
Quoted 7 lines
GSoc 2026 Idea : Improve the new git repo command
Getting started: Build Git from source, experiment with git repo info and git repo structure commands, study the implementation in
builtin/repo.c, review the initial GSoC proposal and discussions, compare functionality with git rev-parse and identify gaps, and submit a *micro-patch to demonstrate familiarity with the codebase*.
I guess I misunderstood, I thought a relevant micropatch to the project idea area ( ie repo.c ) had to be submitted along with a general microproject.
I did submit one code microproject [1] and a doc-fix [2]
Quoted 3 lines
I think that this seems to be easy to do, but the reviewing process may take some time, so it would be better if you stick to a one of the selected microprojects.
Now since a microproject in the gsoc idea domain is not mandatory ... I think it would be okay to start on this ?
Regardless of it being fully reviewed, I feel like I should do some work on repo.c before writing a gsoc proposal. That way I can better formulate a timeline, maybe.
Quoted 3 lines
Yeah, but then we would need to change all the calls to it, using
the_repositoryat first. But I really don't know, I'll leave this discussion for more experienced people.
Alright.
Quoted 4 lines
You can take a look on how
git rev-parse --is-inside-work-treeis being tested today and use it as a base, sincegit repo info path.is-inside-work-treewould return true or false in the same situations.
Right, I dont know why I didn't do that, I will do that and send a patch v2
[1] : [email protected]
[2] : [email protected]
Hi Junio,
Quoted 16 lines · Junio C Hamano
Lucas Seiki Oshiro <[email protected]> writes:
Is https://git.github.io/SoC-2026-Microprojects/ the latest? The above URL points at one a few years old.Anyway, this list however might want a bit of updating.
* I personally feel that "run_command*() to internal call" is way too involved for a microproject. All the low-hanging frutis have already been picked in this area, I think. That is why this does not appear in the list of microproject ideas in more recent years.
* People seem to be finding more instances of "test -X" to replace with test_path_is_* helpers, so that would be fine to keep for now.
Quoted 6 lines
* Ditto for "do not place git upstream of a pipe".
* "Do not use signed int for collection of flag bits" may have outlived its usefulness, as it seems we are pushing more and more uses of enum for collection of flag bits.
Thank you for your suggestions. We've tried to tweak the micro-project page to remove the stale ones.
https://git.github.io/SoC-2026-Microprojects/
Feel free to let us know if you have any further suggestions.
--
Sivaraam