repo: add more path keys to git repo info
cover repo: add more path keys to git repo info
Series adds keys to git repo info.
Keys output paths of repository components:
* path.toplevel: repository tree.
* path.superproject-working-tree: superproject tree from submodules.
* path.objects: repository objects.
* path.hooks: repository hooks.
* path.index: repository index.
* path.grafts: repository grafts.
* path.git-prefix: prefix offset.
Keys support suffixes for format.
Commits contain documentation and tests.
K Jayatheerth (7):
repo: add path.toplevel with absolute and relative suffix formatting
repo: add path.superproject-working-tree with absolute and relative
suffixes
repo: add path.objects with absolute and relative suffix formatting
repo: add path.hooks with absolute and relative suffix formatting
repo: add path.index with absolute and relative suffix formatting
repo: add path.grafts with absolute and relative suffix formatting
repo: add path.git-prefix path key validation
Documentation/git-repo.adoc | 58 +++++++++++++ builtin/repo.c | 167 ++++++++++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 108 +++++++++++++++++++++++ 3 files changed, 333 insertions(+)
Signature · 1 line
2.55.GIT
PATCH 1/7 repo: add path.toplevel with absolute and relative suffix formatting
Scripts frequently need to find the root directory of a repository's working tree. Currently, this requires using git rev-parse --show-toplevel or inferring it from other path components.
Introduce path.toplevel.absolute and path.toplevel.relative keys to git repo info. This allows scripts to retrieve the top-level working tree path in a predictable, strictly formatted manner without relying on rev-parse.
If requested in a bare repository where no working tree exists, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 28 ++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.toplevel.absolute`:: + The canonical absolute path to the top-level directory of the + repository's working tree. Outputs an empty string if the repository + is bare. + +`path.toplevel.relative`:: + The path to the top-level directory of the repository's working + tree relative to the current working directory. Outputs an empty + string if the repository is bare. + `references.format`:: The reference storage format. The valid values are: +
builtin/repo.c +28 -0
@@ -121,6 +121,32 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) { +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, work_tree, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_toplevel_relative (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) { +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, work_tree, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_references_format (struct repository *repo,struct strbuf *buf) { strbuf_addstr(buf,
@@ -137,6 +163,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.toplevel.absolute", get_path_toplevel_absolute }, + { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format }, };
t/t1900-repo-info.sh +30 -0
@@ -213,4 +213,34 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.toplevel absolute and relative' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.toplevel.absolute=$ROOT" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=../" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.toplevel returns empty in a bare repository' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + echo "path.toplevel.absolute=" >expect && + git repo info path.toplevel.absolute >actual && + test_cmp expect actual + ) +' + test_done
Signature · 1 line
2.55.GIT
Re: [GSoC Patch 1/7] repo: add path.toplevel with absolute and relative suffix formatting
Quoted 10 lines
t/t1900-repo-info.sh +8
-0+test_expect_success 'path.toplevel absolute and relative' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + + ROOT="$(test-tool path-utils real_path ..)" &&
t/t1900-repo-info.sh test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ · line 233
Quoted 10 lines
t/t1900-repo-info.sh +10
-0+ + echo "path.toplevel.absolute=$ROOT" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=../" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +'
Question: why not use test_repo_info_path here?
Re: [GSoC Patch 1/7] repo: add path.toplevel with absolute and relative suffix formatting
Hey Lucas,
Quoted 15 lines · Lucas Seiki Oshiro
Quoted 15 lines
t/t1900-repo-info.sh +12
-0+test_expect_success 'path.toplevel absolute and relative' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.toplevel.absolute=$ROOT" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs &&
Quoted 8 lines
Quoted 6 lines
+
+ echo "path.toplevel.relative=../" >expect.rel &&
+ git repo info path.toplevel.relative >actual.rel &&
+test_cmpexpect.rel actual.rel
+ )
+'Question: why not use
test_repo_info_pathhere?
test_repo_info_path doesn't quite fit path.toplevel as the helper assumes an $expected_dir suffix and constructs $ROOT/$expected_dir and ../$expected_dir, while toplevel is $ROOT and ../, respectively, therefore I made this case different.
PATCH 2/7 repo: add path.superproject-working-tree with absolute and relative suffixes
In reply to K JayatheerthScripts working in multi-repository setups often need to identify the top-level working tree of a superproject from within a submodule. Currently, this is only exposed via git rev-parse --show-superproject-working-tree.
Introduce path.superproject-working-tree.absolute and path.superproject-working-tree.relative keys to git repo info. This exposes the core submodule context via a scriptable config-like key using standard format rules.
If requested when not inside a submodule, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 33 +++++++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.superproject-working-tree.absolute`:: + The canonical absolute path to the working tree root of the superproject + if the current repository is an initialized submodule. Outputs an empty + string if not in a submodule. + +`path.superproject-working-tree.relative`:: + The path to the working tree root of the superproject relative to the + current working directory if the current repository is an initialized + submodule. Outputs an empty string if not in a submodule. + `path.toplevel.absolute`:: The canonical absolute path to the top-level directory of the repository's working tree. Outputs an empty string if the repository
builtin/repo.c +33 -0
@@ -18,6 +18,7 @@#include "strbuf.h" #include "string-list.h" #include "shallow.h" +#include "submodule.h" #include "tree.h" #include "tree-walk.h" #include "utf8.h"
@@ -121,6 +122,36 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, superproject.buf, startup_info->prefix,PATH_FORMAT_CANONICAL ); +strbuf_release (&superproject); +return 0 ; +} + +static int get_path_superproject_relative(struct repository *repo UNUSED, struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, superproject.buf, startup_info->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&superproject); +return 0 ; +} +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) {const char *work_tree =repo_get_work_tree (repo);
@@ -163,6 +194,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.superproject-working-tree.absolute", get_path_superproject_absolute }, + { "path.superproject-working-tree.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute }, { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format },
t/t1900-repo-info.sh +34 -0
@@ -213,6 +213,40 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.superproject-working-tree absolute and relative' ' + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + cd sub && + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.superproject-working-tree.absolute=$ROOT" >expect.abs && + git repo info path.superproject-working-tree.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superproject-working-tree.relative=../" >expect.rel && + git repo info path.superproject-working-tree.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.superproject-working-tree returns empty when not in a submodule' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.superproject-working-tree.absolute=" >expect && + git repo info path.superproject-working-tree.absolute >actual && + test_cmp expect actual + ) +' + test_expect_success 'path.toplevel absolute and relative' ' test_when_finished "rm -rf repo" && git init repo &&
Signature · 1 line
2.55.GIT
PATCH 3/7 repo: add path.objects with absolute and relative suffix formatting
In reply to K JayatheerthTools and deployment hooks frequently query the location of the object database directory. Currently, this relies on legacy parsing methods or manually inspecting git rev-parse --git-path objects.
Introduce path.objects.absolute and path.objects.relative keys to git repo info. This allows tools to discover the object database location safely while natively adhering to active GIT_OBJECT_DIRECTORY environment variable overrides.
--- Documentation/git-repo.adoc | 9 +++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 7 +++++++ 3 files changed, 40 insertions(+)
Documentation/git-repo.adoc +9 -0
@@ -119,6 +119,15 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.objects.absolute`:: + The canonical absolute path to the repository's object database directory. + Respects the `GIT_OBJECT_DIRECTORY` environment override. + +`path.objects.relative`:: + The path to the repository's object database directory relative to the + current working directory. Respects the `GIT_OBJECT_DIRECTORY` + environment override. + `path.superproject-working-tree.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +24 -0
@@ -122,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_objects_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *obj_dir =repo_get_object_directory (repo); + +if (!obj_dir) +return error (_ ("unable to get object directory" )); + +format_path (buf, obj_dir, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_objects_relative (struct repository *repo,struct strbuf *buf) +{ +const char *obj_dir =repo_get_object_directory (repo); + +if (!obj_dir) +return error (_ ("unable to get object directory" )); + +format_path (buf, obj_dir, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} + static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -194,6 +216,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.objects.absolute", get_path_objects_absolute }, + { "path.objects.relative", get_path_objects_relative }, { "path.superproject-working-tree.absolute", get_path_superproject_absolute }, { "path.superproject-working-tree.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +7 -0
@@ -213,6 +213,13 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'objects standard' 'objects' '.git/objects' + +test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \ + 'custom-objects' \ + 'GIT_OBJECT_DIRECTORY="$ROOT/custom-objects" && export GIT_OBJECT_DIRECTORY && + mkdir -p "$ROOT/custom-objects"' + test_expect_success 'path.superproject-working-tree absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.55.GIT
PATCH 4/7 repo: add path.hooks with absolute and relative suffix formatting
In reply to K JayatheerthExternal tool integrations and validation systems need a stable way to identify where the repository hooks are stored. Currently, this involves relying on git rev-parse --git-path hooks or querying core.hooksPath manually.
Introduce path.hooks.absolute and path.hooks.relative keys to git repo info. This allows tools to discover the active hooks location natively, ensuring proper resolution regardless of whether Git is using the standard .git/hooks structure or a custom core.hooksPath setup.
--- Documentation/git-repo.adoc | 8 ++++++++ builtin/repo.c | 22 ++++++++++++++++++++++ t/t1900-repo-info.sh | 6 ++++++ 3 files changed, 36 insertions(+)
Documentation/git-repo.adoc +8 -0
@@ -119,6 +119,14 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.hooks.absolute`:: + The canonical absolute path to the repository's hooks directory. + Respects `core.hooksPath` configuration adjustments. + +`path.hooks.relative`:: + The path to the repository's hooks directory relative to the current + working directory. Respects `core.hooksPath` configuration adjustments. + `path.objects.absolute`:: The canonical absolute path to the repository's object database directory. Respects the `GIT_OBJECT_DIRECTORY` environment override.
builtin/repo.c +22 -0
@@ -122,6 +122,26 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf, startup_info->prefix,PATH_FORMAT_CANONICAL ); +strbuf_release (&hooks_path); +return 0 ; +} + +static int get_path_hooks_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf, startup_info->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&hooks_path); +return 0 ; +} +static int get_path_objects_absolute (struct repository *repo,struct strbuf *buf) {const char *obj_dir =repo_get_object_directory (repo);
@@ -216,6 +236,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.hooks.absolute", get_path_hooks_absolute }, + { "path.hooks.relative", get_path_hooks_relative }, { "path.objects.absolute", get_path_objects_absolute }, { "path.objects.relative", get_path_objects_relative }, { "path.superproject-working-tree.absolute", get_path_superproject_absolute },
t/t1900-repo-info.sh +6 -0
@@ -213,6 +213,12 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'hooks standard fallback' 'hooks' '.git/hooks' + +test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ + 'custom-hooks' \ + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' + test_repo_info_path 'objects standard' 'objects' '.git/objects' test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \
Signature · 1 line
2.55.GIT
PATCH 5/7 repo: add path.index with absolute and relative suffix formatting
In reply to K JayatheerthExternal script workflows and formatting layers require straightforward access to the location of the index staging file. Currently, tracking this necessitates a legacy call to git rev-parse --git-path index or --show-toplevel logic abstractions.
Introduce path.index.absolute and path.index.relative keys to git repo info. This allows tooling utilities to discover the active index context cleanly while scaling transparently with localized GIT_INDEX_FILE environment overrides.
--- Documentation/git-repo.adoc | 8 ++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 6 ++++++ 3 files changed, 38 insertions(+)
Documentation/git-repo.adoc +8 -0
@@ -127,6 +127,14 @@ values that they return: The path to the repository's hooks directory relative to the current working directory. Respects `core.hooksPath` configuration adjustments. +`path.index.absolute`:: + The canonical absolute path to the repository's current index file. + Respects the `GIT_INDEX_FILE` environment override. + +`path.index.relative`:: + The path to the repository's current index file relative to the current + working directory. Respects the `GIT_INDEX_FILE` environment override. + `path.objects.absolute`:: The canonical absolute path to the repository's object database directory. Respects the `GIT_OBJECT_DIRECTORY` environment override.
builtin/repo.c +24 -0
@@ -142,6 +142,28 @@ static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_index_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_index_relative (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_objects_absolute (struct repository *repo,struct strbuf *buf) {const char *obj_dir =repo_get_object_directory (repo);
@@ -238,6 +260,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.gitdir.relative", get_path_gitdir_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, + { "path.index.absolute", get_path_index_absolute }, + { "path.index.relative", get_path_index_relative }, { "path.objects.absolute", get_path_objects_absolute }, { "path.objects.relative", get_path_objects_relative }, { "path.superproject-working-tree.absolute", get_path_superproject_absolute },
t/t1900-repo-info.sh +6 -0
@@ -219,6 +219,12 @@ test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ 'custom-hooks' \ 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' +test_repo_info_path 'index standard' 'index' '.git/index' + +test_repo_info_path 'index with GIT_INDEX_FILE override' 'index' \ + 'custom-index-file' \ + 'GIT_INDEX_FILE="$ROOT/custom-index-file" && export GIT_INDEX_FILE' + test_repo_info_path 'objects standard' 'objects' '.git/objects' test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \
Signature · 1 line
2.55.GIT
PATCH 6/7 repo: add path.grafts with absolute and relative suffix formatting
In reply to K JayatheerthExternal toolchains managing specialized history rewrites or legacy history splices require access to the location of the repository grafts file. Currently, this requires a legacy call to git rev-parse --git-path info/grafts.
Introduce path.grafts.absolute and path.grafts.relative keys to git repo info. This allows scripting layers to query the active grafts context cleanly while scaling transparently with active GIT_GRAFT_FILE environment variable overrides.
--- Documentation/git-repo.adoc | 8 ++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 6 ++++++ 3 files changed, 38 insertions(+)
Documentation/git-repo.adoc +8 -0
@@ -119,6 +119,14 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.grafts.absolute`:: + The canonical absolute path to the repository grafts file. + Respects the `GIT_GRAFT_FILE` environment override. + +`path.grafts.relative`:: + The path to the repository grafts file relative to the current working + directory. Respects the `GIT_GRAFT_FILE` environment override. + `path.hooks.absolute`:: The canonical absolute path to the repository's hooks directory. Respects `core.hooksPath` configuration adjustments.
builtin/repo.c +24 -0
@@ -122,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_grafts_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_grafts_relative (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf hooks_path =STRBUF_INIT ;
@@ -258,6 +280,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.grafts.absolute", get_path_grafts_absolute }, + { "path.grafts.relative", get_path_grafts_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, { "path.index.absolute", get_path_index_absolute },
t/t1900-repo-info.sh +6 -0
@@ -213,6 +213,12 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'grafts standard' 'grafts' '.git/info/grafts' + +test_repo_info_path 'grafts with GIT_GRAFT_FILE override' 'grafts' \ + 'custom-graft-file' \ + 'GIT_GRAFT_FILE="$ROOT/custom-graft-file" && export GIT_GRAFT_FILE' + test_repo_info_path 'hooks standard fallback' 'hooks' '.git/hooks' test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
Signature · 1 line
2.55.GIT
PATCH 7/7 repo: add path.git-prefix path key validation
In reply to K JayatheerthScripts and command-line prompt integrations frequently need to know their relative depth inside a repository working tree layout. Currently, this is retrieved using git rev-parse --show-prefix.
Introduce the path.git-prefix key to git repo info. This mirrors the prefix location tracking framework as a standalone key, returning the exact relative path offset complete with a trailing slash, or an empty string if run directly at the repository working tree root.
--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 12 ++++++++++++ t/t1900-repo-info.sh | 19 +++++++++++++++++++ 3 files changed, 36 insertions(+)
Documentation/git-repo.adoc +5 -0
@@ -113,6 +113,11 @@ values that they return: The path to the Git repository's common directory relative to the current working directory. +`path.git-prefix`:: + The relative path from the top-level directory of the working tree to + the current working directory (including a trailing slash). Outputs an + empty string if executed at the root of the working tree. + `path.gitdir.absolute`:: The canonical absolute path to the Git repository directory (the `.git` directory).
builtin/repo.c +12 -0
@@ -1,3 +1,4 @@ +#include "compat/posix.h" #define USE_THE_REPOSITORY_VARIABLE #include "builtin.h"
@@ -100,6 +101,16 @@ static int get_path_commondir_relative(struct repository *repo, struct strbuf *breturn 0 ; } +static int get_path_git_prefix(struct repository *repo UNUSED, struct strbuf *buf) +{ +/* +* startup_info->prefix is NULL if we are at the working tree root. +* We add an empty string to ensure the buffer is cleanly initialized. +*/ +strbuf_addstr (buf, startup_info->prefix ? startup_info->prefix :"" ); +return 0 ; +} +static int get_path_gitdir_absolute (struct repository *repo,struct strbuf *buf) {const char *git_dir =repo_get_git_dir (repo);
@@ -278,6 +289,7 @@ static const struct repo_info_field repo_info_field[] = { { "object.format", get_object_format }, { "path.commondir.absolute", get_path_commondir_absolute }, { "path.commondir.relative", get_path_commondir_relative }, + { "path.git-prefix", get_path_git_prefix }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, { "path.grafts.absolute", get_path_grafts_absolute },
t/t1900-repo-info.sh +19 -0
@@ -207,6 +207,25 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.git-prefix at root and in a subdirectory' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + echo "path.git-prefix=" >expect.root && + git repo info path.git-prefix >actual.root && + test_cmp expect.root actual.root && + + mkdir -p sub/dir && + cd sub/dir && + + echo "path.git-prefix=sub/dir/" >expect.sub && + git repo info path.git-prefix >actual.sub && + test_cmp expect.sub actual.sub + ) +' + test_repo_info_path 'gitdir standard' 'gitdir' '.git' test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
Signature · 1 line
2.55.GIT
Re: [GSoC Patch 7/7] repo: add path.git-prefix path key validation
builtin/repo.c line 3
Quoted 8 lines · K Jayatheerth
builtin/repo.c +1
-0@@ -1,3 +1,4 @@ +#include "compat/posix.h" #define USE_THE_REPOSITORY_VARIABLE #include "builtin.h"
The first include must be <git-compat-util.h> or common include files that include <git-compat-util.h> as the first thing, like <builtin.h>.
As the file already includes <builtin.h>, extra inclusion of <compat/posix.h> before everything else is an absolute no-no.
By the way, I do not see any "validation" in the patch as the title claims. Perhaps retitle it to "repo: add path.git-prefix key" or something simpler like that?
Re: [GSoC Patch 7/7] repo: add path.git-prefix path key validation
Hey Junio,
Quoted 16 lines · Junio C Hamano
builtin/repo.c line 3
Quoted 8 lines · K Jayatheerth
builtin/repo.c +1
-0@@ -1,3 +1,4 @@ +#include "compat/posix.h" #define USE_THE_REPOSITORY_VARIABLE #include "builtin.h" The first include must be <
git-compat-util.h> or common include files that include <git-compat-util.h> as the first thing, like <builtin.h>.
Quoted 3 lines
As the file already includes <
builtin.h>, extra inclusion of <compat/posix.h> before everything else is an absolute no-no.
Oh no, that's just my editor adding headers automatically. Thanks for pointing this out, I will fix it.
Quoted 4 lines
By the way, I do not see any "validation" in the patch as the title claims. Perhaps retitle it to "repo: add path.git-prefix key" or something simpler like that?
True, I will correct that as well.
Regards,
- K Jayatheerth
v2 cover repo: add more path keys to git repo info
In reply to K JayatheerthSeries adds keys to git repo info.
Keys output paths of repository components:
* path.toplevel: repository tree.
* path.superproject-working-tree: superproject tree from submodules.
* path.objects: repository objects.
* path.hooks: repository hooks.
* path.index: repository index.
* path.grafts: repository grafts.
* path.git-prefix: prefix offset.
Keys support suffixes for format.
Commits contain documentation and tests.
K Jayatheerth (7):
repo: add path.toplevel with absolute and relative suffix formatting
repo: add path.superproject-working-tree with absolute and relative
suffixes
repo: add path.objects with absolute and relative suffix formatting
repo: add path.hooks with absolute and relative suffix formatting
repo: add path.index with absolute and relative suffix formatting
repo: add path.grafts with absolute and relative suffix formatting
repo: add path.git-prefix path key
Documentation/git-repo.adoc | 58 +++++++++++++ builtin/repo.c | 166 ++++++++++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 108 +++++++++++++++++++++++ 3 files changed, 332 insertions(+)
Signature · 1 line
2.55.GIT
PATCH v2 1/7 repo: add path.toplevel with absolute and relative suffix formatting
Scripts frequently need to find the root directory of a repository's working tree. Currently, this requires using git rev-parse --show-toplevel or inferring it from other path components.
Introduce path.toplevel.absolute and path.toplevel.relative keys to git repo info. This allows scripts to retrieve the top-level working tree path in a predictable, strictly formatted manner without relying on rev-parse.
If requested in a bare repository where no working tree exists, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 28 ++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.toplevel.absolute`:: + The canonical absolute path to the top-level directory of the + repository's working tree. Outputs an empty string if the repository + is bare. + +`path.toplevel.relative`:: + The path to the top-level directory of the repository's working + tree relative to the current working directory. Outputs an empty + string if the repository is bare. + `references.format`:: The reference storage format. The valid values are: +
builtin/repo.c +28 -0
@@ -121,6 +121,32 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) { +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, work_tree, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_toplevel_relative (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) { +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, work_tree, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_references_format (struct repository *repo,struct strbuf *buf) { strbuf_addstr(buf,
@@ -137,6 +163,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.toplevel.absolute", get_path_toplevel_absolute }, + { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format }, };
t/t1900-repo-info.sh +30 -0
@@ -213,4 +213,34 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.toplevel absolute and relative' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.toplevel.absolute=$ROOT" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=../" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.toplevel returns empty in a bare repository' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + echo "path.toplevel.absolute=" >expect && + git repo info path.toplevel.absolute >actual && + test_cmp expect actual + ) +' + test_done
Signature · 1 line
2.55.GIT
PATCH v2 2/7 repo: add path.superproject-working-tree with absolute and relative suffixes
In reply to K JayatheerthScripts working in multi-repository setups often need to identify the top-level working tree of a superproject from within a submodule. Currently, this is only exposed via git rev-parse --show-superproject-working-tree.
Introduce path.superproject-working-tree.absolute and path.superproject-working-tree.relative keys to git repo info. This exposes the core submodule context via a scriptable config-like key using standard format rules.
If requested when not inside a submodule, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 33 +++++++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.superproject-working-tree.absolute`:: + The canonical absolute path to the working tree root of the superproject + if the current repository is an initialized submodule. Outputs an empty + string if not in a submodule. + +`path.superproject-working-tree.relative`:: + The path to the working tree root of the superproject relative to the + current working directory if the current repository is an initialized + submodule. Outputs an empty string if not in a submodule. + `path.toplevel.absolute`:: The canonical absolute path to the top-level directory of the repository's working tree. Outputs an empty string if the repository
builtin/repo.c +33 -0
@@ -18,6 +18,7 @@#include "strbuf.h" #include "string-list.h" #include "shallow.h" +#include "submodule.h" #include "tree.h" #include "tree-walk.h" #include "utf8.h"
@@ -121,6 +122,36 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, superproject.buf, startup_info->prefix,PATH_FORMAT_CANONICAL ); +strbuf_release (&superproject); +return 0 ; +} + +static int get_path_superproject_relative(struct repository *repo UNUSED, struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, superproject.buf, startup_info->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&superproject); +return 0 ; +} +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) {const char *work_tree =repo_get_work_tree (repo);
@@ -163,6 +194,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.superproject-working-tree.absolute", get_path_superproject_absolute }, + { "path.superproject-working-tree.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute }, { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format },
t/t1900-repo-info.sh +34 -0
@@ -213,6 +213,40 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.superproject-working-tree absolute and relative' ' + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + cd sub && + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.superproject-working-tree.absolute=$ROOT" >expect.abs && + git repo info path.superproject-working-tree.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superproject-working-tree.relative=../" >expect.rel && + git repo info path.superproject-working-tree.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.superproject-working-tree returns empty when not in a submodule' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.superproject-working-tree.absolute=" >expect && + git repo info path.superproject-working-tree.absolute >actual && + test_cmp expect actual + ) +' + test_expect_success 'path.toplevel absolute and relative' ' test_when_finished "rm -rf repo" && git init repo &&
Signature · 1 line
2.55.GIT
PATCH v2 3/7 repo: add path.objects with absolute and relative suffix formatting
In reply to K JayatheerthTools and deployment hooks frequently query the location of the object database directory. Currently, this relies on legacy parsing methods or manually inspecting git rev-parse --git-path objects.
Introduce path.objects.absolute and path.objects.relative keys to git repo info. This allows tools to discover the object database location safely while natively adhering to active GIT_OBJECT_DIRECTORY environment variable overrides.
--- Documentation/git-repo.adoc | 9 +++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 7 +++++++ 3 files changed, 40 insertions(+)
Documentation/git-repo.adoc +9 -0
@@ -119,6 +119,15 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.objects.absolute`:: + The canonical absolute path to the repository's object database directory. + Respects the `GIT_OBJECT_DIRECTORY` environment override. + +`path.objects.relative`:: + The path to the repository's object database directory relative to the + current working directory. Respects the `GIT_OBJECT_DIRECTORY` + environment override. + `path.superproject-working-tree.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +24 -0
@@ -122,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_objects_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *obj_dir =repo_get_object_directory (repo); + +if (!obj_dir) +return error (_ ("unable to get object directory" )); + +format_path (buf, obj_dir, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_objects_relative (struct repository *repo,struct strbuf *buf) +{ +const char *obj_dir =repo_get_object_directory (repo); + +if (!obj_dir) +return error (_ ("unable to get object directory" )); + +format_path (buf, obj_dir, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} + static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -194,6 +216,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.objects.absolute", get_path_objects_absolute }, + { "path.objects.relative", get_path_objects_relative }, { "path.superproject-working-tree.absolute", get_path_superproject_absolute }, { "path.superproject-working-tree.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +7 -0
@@ -213,6 +213,13 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'objects standard' 'objects' '.git/objects' + +test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \ + 'custom-objects' \ + 'GIT_OBJECT_DIRECTORY="$ROOT/custom-objects" && export GIT_OBJECT_DIRECTORY && + mkdir -p "$ROOT/custom-objects"' + test_expect_success 'path.superproject-working-tree absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.55.GIT
PATCH v2 4/7 repo: add path.hooks with absolute and relative suffix formatting
In reply to K JayatheerthExternal tool integrations and validation systems need a stable way to identify where the repository hooks are stored. Currently, this involves relying on git rev-parse --git-path hooks or querying core.hooksPath manually.
Introduce path.hooks.absolute and path.hooks.relative keys to git repo info. This allows tools to discover the active hooks location natively, ensuring proper resolution regardless of whether Git is using the standard .git/hooks structure or a custom core.hooksPath setup.
--- Documentation/git-repo.adoc | 8 ++++++++ builtin/repo.c | 22 ++++++++++++++++++++++ t/t1900-repo-info.sh | 6 ++++++ 3 files changed, 36 insertions(+)
Documentation/git-repo.adoc +8 -0
@@ -119,6 +119,14 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.hooks.absolute`:: + The canonical absolute path to the repository's hooks directory. + Respects `core.hooksPath` configuration adjustments. + +`path.hooks.relative`:: + The path to the repository's hooks directory relative to the current + working directory. Respects `core.hooksPath` configuration adjustments. + `path.objects.absolute`:: The canonical absolute path to the repository's object database directory. Respects the `GIT_OBJECT_DIRECTORY` environment override.
builtin/repo.c +22 -0
@@ -122,6 +122,26 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf, startup_info->prefix,PATH_FORMAT_CANONICAL ); +strbuf_release (&hooks_path); +return 0 ; +} + +static int get_path_hooks_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf, startup_info->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&hooks_path); +return 0 ; +} +static int get_path_objects_absolute (struct repository *repo,struct strbuf *buf) {const char *obj_dir =repo_get_object_directory (repo);
@@ -216,6 +236,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.hooks.absolute", get_path_hooks_absolute }, + { "path.hooks.relative", get_path_hooks_relative }, { "path.objects.absolute", get_path_objects_absolute }, { "path.objects.relative", get_path_objects_relative }, { "path.superproject-working-tree.absolute", get_path_superproject_absolute },
t/t1900-repo-info.sh +6 -0
@@ -213,6 +213,12 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'hooks standard fallback' 'hooks' '.git/hooks' + +test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ + 'custom-hooks' \ + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' + test_repo_info_path 'objects standard' 'objects' '.git/objects' test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \
Signature · 1 line
2.55.GIT
PATCH v2 5/7 repo: add path.index with absolute and relative suffix formatting
In reply to K JayatheerthExternal script workflows and formatting layers require straightforward access to the location of the index staging file. Currently, tracking this necessitates a legacy call to git rev-parse --git-path index or --show-toplevel logic abstractions.
Introduce path.index.absolute and path.index.relative keys to git repo info. This allows tooling utilities to discover the active index context cleanly while scaling transparently with localized GIT_INDEX_FILE environment overrides.
--- Documentation/git-repo.adoc | 8 ++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 6 ++++++ 3 files changed, 38 insertions(+)
Documentation/git-repo.adoc +8 -0
@@ -127,6 +127,14 @@ values that they return: The path to the repository's hooks directory relative to the current working directory. Respects `core.hooksPath` configuration adjustments. +`path.index.absolute`:: + The canonical absolute path to the repository's current index file. + Respects the `GIT_INDEX_FILE` environment override. + +`path.index.relative`:: + The path to the repository's current index file relative to the current + working directory. Respects the `GIT_INDEX_FILE` environment override. + `path.objects.absolute`:: The canonical absolute path to the repository's object database directory. Respects the `GIT_OBJECT_DIRECTORY` environment override.
builtin/repo.c +24 -0
@@ -142,6 +142,28 @@ static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_index_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_index_relative (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_objects_absolute (struct repository *repo,struct strbuf *buf) {const char *obj_dir =repo_get_object_directory (repo);
@@ -238,6 +260,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.gitdir.relative", get_path_gitdir_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, + { "path.index.absolute", get_path_index_absolute }, + { "path.index.relative", get_path_index_relative }, { "path.objects.absolute", get_path_objects_absolute }, { "path.objects.relative", get_path_objects_relative }, { "path.superproject-working-tree.absolute", get_path_superproject_absolute },
t/t1900-repo-info.sh +6 -0
@@ -219,6 +219,12 @@ test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ 'custom-hooks' \ 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' +test_repo_info_path 'index standard' 'index' '.git/index' + +test_repo_info_path 'index with GIT_INDEX_FILE override' 'index' \ + 'custom-index-file' \ + 'GIT_INDEX_FILE="$ROOT/custom-index-file" && export GIT_INDEX_FILE' + test_repo_info_path 'objects standard' 'objects' '.git/objects' test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \
Signature · 1 line
2.55.GIT
Re: [GSoC Patch v2 5/7] repo: add path.index with absolute and relative suffix formatting
Quoted 5 lines
Introduce
path.index.absoluteandpath.index.relativekeys togit repo info. This allows tooling utilities to discover the active index context cleanly while scaling transparently with localizedGIT_INDEX_FILEenvironment overrides.
Note that bare repositories doesn't need to have an index file. Maybe it would be better if you return an empty value in those cases.
Re: [GSoC Patch v2 5/7] repo: add path.index with absolute and relative suffix formatting
Hey Lucas and Junio,
Quoted 9 lines · Lucas Seiki Oshiro
Quoted 6 lines
Introduce
path.index.absoluteandpath.index.relativekeys togit repo info. This allows tooling utilities to discover the active index context cleanly while scaling transparently with localizedGIT_INDEX_FILEenvironment overrides.Note that bare repositories doesn't need to have an index file. Maybe it would be better if you return an empty value in those cases.
I wanted to follow up on this series.
I am a bit unsure about how to proceed with this specific case, especially after Junio's feedback on the grafts patch.
For path.grafts, Junio mentioned that we should return the expected path even if the file doesn't exist yet,
so scripts know where to write it. I am wondering if a similar logic should apply to path.index in bare repositories.
While bare repos don't have a working tree (and therefore usually no index), scripts do sometimes set GIT_INDEX_FILE to build temporary indexes for tree manipulation.
Should we strictly return an empty string for bare repos (similar to how we handle path.toplevel),
or should we return the default <gitdir>/index path in case a script wants to know where it would be?
If this confusion is clear I can send a new version!
Thank you,
Regards
- K Jayatheerth
Re: [GSoC Patch v2 5/7] repo: add path.index with absolute and relative suffix formatting
Quoted 8 lines · K Jayatheerth
While bare repos don't have a working tree (and therefore usually no index), scripts do sometimes set
GIT_INDEX_FILEto build temporary indexes for tree manipulation.Should we strictly return an empty string for bare repos (similar to how we handle path.toplevel),
or should we return the default <gitdir>/index path in case a script wants to know where it would be?
The path to the top level can be an empty string if you are already at the top level, which is neither an error nor an unusual condition. I do not understand the contrast you are drawing here.
I expect "tell me where the index is" to return <gitdir>/index, $GIT_INDEX_FILE, or whatever Git sets during setup. In other words, whatever repo's '.index_file' member holds when control reaches repo_read_index().
If a script checks that location and finds no file, that is the natural way to learn there is no index.
PATCH v2 6/7 repo: add path.grafts with absolute and relative suffix formatting
In reply to K JayatheerthExternal toolchains managing specialized history rewrites or legacy history splices require access to the location of the repository grafts file. Currently, this requires a legacy call to git rev-parse --git-path info/grafts.
Introduce path.grafts.absolute and path.grafts.relative keys to git repo info. This allows scripting layers to query the active grafts context cleanly while scaling transparently with active GIT_GRAFT_FILE environment variable overrides.
--- Documentation/git-repo.adoc | 8 ++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 6 ++++++ 3 files changed, 38 insertions(+)
Documentation/git-repo.adoc +8 -0
@@ -119,6 +119,14 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.grafts.absolute`:: + The canonical absolute path to the repository grafts file. + Respects the `GIT_GRAFT_FILE` environment override. + +`path.grafts.relative`:: + The path to the repository grafts file relative to the current working + directory. Respects the `GIT_GRAFT_FILE` environment override. + `path.hooks.absolute`:: The canonical absolute path to the repository's hooks directory. Respects `core.hooksPath` configuration adjustments.
builtin/repo.c +24 -0
@@ -122,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_grafts_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_grafts_relative (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf hooks_path =STRBUF_INIT ;
@@ -258,6 +280,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.grafts.absolute", get_path_grafts_absolute }, + { "path.grafts.relative", get_path_grafts_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, { "path.index.absolute", get_path_index_absolute },
t/t1900-repo-info.sh +6 -0
@@ -213,6 +213,12 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'grafts standard' 'grafts' '.git/info/grafts' + +test_repo_info_path 'grafts with GIT_GRAFT_FILE override' 'grafts' \ + 'custom-graft-file' \ + 'GIT_GRAFT_FILE="$ROOT/custom-graft-file" && export GIT_GRAFT_FILE' + test_repo_info_path 'hooks standard fallback' 'hooks' '.git/hooks' test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
Signature · 1 line
2.55.GIT
Re: [GSoC Patch v2 6/7] repo: add path.grafts with absolute and relative suffix formatting
Quoted 5 lines
Introduce
path.grafts.absoluteandpath.grafts.relativekeys togit repo info. This allows scripting layers to query the active grafts context cleanly while scaling transparently with activeGIT_GRAFT_FILEenvironment variable overrides.
I ran git repo info path.grafts.relative in a repository with no grafts file, and it returned .git/info/grafts, which obviously doesn't exist.
Wouldn't it be better if we check if that file exists before returning this value?
Re: [GSoC Patch v2 6/7] repo: add path.grafts with absolute and relative suffix formatting
Quoted 11 lines · Lucas Seiki Oshiro
Quoted 4 lines
Introduce
path.grafts.absoluteandpath.grafts.relativekeys togit repo info. This allows scripting layers to query the active grafts context cleanly while scaling transparently with activeGIT_GRAFT_FILEenvironment variable overrides.I ran
git repo info path.grafts.relativein a repository with nograftsfile, and it returned.git/info/grafts, which obviously doesn't exist.Wouldn't it be better if we check if that file exists before returning this value?
That is an interesting question, but I think it depends on who is querying and for what purpose.
If a script is asking where to write the file, then the author wants to know where the file is supposed to be, even if no such file exists yet. Since the file format is public, they are free to write their own tools to manipulate it.
Thanks.
Re: [GSoC Patch v2 6/7] repo: add path.grafts with absolute and relative suffix formatting
Hey Lucas and Junio,
Quoted 18 lines · Junio C Hamano
Quoted 11 lines · Lucas Seiki Oshiro
Quoted 4 lines
Introduce
path.grafts.absoluteandpath.grafts.relativekeys togit repo info. This allows scripting layers to query the active grafts context cleanly while scaling transparently with activeGIT_GRAFT_FILEenvironment variable overrides.I ran
git repo info path.grafts.relativein a repository with nograftsfile, and it returned.git/info/grafts, which obviously doesn't exist.Wouldn't it be better if we check if that file exists before returning this value?
That is an interesting question, but I think it depends on who is querying and for what purpose.
Quoted 6 lines
If a script is asking where to write the file, then the author wants to know where the file is supposed to be, even if no such file exists yet. Since the file format is public, they are free to write their own tools to manipulate it.
Thanks.
That's tough.
I think I align with Junio here.
I just used rev-parse as my compass to work on this command. Just to clarify
Should I send a v3 changing something?
Regards,
- K Jayatheerth
PATCH v2 7/7 repo: add path.git-prefix path key
In reply to K JayatheerthScripts and command-line prompt integrations frequently need to know their relative depth inside a repository working tree layout. Currently, this is retrieved using git rev-parse --show-prefix.
Introduce the path.git-prefix key to git repo info. This mirrors the prefix location tracking framework as a standalone key, returning the exact relative path offset complete with a trailing slash, or an empty string if run directly at the repository working tree root.
--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 11 +++++++++++ t/t1900-repo-info.sh | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+)
Documentation/git-repo.adoc +5 -0
@@ -113,6 +113,11 @@ values that they return: The path to the Git repository's common directory relative to the current working directory. +`path.git-prefix`:: + The relative path from the top-level directory of the working tree to + the current working directory (including a trailing slash). Outputs an + empty string if executed at the root of the working tree. + `path.gitdir.absolute`:: The canonical absolute path to the Git repository directory (the `.git` directory).
builtin/repo.c +11 -0
@@ -100,6 +100,16 @@ static int get_path_commondir_relative(struct repository *repo, struct strbuf *breturn 0 ; } +static int get_path_git_prefix(struct repository *repo UNUSED, struct strbuf *buf) +{ +/* +* startup_info->prefix is NULL if we are at the working tree root. +* We add an empty string to ensure the buffer is cleanly initialized. +*/ +strbuf_addstr (buf, startup_info->prefix ? startup_info->prefix :"" ); +return 0 ; +} +static int get_path_gitdir_absolute (struct repository *repo,struct strbuf *buf) {const char *git_dir =repo_get_git_dir (repo);
@@ -278,6 +288,7 @@ static const struct repo_info_field repo_info_field[] = { { "object.format", get_object_format }, { "path.commondir.absolute", get_path_commondir_absolute }, { "path.commondir.relative", get_path_commondir_relative }, + { "path.git-prefix", get_path_git_prefix }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, { "path.grafts.absolute", get_path_grafts_absolute },
t/t1900-repo-info.sh +19 -0
@@ -207,6 +207,25 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.git-prefix at root and in a subdirectory' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + echo "path.git-prefix=" >expect.root && + git repo info path.git-prefix >actual.root && + test_cmp expect.root actual.root && + + mkdir -p sub/dir && + cd sub/dir && + + echo "path.git-prefix=sub/dir/" >expect.sub && + git repo info path.git-prefix >actual.sub && + test_cmp expect.sub actual.sub + ) +' + test_repo_info_path 'gitdir standard' 'gitdir' '.git' test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
Signature · 1 line
2.55.GIT
v3 cover repo: add more path keys to git repo info
In reply to K JayatheerthSeries adds keys to git repo info.
Keys output paths of repository components:
* path.toplevel: repository tree.
* path.superproject-working-tree: superproject tree from submodules.
* path.objects: repository objects.
* path.hooks: repository hooks.
* path.index: repository index.
* path.grafts: repository grafts.
* path.git-prefix: prefix offset.
Keys support suffixes for format.
Commits contain documentation and tests.
Changes since v2:
* path.index: no functional change; documented that the returned path reflects the default/configured index location even in a bare repository or when the file doesn't exist yet, and added a test covering path.index inside a bare repository.
* path.grafts: no functional change; documented that the path is returned even if the grafts file doesn't currently exist on disk.
* path.git-prefix: no change since v2 (already addressed the stray include and misleading "validation" in the subject).
K Jayatheerth (7):
repo: add path.toplevel with absolute and relative suffix formatting
repo: add path.superproject-working-tree with absolute and relative
suffixes
repo: add path.objects with absolute and relative suffix formatting
repo: add path.hooks with absolute and relative suffix formatting
repo: add path.index with absolute and relative suffix formatting
repo: add path.grafts with absolute and relative suffix formatting
repo: add path.git-prefix path key
Documentation/git-repo.adoc | 64 ++++++++++++++ builtin/repo.c | 166 ++++++++++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 125 +++++++++++++++++++++++++++ 3 files changed, 355 insertions(+)
Range-diff against v2:
1: 297d625ea1 = 1: 297d625ea1 repo: add path.toplevel with absolute and relative suffix formatting
2: 8a84aaa2a1 = 2: 8a84aaa2a1 repo: add path.superproject-working-tree with absolute and relative suffixes
3: 159166ce85 = 3: 159166ce85 repo: add path.objects with absolute and relative suffix formatting
4: ff5e382043 = 4: ff5e382043 repo: add path.hooks with absolute and relative suffix formatting
5: d906735e3d ! 5: 917d3a5076 repo: add path.index with absolute and relative suffix formatting
@@ Documentation/git-repo.adoc: values that they return:
+`path.index.absolute`::
+ The canonical absolute path to the repository's current index file.
-+ Respects the `GIT_INDEX_FILE` environment override.
++ Respects the `GIT_INDEX_FILE` environment override. The returned path
++ reflects the configured/default index location regardless of whether the
++ repository is bare or whether the file currently exists.
+
+`path.index.relative`::
+ The path to the repository's current index file relative to the current
+ working directory. Respects the `GIT_INDEX_FILE` environment override.
++ The returned path reflects the configured/default index location regardless
++ of whether the repository is bare or whether the file currently exists.
+
`path.objects.absolute`::
The canonical absolute path to the repository's object database directory.
@@ t/t1900-repo-info.sh: test_repo_info_path 'hooks with core.hooksPath override' '
+test_repo_info_path 'index with GIT_INDEX_FILE override' 'index' \
+ 'custom-index-file' \
+ 'GIT_INDEX_FILE="$ROOT/custom-index-file" && export GIT_INDEX_FILE'
++
++test_expect_success 'path.index in a bare repository returns default index location' '
++ test_when_finished "rm -rf bare.git" &&
++ git init --bare bare.git &&
++ (
++ cd bare.git &&
++ ROOT="$(test-tool path-utils real_path .)" &&
++
++ echo "path.index.absolute=$ROOT/index" >expect.abs &&
++ git repo info path.index.absolute >actual.abs &&
++ test_cmp expect.abs actual.abs &&
++
++ echo "path.index.relative=index" >expect.rel &&
++ git repo info path.index.relative >actual.rel &&
++ test_cmp expect.rel actual.rel
++ )
++'
+
test_repo_info_path 'objects standard' 'objects' '.git/objects'6: 2d21f9536c ! 6: d47a5701d5 repo: add path.grafts with absolute and relative suffix formatting
@@ Documentation/git-repo.adoc: values that they return:
+path.grafts.absolute::
+ The canonical absolute path to the repository grafts file.
-+ Respects the GIT_GRAFT_FILE environment override.
++ Respects the GIT_GRAFT_FILE environment override. The path is returned
++ regardless of whether the file currently exists on disk.
+
+path.grafts.relative::
+ The path to the repository grafts file relative to the current working
-+ directory. Respects the GIT_GRAFT_FILE environment override.
++ directory. Respects the GIT_GRAFT_FILE environment override. The path
++ is returned regardless of whether the file currently exists on disk.
+
path.hooks.absolute::
The canonical absolute path to the repository's hooks directory.
7: 1dbe191176 = 7: fd90b0b3b5 repo: add path.git-prefix path key
Signature · 1 line
2.55.GIT
PATCH v3 1/7 repo: add path.toplevel with absolute and relative suffix formatting
Scripts frequently need to find the root directory of a repository's working tree. Currently, this requires using git rev-parse --show-toplevel or inferring it from other path components.
Introduce path.toplevel.absolute and path.toplevel.relative keys to git repo info. This allows scripts to retrieve the top-level working tree path in a predictable, strictly formatted manner without relying on rev-parse.
If requested in a bare repository where no working tree exists, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 28 ++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.toplevel.absolute`:: + The canonical absolute path to the top-level directory of the + repository's working tree. Outputs an empty string if the repository + is bare. + +`path.toplevel.relative`:: + The path to the top-level directory of the repository's working + tree relative to the current working directory. Outputs an empty + string if the repository is bare. + `references.format`:: The reference storage format. The valid values are: +
builtin/repo.c +28 -0
@@ -121,6 +121,32 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) { +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, work_tree, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_toplevel_relative (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) { +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, work_tree, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_references_format (struct repository *repo,struct strbuf *buf) { strbuf_addstr(buf,
@@ -137,6 +163,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.toplevel.absolute", get_path_toplevel_absolute }, + { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format }, };
t/t1900-repo-info.sh +30 -0
@@ -213,4 +213,34 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.toplevel absolute and relative' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.toplevel.absolute=$ROOT" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=../" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.toplevel returns empty in a bare repository' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + echo "path.toplevel.absolute=" >expect && + git repo info path.toplevel.absolute >actual && + test_cmp expect actual + ) +' + test_done
Signature · 1 line
2.55.GIT
Re: [PATCH v3 1/7] repo: add path.toplevel with absolute and relative suffix formatting
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 135
Quoted 12 lines · K Jayatheerth
builtin/repo.c +12
-0+static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) { +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, work_tree, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +}
I can manage to wiggle it in, of course, but I thought we lost the '.prefix' member from 'startup_info' in the recent tip of 'master'. As the topic is not targeting 'maint' as a bugfix, perhaps we want to use a more up-to-date 'master' as the base of the topic?
Thanks.
Re: [PATCH v3 1/7] repo: add path.toplevel with absolute and relative suffix formatting
Quoted 9 lines · Junio C Hamano
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 135
Quoted 3 lines · K Jayatheerth
builtin/repo.c +3
-0+format_path (buf, work_tree, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +}I can manage to wiggle it in, of course, but I thought we lost the '.prefix' member from '
startup_info' in the recent tip of 'master'.
Indeed.
Quoted 4 lines
As the topic is not targeting 'maint' as a bugfix, perhaps we want to use a more up-to-date 'master' as the base of the topic?
Thanks.
I see Patrick has changed the prefix member to the repo struct. Didn't notice that before!
I will use the latest master branch for v4
Regards,
- K Jayatheerth
Re: [PATCH v3 1/7] repo: add path.toplevel with absolute and relative suffix formatting
In reply to K JayatheerthQuoted 8 lines · K Jayatheerth
Scripts frequently need to find the root directory of a repository's working tree. Currently, this requires using
git rev-parse --show-toplevelor inferring it from other path components.Introduce
path.toplevel.absoluteandpath.toplevel.relativekeys togit repo info. This allows scripts to retrieve the top-level working tree path in a predictable, strictly formatted manner without relying onrev-parse.
Ok, this seems like suitable information to also look up under git-repo-info.
Quoted 2 lines
If requested in a bare repository where no working tree exists, the command returns an empty string.
This matches the existing behavior in git-rev-parse(1). Makes sense.
Quoted 35 lines
Mentored-by Justin Tobler <[email protected]>Mentored-by Lucas Seiki Oshiro <[email protected]>Signed-off-by K Jayatheerth <[email protected]>--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 28 ++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 30 ++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+)Documentation/git-repo.adoc +10
-0@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.toplevel.absolute`:: + The canonical absolute path to the top-level directory of the + repository's working tree. Outputs an empty string if the repository + is bare. + +`path.toplevel.relative`:: + The path to the top-level directory of the repository's working + tree relative to the current working directory. Outputs an empty + string if the repository is bare. + `references.format`:: The reference storage format. The valid values are: +builtin/repo.c +0
-0
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 129
Quoted 9 lines
builtin/repo.c +6
-0@@ -121,6 +121,32 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) { +strbuf_addstr (buf,"" );
The strbuf here is already NULL-terminated when its initialized. I don't think this should be necessary.
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 142
Quoted 13 lines
builtin/repo.c +13
-0+return 0 ; + } + +format_path (buf, work_tree, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_toplevel_relative (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) { +strbuf_addstr (buf,"" );
Same here.
Quoted 44 lines
builtin/repo.c +9
-0+return 0 ; + } + +format_path (buf, work_tree, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_references_format (struct repository *repo,struct strbuf *buf) { strbuf_addstr(buf,@@ -137,6 +163,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.toplevel.absolute", get_path_toplevel_absolute }, + { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format }, };t/t1900-repo-info.sh +17
-0@@ -213,4 +213,34 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.toplevel absolute and relative' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.toplevel.absolute=$ROOT" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=../" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + )
t/t1900-repo-info.sh test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ · line 242
Quoted 10 lines
t/t1900-repo-info.sh +10
-0+' + +test_expect_success 'path.toplevel returns empty in a bare repository' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + echo "path.toplevel.absolute=" >expect && + git repo info path.toplevel.absolute >actual && + test_cmp expect actual
In this test we are only checking the absolute path. It probably wouldn't hurt to also check the relative path too.
-Justin
Re: [PATCH v3 1/7] repo: add path.toplevel with absolute and relative suffix formatting
Hey Justin,
Thanks for the detailed review.
Quoted 11 lines · Justin Tobler
Quoted 8 lines · K Jayatheerth
Scripts frequently need to find the root directory of a repository's working tree. Currently, this requires using
git rev-parse --show-toplevelor inferring it from other path components.Introduce
path.toplevel.absoluteandpath.toplevel.relativekeys togit repo info. This allows scripts to retrieve the top-level working tree path in a predictable, strictly formatted manner without relying onrev-parse.
Quoted 8 lines
Ok, this seems like suitable information to also look up under git-repo-info.
Quoted 2 lines
If requested in a bare repository where no working tree exists, the command returns an empty string.
This matches the existing behavior in git-rev-parse(1). Makes sense.
Yes, that is correct.
Quoted 11 lines
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 129
Quoted 7 lines
builtin/repo.c +6
-0+static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) { +strbuf_addstr (buf,"" );The strbuf here is already NULL-terminated when its initialized. I don't think this should be necessary.
Very nice point indeed
I will change that everywhere I have added that.
Quoted 15 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!work_tree) { + strbuf_addstr(buf, "");Same here.
t/t1900-repo-info.sh test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ · line 242
Quoted 8 lines
t/t1900-repo-info.sh +8
-0+test_expect_success 'path.toplevel returns empty in a bare repository' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + echo "path.toplevel.absolute=" >expect && + git repo info path.toplevel.absolute >actual && + test_cmp expect actual
Quoted 3 lines
In this test we are only checking the absolute path. It probably wouldn't hurt to also check the relative path too.
Good catch. I'll add relative-path tests in both places.
Quoted 10 lines
Quoted 4 lines
Introduce
path.superproject-working-tree.absoluteandpath.superproject-working-tree.relativekeys togit repo info. This exposes the core submodule context via a scriptable config-like key using standard format rules.Ok, this also seems like a good fit to include as a key in git-repo-info, but "superproject-working-tree" is a bit of a mouthful IMO. An alternative could potentially be "superproject-root"? Maybe its best to just be consistent with the option name in git-rev-parse(1) and keep it the same though.
show-superproject-working-tree is what git rev parse uses. I am a bit unclear about this.
Since it is meant to be a scripting command, I don't know if it being a long name matters much.
At the same time, I don't think we can keep the exact "show-superproject-working-tree" as the key's name.
As the "show" is indirectly covered by "path." so the "show" is just redundant if you ask me (I might be wrong here).
That is actually why I kept the rest of the name similar and omitted the prefix from the flag name.
In other words, I am fine with the name being either one. That said, I am more inclined with the "superproject-root". I think the name explains exactly what it does.
Whereas "superproject-working-tree" was not that clear to me when I first read it (Might be subjective to me).
Quoted 28 lines
Review
Quoted 7 lines
(quoted diff) +7
-0+static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) +{ + struct strbuf superproject = STRBUF_INIT; + + if (!get_superproject_working_tree(&superproject)) { + strbuf_release(&superproject); + strbuf_addstr(buf, "");Same comment here as in the previous patch...
Review
Quoted 5 lines
(quoted diff) +5
-0+ struct strbuf superproject = STRBUF_INIT; + + if (!get_superproject_working_tree(&superproject)) { + strbuf_release(&superproject); + strbuf_addstr(buf, "");...and here as well...
Quoted 10 lines
builtin/repo.c +10
-0+return 0 ; + } + +format_path (buf, superproject.buf, startup_info->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&superproject); +return 0 ; +} + +test_expect_success 'path.superproject-working-tree returns empty when not in a submodule' ' + test_when_finished "rm -rf repo" &&
Quoted 9 lines
t/t1900-repo-info.sh test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ · line 242
Quoted 6 lines
t/t1900-repo-info.sh +6
-0+ git init repo && + ( + cd repo && + echo "path.superproject-working-tree.absolute=" >expect && + git repo info path.superproject-working-tree.absolute >actual && + test_cmp expect actual... and here as well. :)
Good catch. I'll add a relative-path test there as well.
Quoted 8 lines
Quoted 3 lines
Tools and deployment hooks frequently query the location of the object database directory. Currently, this relies on legacy parsing methods or manually inspecting
git rev-parse --git-path objects."Tools and deployment hooks" seems a bit overly specific. Maybe instead we could just say "Scripts operating on a repository may need to query the location of the object database directory"?
I think your version is consistent with other patches as well. I wanted to ask if it is not a good practice to write commit messages which are very specific.
I also wanted to know what constitutes being overly specific so that I can avoid doing it again.
Quoted 3 lines
Also, I'm not entirely sure what is meant by "legacy parsing methods" here.
Something scripts have historically done: parse git rev-parse --git-dir (or read .git/config by hand)
and manually append /objects, rather than asking for the object directory directly
which breaks if GIT_OBJECT_DIRECTORY is set.
I'll reword the commit message to just say that explicitly instead of the vague "legacy parsing methods" phrase.
Quoted 13 lines
Quoted 4 lines
Introduce
path.objects.absoluteandpath.objects.relativekeys togit repo info. This allows tools to discover the object database location safely while natively adhering to activeGIT_OBJECT_DIRECTORYenvironment variable overrides.In the context of pluggable ODBs, this proposed key is a little more interesting because a non-"files" ODB source in the future may not even have a filesystem path to an objects directory. When this becomes more relevant, we could just adapt these keys to return an empty string in such cases, but it does also make me question whether it is information that we should further expose in the first place if it does eventually becomes an internal detail of a specific ODB source.
Quoted 3 lines
It probably doesn't matter too much, but I've CC'd Patrick for his thoughts too.
Thanks for looping in Patrick!
That's a fair concern.
My thinking is that the "files" backend is going to be the reality for the vast majority of
repositories for a long time yet, and scripts asking for path.objects today are almost certainly
assuming a filesystem-backed ODB anyway (that's the whole reason they'd want the path).
So I don't think we're locking ourselves into a bad abstraction by adding it now.
If/when a non-filesystem ODB source becomes real,
we'd have two reasonable options:
return an empty string for that key (same pattern we already use for path.toplevel/superproject-working-tree when the concept doesn't apply),
or deprecate the key outright if it turns out to be meaningless in that world. Either way it doesn't block adding it now, worst case we're removing or narrowing a key later, not stuck with something actively wrong.
Quoted 4 lines
Quoted 4 lines
builtin/repo.c +4
-0+static int get_path_objects_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *obj_dir =repo_get_object_directory (repo); +
Quoted 9 lines
Review
Quoted 4 lines
(quoted diff) +4
-0+ if (!obj_dir) + return error(_("unable to get object directory")); + + format_path(buf, obj_dir, startup_info->prefix, PATH_FORMAT_CANONICAL);For the absolute path, do we actually need to provide the prefix? It might make it more clear that its the aboslute path if we just pass "" instead?
This point was raised in the foundational patch as well. It won't change the output for sure, so I will pass "" instead.
Quoted 7 lines · Justin Tobler
Quoted 4 lines · K Jayatheerth
External tool integrations and validation systems need a stable way to identify where the repository hooks are stored. Currently, this involves relying on
git rev-parse --git-path hooksor queryingcore.hooksPathmanually.
Quoted 5 lines
Similar to the comment in the previous patch, "External tool intergations and validation systems" seems overly specific IMO. Also, "need" is a bit strongly worded as I'm sure its not a requirement for every external script/tool.
Got it, I will try it to be not overly specific as well. Maybe something like:
Scripts operating on a repository may want a stable way to identify where the repository hooks are stored. Currently, this involves relying on git rev-parse --git-path hooks or querying core.hooksPath manually.
Introduce path.hooks.absolute and path.hooks.relative keys to git repo info. This allows scripts to discover the active hooks location, ensuring proper resolution regardless of whether Git is using the standard .git/hooks structure or a custom core.hooksPath setup.
Quoted 19 lines
Quoted 4 lines
Introduce
path.hooks.absoluteandpath.hooks.relativekeys togit repo info. This allows tools to discover the active hooks location natively, ensuring proper resolution regardless of whether Git is using the standard.git/hooksstructure or a customcore.hooksPathsetup.Per hooks path documentation:
The path can be either absolute or relative. A relative path is taken as relative to the directory where the hooks are run.
...
You can also disable all hooks entirely by setting core.hooksPath to
/dev/null.Should we handle this
/dev/nullcase specially? It looks like:$ git -c core.hooksPath=/dev/null rev-parse --git-path hooks
Quoted 8 lines
just prints '
/dev/null'. I do wonder if this makes much sense though in context of the relative path version of this key. From some quick testing, it appears the git-rev-parse(1) version of this option always prints the absolute path if that is what is configured (it appears to ignore --path-format). Maybe we should just special case/dev/nulland return an empty string? I'm not entirely sure what the best route is here though.
After thinking about it
I would lean towards not special-casing it. A few reasons:
/dev/null is just a valid (if unusual) value of core.hooksPath as far as Git is concerned, the field is documented to reflect whatever core.hooksPath resolves to, and rev-parse --git-path hooks already treats it as an ordinary path.
If we special-case it to an empty string, we'd be the only place in Git that treats /dev/null as meaningfully different from any other hooksPath value.
Empty string is already used by other keys in this series
to mean "this concept doesn't apply here" (no working tree, not a submodule). Using empty string for "hooks are disabled" would overload that meaning with something different, "the path exists but you shouldn't use it"
and a script can't tell the two apart without also knowing the hooksPath convention, which defeats the purpose of adding a structured key in the first place.
Any script that's checking for /dev/null already has to know that convention when
using the existing rev-parse interface, so we're not creating new surprises, just carrying forward a pre-existing quirk of core.hooksPath semantics.
For the relative version:
I'll let format_path/relative_path do whatever it already does for a path that isn't under the prefix
(I'd guess it falls back to printing the absolute path, similar to how rev-parse seems to ignore --path-format for this case). That keeps behavior consistent with the existing tool rather than introducing new special-casing for path.hooks.relative specifically.
I'll add a test covering core.hooksPath=/dev/null to lock in whichever behavior we land on,
and I can add a doc note under path.hooks.absolute/path.hooks.relative mentioning that /dev/null is passed through unchanged if that's the value in use,
similar to how the existing hooksPath docs describe it.
Let me know if you still think empty-string is preferable despite the above, happy to go either way once we agree on the reasoning.
Thanks again for the detailed review!
Regards,
- K Jayatheerth
PATCH v3 2/7 repo: add path.superproject-working-tree with absolute and relative suffixes
In reply to K JayatheerthScripts working in multi-repository setups often need to identify the top-level working tree of a superproject from within a submodule. Currently, this is only exposed via git rev-parse --show-superproject-working-tree.
Introduce path.superproject-working-tree.absolute and path.superproject-working-tree.relative keys to git repo info. This exposes the core submodule context via a scriptable config-like key using standard format rules.
If requested when not inside a submodule, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 33 +++++++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.superproject-working-tree.absolute`:: + The canonical absolute path to the working tree root of the superproject + if the current repository is an initialized submodule. Outputs an empty + string if not in a submodule. + +`path.superproject-working-tree.relative`:: + The path to the working tree root of the superproject relative to the + current working directory if the current repository is an initialized + submodule. Outputs an empty string if not in a submodule. + `path.toplevel.absolute`:: The canonical absolute path to the top-level directory of the repository's working tree. Outputs an empty string if the repository
builtin/repo.c +33 -0
@@ -18,6 +18,7 @@#include "strbuf.h" #include "string-list.h" #include "shallow.h" +#include "submodule.h" #include "tree.h" #include "tree-walk.h" #include "utf8.h"
@@ -121,6 +122,36 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, superproject.buf, startup_info->prefix,PATH_FORMAT_CANONICAL ); +strbuf_release (&superproject); +return 0 ; +} + +static int get_path_superproject_relative(struct repository *repo UNUSED, struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +strbuf_addstr (buf,"" ); +return 0 ; + } + +format_path (buf, superproject.buf, startup_info->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&superproject); +return 0 ; +} +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) {const char *work_tree =repo_get_work_tree (repo);
@@ -163,6 +194,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.superproject-working-tree.absolute", get_path_superproject_absolute }, + { "path.superproject-working-tree.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute }, { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format },
t/t1900-repo-info.sh +34 -0
@@ -213,6 +213,40 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.superproject-working-tree absolute and relative' ' + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + cd sub && + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.superproject-working-tree.absolute=$ROOT" >expect.abs && + git repo info path.superproject-working-tree.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superproject-working-tree.relative=../" >expect.rel && + git repo info path.superproject-working-tree.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.superproject-working-tree returns empty when not in a submodule' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.superproject-working-tree.absolute=" >expect && + git repo info path.superproject-working-tree.absolute >actual && + test_cmp expect actual + ) +' + test_expect_success 'path.toplevel absolute and relative' ' test_when_finished "rm -rf repo" && git init repo &&
Signature · 1 line
2.55.GIT
Re: [PATCH v3 2/7] repo: add path.superproject-working-tree with absolute and relative suffixes
Quoted 9 lines · K Jayatheerth
Scripts working in multi-repository setups often need to identify the top-level working tree of a superproject from within a submodule. Currently, this is only exposed via
git rev-parse --show-superproject-working-tree.Introduce
path.superproject-working-tree.absoluteandpath.superproject-working-tree.relativekeys togit repo info. This exposes the core submodule context via a scriptable config-like key using standard format rules.
Ok, this also seems like a good fit to include as a key in git-repo-info, but "superproject-working-tree" is a bit of a mouthful IMO. An alternative could potentially be "superproject-root"? Maybe its best to just be consistent with the option name in git-rev-parse(1) and keep it the same though.
Quoted 46 lines
If requested when not inside a submodule, the command returns an empty string.
Mentored-by Justin Tobler <[email protected]>Mentored-by Lucas Seiki Oshiro <[email protected]>Signed-off-by K Jayatheerth <[email protected]>--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 33 +++++++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 77 insertions(+)Documentation/git-repo.adoc +10
-0@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.superproject-working-tree.absolute`:: + The canonical absolute path to the working tree root of the superproject + if the current repository is an initialized submodule. Outputs an empty + string if not in a submodule. + +`path.superproject-working-tree.relative`:: + The path to the working tree root of the superproject relative to the + current working directory if the current repository is an initialized + submodule. Outputs an empty string if not in a submodule. + `path.toplevel.absolute`:: The canonical absolute path to the top-level directory of the repository's working tree. Outputs an empty string if the repositorybuiltin/repo.c +1
-0@@ -18,6 +18,7 @@#include "strbuf.h" #include "string-list.h" #include "shallow.h" +#include "submodule.h" #include "tree.h" #include "tree-walk.h" #include "utf8.h"
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 131
Quoted 10 lines
builtin/repo.c +7
-0@@ -121,6 +122,36 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +strbuf_addstr (buf,"" );
Same comment here as in the previous patch...
Quoted 5 lines
builtin/repo.c +5
-0+return 0 ; + } + +format_path (buf, superproject.buf, startup_info->prefix,PATH_FORMAT_CANONICAL ); +strbuf_release (&superproject);
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 146
Quoted 10 lines
builtin/repo.c +10
-0+return 0 ; +} + +static int get_path_superproject_relative(struct repository *repo UNUSED, struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +strbuf_addstr (buf,"" );
...and here as well...
Quoted 49 lines
builtin/repo.c +10
-0+return 0 ; + } + +format_path (buf, superproject.buf, startup_info->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&superproject); +return 0 ; +} +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) {const char *work_tree =repo_get_work_tree (repo);@@ -163,6 +194,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.superproject-working-tree.absolute", get_path_superproject_absolute }, + { "path.superproject-working-tree.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute }, { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format },t/t1900-repo-info.sh +21
-0@@ -213,6 +213,40 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.superproject-working-tree absolute and relative' ' + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + cd sub && + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.superproject-working-tree.absolute=$ROOT" >expect.abs && + git repo info path.superproject-working-tree.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superproject-working-tree.relative=../" >expect.rel && + git repo info path.superproject-working-tree.relative >actual.rel && + test_cmp expect.rel actual.rel + )
t/t1900-repo-info.sh test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ · line 246
Quoted 10 lines
t/t1900-repo-info.sh +10
-0+' + +test_expect_success 'path.superproject-working-tree returns empty when not in a submodule' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.superproject-working-tree.absolute=" >expect && + git repo info path.superproject-working-tree.absolute >actual && + test_cmp expect actual
... and here as well. :)
-Justin
PATCH v3 3/7 repo: add path.objects with absolute and relative suffix formatting
In reply to K JayatheerthTools and deployment hooks frequently query the location of the object database directory. Currently, this relies on legacy parsing methods or manually inspecting git rev-parse --git-path objects.
Introduce path.objects.absolute and path.objects.relative keys to git repo info. This allows tools to discover the object database location safely while natively adhering to active GIT_OBJECT_DIRECTORY environment variable overrides.
--- Documentation/git-repo.adoc | 9 +++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 7 +++++++ 3 files changed, 40 insertions(+)
Documentation/git-repo.adoc +9 -0
@@ -119,6 +119,15 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.objects.absolute`:: + The canonical absolute path to the repository's object database directory. + Respects the `GIT_OBJECT_DIRECTORY` environment override. + +`path.objects.relative`:: + The path to the repository's object database directory relative to the + current working directory. Respects the `GIT_OBJECT_DIRECTORY` + environment override. + `path.superproject-working-tree.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +24 -0
@@ -122,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_objects_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *obj_dir =repo_get_object_directory (repo); + +if (!obj_dir) +return error (_ ("unable to get object directory" )); + +format_path (buf, obj_dir, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_objects_relative (struct repository *repo,struct strbuf *buf) +{ +const char *obj_dir =repo_get_object_directory (repo); + +if (!obj_dir) +return error (_ ("unable to get object directory" )); + +format_path (buf, obj_dir, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} + static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -194,6 +216,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.objects.absolute", get_path_objects_absolute }, + { "path.objects.relative", get_path_objects_relative }, { "path.superproject-working-tree.absolute", get_path_superproject_absolute }, { "path.superproject-working-tree.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +7 -0
@@ -213,6 +213,13 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'objects standard' 'objects' '.git/objects' + +test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \ + 'custom-objects' \ + 'GIT_OBJECT_DIRECTORY="$ROOT/custom-objects" && export GIT_OBJECT_DIRECTORY && + mkdir -p "$ROOT/custom-objects"' + test_expect_success 'path.superproject-working-tree absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.55.GIT
Re: [PATCH v3 3/7] repo: add path.objects with absolute and relative suffix formatting
Quoted 3 lines · K Jayatheerth
Tools and deployment hooks frequently query the location of the object database directory. Currently, this relies on legacy parsing methods or manually inspecting
git rev-parse --git-path objects.
"Tools and deployment hooks" seems a bit overly specific. Maybe instead we could just say "Scripts operating on a repository may need to query the location of the object database directory"?
Also, I'm not entirely sure what is meant by "legacy parsing methods" here.
Quoted 4 lines
Introduce
path.objects.absoluteandpath.objects.relativekeys togit repo info. This allows tools to discover the object database location safely while natively adhering to activeGIT_OBJECT_DIRECTORYenvironment variable overrides.
In the context of pluggable ODBs, this proposed key is a little more interesting because a non-"files" ODB source in the future may not even have a filesystem path to an objects directory. When this becomes more relevant, we could just adapt these keys to return an empty string in such cases, but it does also make me question whether it is information that we should further expose in the first place if it does eventually becomes an internal detail of a specific ODB source.
It probably doesn't matter too much, but I've CC'd Patrick for his thoughts too.
[snip]
Quoted 6 lines
builtin/repo.c +0
-0@@ -122,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ;
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 132
Quoted 10 lines
builtin/repo.c +8
-0} +static int get_path_objects_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *obj_dir =repo_get_object_directory (repo); + +if (!obj_dir) +return error (_ ("unable to get object directory" )); + +format_path (buf, obj_dir, startup_info->prefix,PATH_FORMAT_CANONICAL );
For the absolute path, do we actually need to provide the prefix? It might make it more clear that its the aboslute path if we just pass "" instead?
-Justin
PATCH v3 4/7 repo: add path.hooks with absolute and relative suffix formatting
In reply to K JayatheerthExternal tool integrations and validation systems need a stable way to identify where the repository hooks are stored. Currently, this involves relying on git rev-parse --git-path hooks or querying core.hooksPath manually.
Introduce path.hooks.absolute and path.hooks.relative keys to git repo info. This allows tools to discover the active hooks location natively, ensuring proper resolution regardless of whether Git is using the standard .git/hooks structure or a custom core.hooksPath setup.
--- Documentation/git-repo.adoc | 8 ++++++++ builtin/repo.c | 22 ++++++++++++++++++++++ t/t1900-repo-info.sh | 6 ++++++ 3 files changed, 36 insertions(+)
Documentation/git-repo.adoc +8 -0
@@ -119,6 +119,14 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.hooks.absolute`:: + The canonical absolute path to the repository's hooks directory. + Respects `core.hooksPath` configuration adjustments. + +`path.hooks.relative`:: + The path to the repository's hooks directory relative to the current + working directory. Respects `core.hooksPath` configuration adjustments. + `path.objects.absolute`:: The canonical absolute path to the repository's object database directory. Respects the `GIT_OBJECT_DIRECTORY` environment override.
builtin/repo.c +22 -0
@@ -122,6 +122,26 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf, startup_info->prefix,PATH_FORMAT_CANONICAL ); +strbuf_release (&hooks_path); +return 0 ; +} + +static int get_path_hooks_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf, startup_info->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&hooks_path); +return 0 ; +} +static int get_path_objects_absolute (struct repository *repo,struct strbuf *buf) {const char *obj_dir =repo_get_object_directory (repo);
@@ -216,6 +236,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.hooks.absolute", get_path_hooks_absolute }, + { "path.hooks.relative", get_path_hooks_relative }, { "path.objects.absolute", get_path_objects_absolute }, { "path.objects.relative", get_path_objects_relative }, { "path.superproject-working-tree.absolute", get_path_superproject_absolute },
t/t1900-repo-info.sh +6 -0
@@ -213,6 +213,12 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'hooks standard fallback' 'hooks' '.git/hooks' + +test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ + 'custom-hooks' \ + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' + test_repo_info_path 'objects standard' 'objects' '.git/objects' test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \
Signature · 1 line
2.55.GIT
Re: [PATCH v3 4/7] repo: add path.hooks with absolute and relative suffix formatting
Quoted 4 lines · K Jayatheerth
External tool integrations and validation systems need a stable way to identify where the repository hooks are stored. Currently, this involves relying on
git rev-parse --git-path hooksor queryingcore.hooksPathmanually.
Similar to the comment in the previous patch, "External tool intergations and validation systems" seems overly specific IMO. Also, "need" is a bit strongly worded as I'm sure its not a requirement for every external script/tool.
Quoted 4 lines
Introduce
path.hooks.absoluteandpath.hooks.relativekeys togit repo info. This allows tools to discover the active hooks location natively, ensuring proper resolution regardless of whether Git is using the standard.git/hooksstructure or a customcore.hooksPathsetup.
Per hooks path documentation:
The path can be either absolute or relative. A relative path is taken as relative to the directory where the hooks are run.
...
You can also disable all hooks entirely by setting core.hooksPath to /dev/null.
Should we handle this /dev/null case specially? It looks like:
$ git -c core.hooksPath=/dev/null rev-parse --git-path hooks
just prints '/dev/null'. I do wonder if this makes much sense though in context of the relative path version of this key. From some quick testing, it appears the git-rev-parse(1) version of this option always prints the absolute path if that is what is configured (it appears to ignore --path-format). Maybe we should just special case /dev/null and return an empty string? I'm not entirely sure what the best route is here though.
-Justin
PATCH v3 5/7 repo: add path.index with absolute and relative suffix formatting
In reply to K JayatheerthExternal script workflows and formatting layers require straightforward access to the location of the index staging file. Currently, tracking this necessitates a legacy call to git rev-parse --git-path index or --show-toplevel logic abstractions.
Introduce path.index.absolute and path.index.relative keys to git repo info. This allows tooling utilities to discover the active index context cleanly while scaling transparently with localized GIT_INDEX_FILE environment overrides.
--- Documentation/git-repo.adoc | 12 ++++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 59 insertions(+)
Documentation/git-repo.adoc +12 -0
@@ -127,6 +127,18 @@ values that they return: The path to the repository's hooks directory relative to the current working directory. Respects `core.hooksPath` configuration adjustments. +`path.index.absolute`:: + The canonical absolute path to the repository's current index file. + Respects the `GIT_INDEX_FILE` environment override. The returned path + reflects the configured/default index location regardless of whether the + repository is bare or whether the file currently exists. + +`path.index.relative`:: + The path to the repository's current index file relative to the current + working directory. Respects the `GIT_INDEX_FILE` environment override. + The returned path reflects the configured/default index location regardless + of whether the repository is bare or whether the file currently exists. + `path.objects.absolute`:: The canonical absolute path to the repository's object database directory. Respects the `GIT_OBJECT_DIRECTORY` environment override.
builtin/repo.c +24 -0
@@ -142,6 +142,28 @@ static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_index_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_index_relative (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_objects_absolute (struct repository *repo,struct strbuf *buf) {const char *obj_dir =repo_get_object_directory (repo);
@@ -238,6 +260,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.gitdir.relative", get_path_gitdir_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, + { "path.index.absolute", get_path_index_absolute }, + { "path.index.relative", get_path_index_relative }, { "path.objects.absolute", get_path_objects_absolute }, { "path.objects.relative", get_path_objects_relative }, { "path.superproject-working-tree.absolute", get_path_superproject_absolute },
t/t1900-repo-info.sh +23 -0
@@ -219,6 +219,29 @@ test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ 'custom-hooks' \ 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' +test_repo_info_path 'index standard' 'index' '.git/index' + +test_repo_info_path 'index with GIT_INDEX_FILE override' 'index' \ + 'custom-index-file' \ + 'GIT_INDEX_FILE="$ROOT/custom-index-file" && export GIT_INDEX_FILE' + +test_expect_success 'path.index in a bare repository returns default index location' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + ROOT="$(test-tool path-utils real_path .)" && + + echo "path.index.absolute=$ROOT/index" >expect.abs && + git repo info path.index.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.index.relative=index" >expect.rel && + git repo info path.index.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_repo_info_path 'objects standard' 'objects' '.git/objects' test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \
Signature · 1 line
2.55.GIT
PATCH v3 6/7 repo: add path.grafts with absolute and relative suffix formatting
In reply to K JayatheerthExternal toolchains managing specialized history rewrites or legacy history splices require access to the location of the repository grafts file. Currently, this requires a legacy call to git rev-parse --git-path info/grafts.
Introduce path.grafts.absolute and path.grafts.relative keys to git repo info. This allows scripting layers to query the active grafts context cleanly while scaling transparently with active GIT_GRAFT_FILE environment variable overrides.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 6 ++++++ 3 files changed, 40 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.grafts.absolute`:: + The canonical absolute path to the repository grafts file. + Respects the `GIT_GRAFT_FILE` environment override. The path is returned + regardless of whether the file currently exists on disk. + +`path.grafts.relative`:: + The path to the repository grafts file relative to the current working + directory. Respects the `GIT_GRAFT_FILE` environment override. The path + is returned regardless of whether the file currently exists on disk. + `path.hooks.absolute`:: The canonical absolute path to the repository's hooks directory. Respects `core.hooksPath` configuration adjustments.
builtin/repo.c +24 -0
@@ -122,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_grafts_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file, startup_info->prefix,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_grafts_relative (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file, startup_info->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf hooks_path =STRBUF_INIT ;
@@ -258,6 +280,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.grafts.absolute", get_path_grafts_absolute }, + { "path.grafts.relative", get_path_grafts_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, { "path.index.absolute", get_path_index_absolute },
t/t1900-repo-info.sh +6 -0
@@ -213,6 +213,12 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'grafts standard' 'grafts' '.git/info/grafts' + +test_repo_info_path 'grafts with GIT_GRAFT_FILE override' 'grafts' \ + 'custom-graft-file' \ + 'GIT_GRAFT_FILE="$ROOT/custom-graft-file" && export GIT_GRAFT_FILE' + test_repo_info_path 'hooks standard fallback' 'hooks' '.git/hooks' test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
Signature · 1 line
2.55.GIT
PATCH v3 7/7 repo: add path.git-prefix path key
In reply to K JayatheerthScripts and command-line prompt integrations frequently need to know their relative depth inside a repository working tree layout. Currently, this is retrieved using git rev-parse --show-prefix.
Introduce the path.git-prefix key to git repo info. This mirrors the prefix location tracking framework as a standalone key, returning the exact relative path offset complete with a trailing slash, or an empty string if run directly at the repository working tree root.
--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 11 +++++++++++ t/t1900-repo-info.sh | 19 +++++++++++++++++++ 3 files changed, 35 insertions(+)
Documentation/git-repo.adoc +5 -0
@@ -113,6 +113,11 @@ values that they return: The path to the Git repository's common directory relative to the current working directory. +`path.git-prefix`:: + The relative path from the top-level directory of the working tree to + the current working directory (including a trailing slash). Outputs an + empty string if executed at the root of the working tree. + `path.gitdir.absolute`:: The canonical absolute path to the Git repository directory (the `.git` directory).
builtin/repo.c +11 -0
@@ -100,6 +100,16 @@ static int get_path_commondir_relative(struct repository *repo, struct strbuf *breturn 0 ; } +static int get_path_git_prefix(struct repository *repo UNUSED, struct strbuf *buf) +{ +/* +* startup_info->prefix is NULL if we are at the working tree root. +* We add an empty string to ensure the buffer is cleanly initialized. +*/ +strbuf_addstr (buf, startup_info->prefix ? startup_info->prefix :"" ); +return 0 ; +} +static int get_path_gitdir_absolute (struct repository *repo,struct strbuf *buf) {const char *git_dir =repo_get_git_dir (repo);
@@ -278,6 +288,7 @@ static const struct repo_info_field repo_info_field[] = { { "object.format", get_object_format }, { "path.commondir.absolute", get_path_commondir_absolute }, { "path.commondir.relative", get_path_commondir_relative }, + { "path.git-prefix", get_path_git_prefix }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, { "path.grafts.absolute", get_path_grafts_absolute },
t/t1900-repo-info.sh +19 -0
@@ -207,6 +207,25 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.git-prefix at root and in a subdirectory' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + echo "path.git-prefix=" >expect.root && + git repo info path.git-prefix >actual.root && + test_cmp expect.root actual.root && + + mkdir -p sub/dir && + cd sub/dir && + + echo "path.git-prefix=sub/dir/" >expect.sub && + git repo info path.git-prefix >actual.sub && + test_cmp expect.sub actual.sub + ) +' + test_repo_info_path 'gitdir standard' 'gitdir' '.git' test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
Signature · 1 line
2.55.GIT
Quoted 9 lines · K Jayatheerth
Series adds keys to git repo info.
Keys output paths of repository components:
* path.toplevel: repository tree.
* path.superproject-working-tree: superproject tree from submodules.
* path.objects: repository objects.
* path.hooks: repository hooks.
* path.index: repository index.
* path.grafts: repository grafts.
* path.git-prefix: prefix offset.
I guess the issues I had at the design level in the previous iteration is gone ;-)
I'd love to hear real reviews from others on these patches, but at least I didn't spot anything glaringly wrong anymore.
Thanks.
Quoted 13 lines · Junio C Hamano
Quoted 9 lines · K Jayatheerth
Series adds keys to git repo info.
Keys output paths of repository components:
* path.toplevel: repository tree.
* path.superproject-working-tree: superproject tree from submodules.
* path.objects: repository objects.
* path.hooks: repository hooks.
* path.index: repository index.
* path.grafts: repository grafts.
* path.git-prefix: prefix offset.
Quoted 7 lines
I guess the issues I had at the design level in the previous iteration is gone ;-)
I'd love to hear real reviews from others on these patches, but at least I didn't spot anything glaringly wrong anymore.
Thanks.
Sure,
until then I will work on the histogram patches in git repo structure.
Thanks for validating!
Regards,
- K Jayatheerth
Quoted 3 lines
I'd love to hear real reviews from others on these patches, but at least I didn't spot anything glaringly wrong anymore.
It looks good to me :-)
Quoted 4 lines · Lucas Seiki Oshiro
Quoted 2 lines
I'd love to hear real reviews from others on these patches, but at least I didn't spot anything glaringly wrong anymore.
It looks good to me :-)
Can you try to make your review sound a bit more credible to readers?
It is much harder to give positive reviews than to merely point out a few breakages in a patch, but there are still things reviewers can do. Thinking aloud to follow the author's line of thought is a technique I have found over the years to work well in demonstrating that your Ack is backed by having actually read and understood the patch. There may be other techniques experienced reviewers (by now you know who they are after reading what they wrote on your patches and others') use when giving positive reviews.
Thanks.
v4 cover repo: add more path keys to git repo info
In reply to K JayatheerthSeries adds keys to git repo info.
Keys output paths of repository components:
* path.toplevel: repository tree.
* path.superproject-root: superproject tree from submodules.
* path.hooks: repository hooks.
* path.index: repository index.
* path.grafts: repository grafts.
* path.git-prefix: prefix offset.
The patch also removes an unused header.
Keys support suffixes for format.
Commits contain documentation and tests.
Changes since v3:
* The prefix member has been shifted from startup_info to repo, therefore we now omit the header and use repo->prefix everywhere. Development of these patches is now based on the latest branch.
* Since strbuf is NUL-terminated, remove all strbuf_addstr(buf, ""); lines from the patches.
* Add relative-path test cases alongside the existing absolute-path test cases wherever we don't use the existing helper.
* Renamed superproject-working-tree to superproject-root because I feel the latter is a bit clearer. That said, I'm happy with either name, so if you prefer superproject-working-tree, I'm perfectly fine reverting it.
* Changed almost all the commit messages to make them not overly specific.
* Dropped path.objects from this series. During a sync discussion with my mentors, we concluded that this key should wait, since the object database's on-disk layout is expected to change significantly as pluggable ODB backends are introduced.
* Removed repo->prefix from the absolute path functions (the absolute-path variants now pass "" instead).
* Added a /dev/null test case for core.hooksPath, guarded against MINGW since /dev/null doesn't resolve to a real canonicalizable path on Windows.
K Jayatheerth (7):
repo: add path.toplevel with absolute and relative suffix formatting
repo: add path.superproject-root with absolute and relative suffixes
repo: add path.hooks with absolute and relative suffixes
repo: add path.index with absolute and relative suffixes
repo: add path.grafts with absolute and relative suffixes
repo: add path.git-prefix
repo: remove unused setup.h include
Documentation/git-repo.adoc | 57 +++++++++++++ builtin/repo.c | 137 +++++++++++++++++++++++++++++++- t/t1900-repo-info.sh | 154 +++++++++++++++++++++++++++++++++++- 3 files changed, 345 insertions(+), 3 deletions(-)
Range-diff against v3:
1: baed121c74 ! 1: 3880485020 repo: add path.toplevel with absolute and relative suffix formatting
@@ Commit message
Scripts frequently need to find the root directory of a repository's
working tree. Currently, this requires using `git rev-parse --show-toplevel`
- or inferring it from other path components.
+ or inferring it from other repository information.
Introduce `path.toplevel.absolute` and `path.toplevel.relative` keys
to `git repo info`. This allows scripts to retrieve the top-level
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+{
+ const char *work_tree = repo_get_work_tree(repo);
+
-+ if (!work_tree) {
-+ strbuf_addstr(buf, "");
++ if (!work_tree)
+ return 0;
-+ }
+
-+ format_path(buf, work_tree, startup_info->prefix, PATH_FORMAT_CANONICAL);
++ format_path(buf, work_tree, "", PATH_FORMAT_CANONICAL);
+ return 0;
+}
+
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+{
+ const char *work_tree = repo_get_work_tree(repo);
+
-+ if (!work_tree) {
-+ strbuf_addstr(buf, "");
++ if (!work_tree)
+ return 0;
-+ }
+
-+ format_path(buf, work_tree, startup_info->prefix, PATH_FORMAT_RELATIVE);
++ format_path(buf, work_tree, repo->prefix, PATH_FORMAT_RELATIVE);
+ return 0;
+}
+
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
+ )
+'
+
-+test_expect_success 'path.toplevel returns empty in a bare repository' '
++test_expect_success 'path.toplevel absolute and relative in a bare repository' '
+ test_when_finished "rm -rf bare.git" &&
+ git init --bare bare.git &&
+ (
+ cd bare.git &&
-+ echo "path.toplevel.absolute=" >expect &&
-+ git repo info path.toplevel.absolute >actual &&
-+ test_cmp expect actual
++
++ echo "path.toplevel.absolute=" >expect.abs &&
++ git repo info path.toplevel.absolute >actual.abs &&
++ test_cmp expect.abs actual.abs &&
++
++ echo "path.toplevel.relative=" >expect.rel &&
++ git repo info path.toplevel.relative >actual.rel &&
++ test_cmp expect.rel actual.rel
+ )
+'
+
2: 2f363b6358 ! 2: 1b7b0d286c repo: add path.superproject-working-tree with absolute and relative suffixes
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: add path.superproject-working-tree with absolute and relative suffixes
+ repo: add path.superproject-root with absolute and relative suffixes
Scripts working in multi-repository setups often need to identify the
top-level working tree of a superproject from within a submodule.
Currently, this is only exposed via `git rev-parse
--show-superproject-working-tree`.
- Introduce `path.superproject-working-tree.absolute` and
- `path.superproject-working-tree.relative` keys to `git repo info`.
+ Introduce `path.superproject-root.absolute` and
+ `path.superproject-root.relative` keys to `git repo info`.
This exposes the core submodule context via a scriptable config-like key
using standard format rules.
@@ Documentation/git-repo.adoc: values that they return:
`path.gitdir.relative`::
The path to the Git repository directory relative to the current working directory.
-+`path.superproject-working-tree.absolute`::
++`path.superproject-root.absolute`::
+ The canonical absolute path to the working tree root of the superproject
+ if the current repository is an initialized submodule. Outputs an empty
+ string if not in a submodule.
+
-+`path.superproject-working-tree.relative`::
++`path.superproject-root.relative`::
+ The path to the working tree root of the superproject relative to the
+ current working directory if the current repository is an initialized
+ submodule. Outputs an empty string if not in a submodule.
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+
+ if (!get_superproject_working_tree(&superproject)) {
+ strbuf_release(&superproject);
-+ strbuf_addstr(buf, "");
+ return 0;
+ }
+
-+ format_path(buf, superproject.buf, startup_info->prefix, PATH_FORMAT_CANONICAL);
++ format_path(buf, superproject.buf, "", PATH_FORMAT_CANONICAL);
+ strbuf_release(&superproject);
+ return 0;
+}
+
-+static int get_path_superproject_relative(struct repository *repo UNUSED, struct strbuf *buf)
++static int get_path_superproject_relative(struct repository *repo, struct strbuf *buf)
+{
+ struct strbuf superproject = STRBUF_INIT;
+
+ if (!get_superproject_working_tree(&superproject)) {
+ strbuf_release(&superproject);
-+ strbuf_addstr(buf, "");
+ return 0;
+ }
+
-+ format_path(buf, superproject.buf, startup_info->prefix, PATH_FORMAT_RELATIVE);
++ format_path(buf, superproject.buf, repo->prefix, PATH_FORMAT_RELATIVE);
+ strbuf_release(&superproject);
+ return 0;
+}
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
{ "path.commondir.relative", get_path_commondir_relative },
{ "path.gitdir.absolute", get_path_gitdir_absolute },
{ "path.gitdir.relative", get_path_gitdir_relative },
-+ { "path.superproject-working-tree.absolute", get_path_superproject_absolute },
-+ { "path.superproject-working-tree.relative", get_path_superproject_relative },
++ { "path.superproject-root.absolute", get_path_superproject_absolute },
++ { "path.superproject-root.relative", get_path_superproject_relative },
{ "path.toplevel.absolute", get_path_toplevel_absolute },
{ "path.toplevel.relative", get_path_toplevel_relative },
{ "references.format", get_references_format },
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
'.git' \
'GIT_DIR="../.git" && export GIT_DIR'
-+test_expect_success 'path.superproject-working-tree absolute and relative' '
++test_expect_success 'path.superproject-root absolute and relative' '
+ test_when_finished "rm -rf sub super" &&
+ git init sub &&
+ test_commit -C sub initial &&
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
+ cd sub &&
+ ROOT="$(test-tool path-utils real_path ..)" &&
+
-+ echo "path.superproject-working-tree.absolute=$ROOT" >expect.abs &&
-+ git repo info path.superproject-working-tree.absolute >actual.abs &&
++ echo "path.superproject-root.absolute=$ROOT" >expect.abs &&
++ git repo info path.superproject-root.absolute >actual.abs &&
+ test_cmp expect.abs actual.abs &&
+
-+ echo "path.superproject-working-tree.relative=../" >expect.rel &&
-+ git repo info path.superproject-working-tree.relative >actual.rel &&
++ echo "path.superproject-root.relative=../" >expect.rel &&
++ git repo info path.superproject-root.relative >actual.rel &&
+ test_cmp expect.rel actual.rel
+ )
+'
+
-+test_expect_success 'path.superproject-working-tree returns empty when not in a submodule' '
++test_expect_success 'path.superproject-root returns empty when not in a submodule' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
-+ echo "path.superproject-working-tree.absolute=" >expect &&
-+ git repo info path.superproject-working-tree.absolute >actual &&
-+ test_cmp expect actual
++
++ echo "path.superproject-root.absolute=" >expect.abs &&
++ git repo info path.superproject-root.absolute >actual.abs &&
++ test_cmp expect.abs actual.abs &&
++
++ echo "path.superproject-root.relative=" >expect.rel &&
++ git repo info path.superproject-root.relative >actual.rel &&
++ test_cmp expect.rel actual.rel
+ )
+'
+4: e3facc7989 ! 3: 517f621eb0 repo: add path.hooks with absolute and relative suffix formatting
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: add path.hooks with absolute and relative suffix formatting
+ repo: add path.hooks with absolute and relative suffixes
- External tool integrations and validation systems need a stable way to
- identify where the repository hooks are stored. Currently, this involves
- relying on git rev-parse --git-path hooks or querying core.hooksPath
- manually.
+ Hooks are an integral part of a repository's configuration and are
+ commonly used by tooling to automate repository-specific workflows.
+ Currently, scripts typically retrieve the hooks directory by invoking
+ git rev-parse --git-path hooks.
Introduce path.hooks.absolute and path.hooks.relative keys to
- git repo info. This allows tools to discover the active hooks location
- natively, ensuring proper resolution regardless of whether Git is using
- the standard .git/hooks structure or a custom core.hooksPath setup.
+ git repo info. This exposes the hooks directory as a scriptable
+ config-like key using standard format rules, allowing scripts to
+ retrieve it through the same interface as other repository path
+ information.
@@ Documentation/git-repo.adoc: values that they return:
+path.hooks.absolute::
+ The canonical absolute path to the repository's hooks directory.
-+ Respects core.hooksPath configuration adjustments.
++ Respects the core.hooksPath configuration. If core.hooksPath is
++ set to /dev/null, that value is returned unchanged.
+
+path.hooks.relative::
+ The path to the repository's hooks directory relative to the current
-+ working directory. Respects core.hooksPath configuration adjustments.
++ working directory. Respects the core.hooksPath configuration.
+
- path.objects.absolute::
- The canonical absolute path to the repository's object database directory.
- Respects the GIT_OBJECT_DIRECTORY environment override.
+ path.superproject-root.absolute::
+ The canonical absolute path to the working tree root of the superproject
+ if the current repository is an initialized submodule. Outputs an empty
## builtin/repo.c ##
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+ struct strbuf hooks_path = STRBUF_INIT;
+
+ repo_git_path_replace(repo, &hooks_path, "hooks");
-+ format_path(buf, hooks_path.buf, startup_info->prefix, PATH_FORMAT_CANONICAL);
++ format_path(buf, hooks_path.buf, "", PATH_FORMAT_CANONICAL);
+ strbuf_release(&hooks_path);
+ return 0;
+}
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+ struct strbuf hooks_path = STRBUF_INIT;
+
+ repo_git_path_replace(repo, &hooks_path, "hooks");
-+ format_path(buf, hooks_path.buf, startup_info->prefix, PATH_FORMAT_RELATIVE);
++ format_path(buf, hooks_path.buf, repo->prefix, PATH_FORMAT_RELATIVE);
+ strbuf_release(&hooks_path);
+ return 0;
+}
+
- static int get_path_objects_absolute(struct repository *repo, struct strbuf *buf)
+ static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) {
- const char *obj_dir = repo_get_object_directory(repo);
+ struct strbuf superproject = STRBUF_INIT;
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
{ "path.commondir.relative", get_path_commondir_relative },
{ "path.gitdir.absolute", get_path_gitdir_absolute },
{ "path.gitdir.relative", get_path_gitdir_relative },
+ { "path.hooks.absolute", get_path_hooks_absolute },
+ { "path.hooks.relative", get_path_hooks_relative },
- { "path.objects.absolute", get_path_objects_absolute },
- { "path.objects.relative", get_path_objects_relative },
- { "path.superproject-working-tree.absolute", get_path_superproject_absolute },
+ { "path.superproject-root.absolute", get_path_superproject_absolute },
+ { "path.superproject-root.relative", get_path_superproject_relative },
+ { "path.toplevel.absolute", get_path_toplevel_absolute },
## t/t1900-repo-info.sh ##
+@@ t/t1900-repo-info.sh: test_repo_info_path () {
+ cd repo/sub &&
+ ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
+ eval "$init_command" &&
+- echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect &&
++ case "$expected_dir" in
++ /*) EXPECT_ABS="$expected_dir" ;;
++ *) EXPECT_ABS="$ROOT/$expected_dir" ;;
++ esac &&
++ echo "path.$field_name.absolute=$EXPECT_ABS" >expect &&
+ git repo info "path.$field_name.absolute" >actual &&
+ test_cmp expect actual
+ )
+@@ t/t1900-repo-info.sh: test_repo_info_path () {
+ cd repo/sub &&
+ ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
+ eval "$init_command" &&
+- echo "path.$field_name.relative=../$expected_dir" >expect &&
++ case "$expected_dir" in
++ /*) EXPECT_REL="$(test-tool path-utils relative_path "$expected_dir" "$PWD")" ;;
++ *) EXPECT_REL="../$expected_dir" ;;
++ esac &&
++ echo "path.$field_name.relative=$EXPECT_REL" >expect &&
+ git repo info "path.$field_name.relative" >actual &&
+ test_cmp expect actual
+ )
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
'.git' \
'GIT_DIR="../.git" && export GIT_DIR'
-+test_repo_info_path 'hooks standard fallback' 'hooks' '.git/hooks' ++test_repo_info_path 'hooks standard' 'hooks' '.git/hooks'
+
+test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
+ 'custom-hooks' \
+ 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"'
+
- test_repo_info_path 'objects standard' 'objects' '.git/objects'
-
- test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \
++# /dev/null is not a real, canonicalizable filesystem path on Windows,
++# so path resolution for core.hooksPath=/dev/null cannot be expected to
++# produce a literal "/dev/null" the way it does on POSIX systems.
++if ! test_have_prereq MINGW
++then
++ test_repo_info_path 'hooks with core.hooksPath=/dev/null' 'hooks' \
++ '/dev/null' \
++ 'git config core.hooksPath /dev/null'
++fi
++
+ test_expect_success 'path.superproject-root absolute and relative' '
+ test_when_finished "rm -rf sub super" &&
+ git init sub &&
5: ab157b8b49 ! 4: 37d28712de repo: add path.index with absolute and relative suffix formatting
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: add path.index with absolute and relative suffix formatting
+ repo: add path.index with absolute and relative suffixes
- External script workflows and formatting layers require straightforward
- access to the location of the index staging file. Currently, tracking
- this necessitates a legacy call to git rev-parse --git-path index or
- --show-toplevel logic abstractions.
+ The repository index is a fundamental component used by Git and related
+ tooling to track the working tree state. Scripts that interact with the
+ index currently retrieve its location by invoking
+ git rev-parse --git-path index.
Introduce path.index.absolute and path.index.relative keys to
- git repo info. This allows tooling utilities to discover the active
- index context cleanly while scaling transparently with localized
- GIT_INDEX_FILE environment overrides.
+ git repo info. This exposes the index file location as a scriptable
+ config-like key using standard format rules, allowing scripts to
+ retrieve it through the same interface as other repository path
+ information.
@@ Commit message
## Documentation/git-repo.adoc ##
@@ Documentation/git-repo.adoc: values that they return:
The path to the repository's hooks directory relative to the current
- working directory. Respects core.hooksPath configuration adjustments.
+ working directory. Respects the core.hooksPath configuration.
+path.index.absolute::
+ The canonical absolute path to the repository's current index file.
-+ Respects the GIT_INDEX_FILE environment override. The returned path
-+ reflects the configured/default index location regardless of whether the
-+ repository is bare or whether the file currently exists.
++ Respects the GIT_INDEX_FILE environment override. Returns the
++ configured index path even if the repository is bare or the file does
++ not exist.
+
+path.index.relative::
+ The path to the repository's current index file relative to the current
+ working directory. Respects the GIT_INDEX_FILE environment override.
-+ The returned path reflects the configured/default index location regardless
-+ of whether the repository is bare or whether the file currently exists.
++ Returns the configured index path even if the repository is bare or the
++ file does not exist.
+
- path.objects.absolute::
- The canonical absolute path to the repository's object database directory.
- Respects the GIT_OBJECT_DIRECTORY environment override.
+ path.superproject-root.absolute::
+ The canonical absolute path to the working tree root of the superproject
+ if the current repository is an initialized submodule. Outputs an empty
## builtin/repo.c ##
@@ builtin/repo.c: static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf)
@@ builtin/repo.c: static int get_path_hooks_relative(struct repository *repo, stru
+ if (!index_file)
+ return error(_("unable to get index file"));
+
-+ format_path(buf, index_file, startup_info->prefix, PATH_FORMAT_CANONICAL);
++ format_path(buf, index_file, "", PATH_FORMAT_CANONICAL);
+ return 0;
+}
+
@@ builtin/repo.c: static int get_path_hooks_relative(struct repository *repo, stru
+ if (!index_file)
+ return error(_("unable to get index file"));
+
-+ format_path(buf, index_file, startup_info->prefix, PATH_FORMAT_RELATIVE);
++ format_path(buf, index_file, repo->prefix, PATH_FORMAT_RELATIVE);
+ return 0;
+}
+
- static int get_path_objects_absolute(struct repository *repo, struct strbuf *buf)
+ static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) {
- const char *obj_dir = repo_get_object_directory(repo);
+ struct strbuf superproject = STRBUF_INIT;
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
{ "path.gitdir.relative", get_path_gitdir_relative },
{ "path.hooks.absolute", get_path_hooks_absolute },
{ "path.hooks.relative", get_path_hooks_relative },
+ { "path.index.absolute", get_path_index_absolute },
+ { "path.index.relative", get_path_index_relative },
- { "path.objects.absolute", get_path_objects_absolute },
- { "path.objects.relative", get_path_objects_relative },
- { "path.superproject-working-tree.absolute", get_path_superproject_absolute },
+ { "path.superproject-root.absolute", get_path_superproject_absolute },
+ { "path.superproject-root.relative", get_path_superproject_relative },
+ { "path.toplevel.absolute", get_path_toplevel_absolute },
## t/t1900-repo-info.sh ##
-@@ t/t1900-repo-info.sh: test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
- 'custom-hooks' \
- 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"'
+@@ t/t1900-repo-info.sh: then
+ 'git config core.hooksPath /dev/null'
+ fi
+test_repo_info_path 'index standard' 'index' '.git/index'
+
@@ t/t1900-repo-info.sh: test_repo_info_path 'hooks with core.hooksPath override' '
+ )
+'
+
- test_repo_info_path 'objects standard' 'objects' '.git/objects'
-
- test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \
+ test_expect_success 'path.superproject-root absolute and relative' '
+ test_when_finished "rm -rf sub super" &&
+ git init sub &&
6: d80719367b ! 5: d88340f5a6 repo: add path.grafts with absolute and relative suffix formatting
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: add path.grafts with absolute and relative suffix formatting
+ repo: add path.grafts with absolute and relative suffixes
- External toolchains managing specialized history rewrites or legacy
- history splices require access to the location of the repository grafts
- file. Currently, this requires a legacy call to git rev-parse --git-path info/grafts.
+ The repository grafts file specifies alternate parent relationships for
+ commits and may be used by repository tooling that needs to inspect or
+ manage grafts. Scripts currently retrieve its location by invoking
+ git rev-parse --git-path info/grafts.
Introduce path.grafts.absolute and path.grafts.relative keys to
- git repo info. This allows scripting layers to query the active grafts
- context cleanly while scaling transparently with active GIT_GRAFT_FILE
- environment variable overrides.
+ git repo info. This exposes the grafts file location as a scriptable
+ config-like key using standard format rules, allowing scripts to
+ retrieve it through the same interface as other repository path
+ information.
@@ Documentation/git-repo.adoc: values that they return:
The path to the Git repository directory relative to the current working directory.
+path.grafts.absolute::
-+ The canonical absolute path to the repository grafts file.
-+ Respects the GIT_GRAFT_FILE environment override. The path is returned
-+ regardless of whether the file currently exists on disk.
++ The canonical absolute path to the repository's graft file.
++ Respects the GIT_GRAFT_FILE environment override. The path is
++ returned regardless of whether the file currently exists on disk.
+
+path.grafts.relative::
-+ The path to the repository grafts file relative to the current working
-+ directory. Respects the GIT_GRAFT_FILE environment override. The path
-+ is returned regardless of whether the file currently exists on disk.
++ The path to the repository's graft file relative to the current
++ working directory. Respects the GIT_GRAFT_FILE environment
++ override. The path is returned regardless of whether the file
++ currently exists on disk.
+
path.hooks.absolute::
The canonical absolute path to the repository's hooks directory.
- Respects core.hooksPath configuration adjustments.
+ Respects the core.hooksPath configuration. If core.hooksPath is
## builtin/repo.c ##
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+ if (!graft_file)
+ return error(_("unable to get graft file"));
+
-+ format_path(buf, graft_file, startup_info->prefix, PATH_FORMAT_CANONICAL);
++ format_path(buf, graft_file, "", PATH_FORMAT_CANONICAL);
+ return 0;
+}
+
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+ if (!graft_file)
+ return error(_("unable to get graft file"));
+
-+ format_path(buf, graft_file, startup_info->prefix, PATH_FORMAT_RELATIVE);
++ format_path(buf, graft_file, repo->prefix, PATH_FORMAT_RELATIVE);
+ return 0;
+}
+
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
+ 'custom-graft-file' \
+ 'GIT_GRAFT_FILE="$ROOT/custom-graft-file" && export GIT_GRAFT_FILE'
+
- test_repo_info_path 'hooks standard fallback' 'hooks' '.git/hooks'
+ test_repo_info_path 'hooks standard' 'hooks' '.git/hooks'
test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
7: ac6aee77e8 ! 6: 38b19d8bfd repo: add path.git-prefix path key
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: add path.git-prefix path key
+ repo: add path.git-prefix
- Scripts and command-line prompt integrations frequently need to know their
- relative depth inside a repository working tree layout. Currently, this
- is retrieved using `git rev-parse --show-prefix`.
+ Scripts sometimes need the path from the repository's working tree root
+ to the current working directory. While this information can be derived
+ through existing Git commands, `git repo info` does not currently expose
+ it as a scriptable key.
- Introduce the `path.git-prefix` key to `git repo info`. This mirrors the
- prefix location tracking framework as a standalone key, returning the
- exact relative path offset complete with a trailing slash, or an empty
- string if run directly at the repository working tree root.
+ Introduce the `path.git-prefix` key to `git repo info`. The key returns
+ the path from the working tree root to the current working directory,
+ returning the empty string when invoked from the working tree root.
Mentored-by: Justin Tobler <[email protected]>
Mentored-by: Lucas Seiki Oshiro <[email protected]>
@@ Documentation/git-repo.adoc: values that they return:
the current working directory.
+`path.git-prefix`::
-+ The relative path from the top-level directory of the working tree to
-+ the current working directory (including a trailing slash). Outputs an
-+ empty string if executed at the root of the working tree.
++ The path from the root of the working tree to the current working
++ directory. Returns the empty string when the current working directory
++ is the root of the working tree.
+
`path.gitdir.absolute`::
The canonical absolute path to the Git repository directory (the `.git` directory).
@@ builtin/repo.c: static int get_path_commondir_relative(struct repository *repo,
return 0;
}
-+static int get_path_git_prefix(struct repository *repo UNUSED, struct strbuf *buf)
++static int get_path_git_prefix(struct repository *repo, struct strbuf *buf)
+{
+ /*
-+ * startup_info->prefix is NULL if we are at the working tree root.
-+ * We add an empty string to ensure the buffer is cleanly initialized.
++ * repo->prefix is NULL when the current working directory is
++ * the worktree root.
+ */
-+ strbuf_addstr(buf, startup_info->prefix ? startup_info->prefix : "");
++ strbuf_addstr(buf, repo->prefix ? repo->prefix : "");
+ return 0;
+}
+
@@ t/t1900-repo-info.sh: test_repo_info_path 'commondir with only GIT_DIR' 'commond
'.git' \
'GIT_DIR="../.git" && export GIT_DIR'
-+test_expect_success 'path.git-prefix at root and in a subdirectory' '
++test_expect_success 'path.git-prefix at repository root' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
++ echo "path.git-prefix=" >expect &&
++ git repo info path.git-prefix >actual &&
++ test_cmp expect actual
++ )
++'
+
-+ echo "path.git-prefix=" >expect.root &&
-+ git repo info path.git-prefix >actual.root &&
-+ test_cmp expect.root actual.root &&
-+
-+ mkdir -p sub/dir &&
-+ cd sub/dir &&
-+
-+ echo "path.git-prefix=sub/dir/" >expect.sub &&
-+ git repo info path.git-prefix >actual.sub &&
-+ test_cmp expect.sub actual.sub
++test_expect_success 'path.git-prefix in subdirectory' '
++ test_when_finished "rm -rf repo" &&
++ git init repo &&
++ mkdir -p repo/sub/dir &&
++ (
++ cd repo/sub/dir &&
++ echo "path.git-prefix=sub/dir/" >expect &&
++ git repo info path.git-prefix >actual &&
++ test_cmp expect actual
+ )
+'
+3: 736c8e0576 ! 7: f28ee4e169 repo: add path.objects with absolute and relative suffix formatting
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: add path.objects with absolute and relative suffix formatting
+ repo: remove unused setup.h include
- Tools and deployment hooks frequently query the location of the object
- database directory. Currently, this relies on legacy parsing methods or
- manually inspecting git rev-parse --git-path objects.
+ The repository prefix is now stored in struct repository, so
+ builtin/repo.c no longer uses any declarations from setup.h.
- Introduce path.objects.absolute and path.objects.relative keys to
- git repo info. This allows tools to discover the object database
- location safely while natively adhering to active GIT_OBJECT_DIRECTORY
- environment variable overrides.
+ Remove the now-unused include.
- ## Documentation/git-repo.adoc ##
-@@ Documentation/git-repo.adoc: values that they return:
- path.gitdir.relative::
- The path to the Git repository directory relative to the current working directory.
-
-+path.objects.absolute::
-+ The canonical absolute path to the repository's object database directory.
-+ Respects the GIT_OBJECT_DIRECTORY environment override.
-+
-+path.objects.relative::
-+ The path to the repository's object database directory relative to the
-+ current working directory. Respects the GIT_OBJECT_DIRECTORY
-+ environment override.
-+
- path.superproject-working-tree.absolute::
- The canonical absolute path to the working tree root of the superproject
- if the current repository is an initialized submodule. Outputs an empty
-
## builtin/repo.c ##
-@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)
- return 0;
- }
-
-+static int get_path_objects_absolute(struct repository *repo, struct strbuf *buf) -+{
-+ const char *obj_dir = repo_get_object_directory(repo);
-+
-+ if (!obj_dir)
-+ return error(_("unable to get object directory"));
-+
-+ format_path(buf, obj_dir, startup_info->prefix, PATH_FORMAT_CANONICAL);
-+ return 0;
-+}
-+
-+static int get_path_objects_relative(struct repository *repo, struct strbuf *buf) -+{
-+ const char *obj_dir = repo_get_object_directory(repo);
-+
-+ if (!obj_dir)
-+ return error(_("unable to get object directory"));
-+
-+ format_path(buf, obj_dir, startup_info->prefix, PATH_FORMAT_RELATIVE);
-+ return 0;
-+}
-+
- static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf)
- {
- struct strbuf superproject = STRBUF_INIT;
-@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
- { "path.commondir.relative", get_path_commondir_relative },
- { "path.gitdir.absolute", get_path_gitdir_absolute },
- { "path.gitdir.relative", get_path_gitdir_relative },
-+ { "path.objects.absolute", get_path_objects_absolute },
-+ { "path.objects.relative", get_path_objects_relative },
- { "path.superproject-working-tree.absolute", get_path_superproject_absolute },
- { "path.superproject-working-tree.relative", get_path_superproject_relative },
- { "path.toplevel.absolute", get_path_toplevel_absolute },
-
- ## t/t1900-repo-info.sh ##
-@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
- '.git' \
- 'GIT_DIR="../.git" && export GIT_DIR'
-
-+test_repo_info_path 'objects standard' 'objects' '.git/objects'
-+
-+test_repo_info_path 'objects with GIT_OBJECT_DIRECTORY override' 'objects' \
-+ 'custom-objects' \
-+ 'GIT_OBJECT_DIRECTORY="$ROOT/custom-objects" && export GIT_OBJECT_DIRECTORY &&
-+ mkdir -p "$ROOT/custom-objects"'
-+
- test_expect_success 'path.superproject-working-tree absolute and relative' '
- test_when_finished "rm -rf sub super" &&
- git init sub &&
+@@
+ #include "ref-filter.h"
+ #include "refs.h"
+ #include "revision.h"
+-#include "setup.h"
+ #include "strbuf.h"
+ #include "string-list.h"
+ #include "shallow.h"
Signature · 1 line
2.55.GIT
PATCH v4 1/7 repo: add path.toplevel with absolute and relative suffix formatting
Scripts frequently need to find the root directory of a repository's working tree. Currently, this requires using git rev-parse --show-toplevel or inferring it from other repository information.
Introduce path.toplevel.absolute and path.toplevel.relative keys to git repo info. This allows scripts to retrieve the top-level working tree path in a predictable, strictly formatted manner without relying on rev-parse.
If requested in a bare repository where no working tree exists, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.toplevel.absolute`:: + The canonical absolute path to the top-level directory of the + repository's working tree. Outputs an empty string if the repository + is bare. + +`path.toplevel.relative`:: + The path to the top-level directory of the repository's working + tree relative to the current working directory. Outputs an empty + string if the repository is bare. + `references.format`:: The reference storage format. The valid values are: +
builtin/repo.c +24 -0
@@ -121,6 +121,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) +return 0 ; + +format_path (buf, work_tree,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_toplevel_relative (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) +return 0 ; + +format_path (buf, work_tree, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_references_format (struct repository *repo,struct strbuf *buf) { strbuf_addstr(buf,
@@ -137,6 +159,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.toplevel.absolute", get_path_toplevel_absolute }, + { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format }, };
t/t1900-repo-info.sh +35 -0
@@ -213,4 +213,39 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.toplevel absolute and relative' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.toplevel.absolute=$ROOT" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=../" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.toplevel absolute and relative in a bare repository' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + + echo "path.toplevel.absolute=" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_done
Signature · 1 line
2.55.GIT
PATCH v4 2/7 repo: add path.superproject-root with absolute and relative suffixes
In reply to K JayatheerthScripts working in multi-repository setups often need to identify the top-level working tree of a superproject from within a submodule. Currently, this is only exposed via git rev-parse --show-superproject-working-tree.
Introduce path.superproject-root.absolute and path.superproject-root.relative keys to git repo info. This exposes the core submodule context via a scriptable config-like key using standard format rules.
If requested when not inside a submodule, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 31 +++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.superproject-root.absolute`:: + The canonical absolute path to the working tree root of the superproject + if the current repository is an initialized submodule. Outputs an empty + string if not in a submodule. + +`path.superproject-root.relative`:: + The path to the working tree root of the superproject relative to the + current working directory if the current repository is an initialized + submodule. Outputs an empty string if not in a submodule. + `path.toplevel.absolute`:: The canonical absolute path to the top-level directory of the repository's working tree. Outputs an empty string if the repository
builtin/repo.c +31 -0
@@ -18,6 +18,7 @@#include "strbuf.h" #include "string-list.h" #include "shallow.h" +#include "submodule.h" #include "tree.h" #include "tree-walk.h" #include "utf8.h"
@@ -121,6 +122,34 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +return 0 ; + } + +format_path (buf, superproject.buf,"" ,PATH_FORMAT_CANONICAL ); +strbuf_release (&superproject); +return 0 ; +} + +static int get_path_superproject_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +return 0 ; + } + +format_path (buf, superproject.buf, repo->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&superproject); +return 0 ; +} +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) {const char *work_tree =repo_get_work_tree (repo);
@@ -159,6 +188,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.superproject-root.absolute", get_path_superproject_absolute }, + { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute }, { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format },
t/t1900-repo-info.sh +39 -0
@@ -213,6 +213,45 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.superproject-root absolute and relative' ' + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + cd sub && + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.superproject-root.absolute=$ROOT" >expect.abs && + git repo info path.superproject-root.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superproject-root.relative=../" >expect.rel && + git repo info path.superproject-root.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.superproject-root returns empty when not in a submodule' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + echo "path.superproject-root.absolute=" >expect.abs && + git repo info path.superproject-root.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superproject-root.relative=" >expect.rel && + git repo info path.superproject-root.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_expect_success 'path.toplevel absolute and relative' ' test_when_finished "rm -rf repo" && git init repo &&
Signature · 1 line
2.55.GIT
PATCH v4 3/7 repo: add path.hooks with absolute and relative suffixes
In reply to K JayatheerthHooks are an integral part of a repository's configuration and are commonly used by tooling to automate repository-specific workflows. Currently, scripts typically retrieve the hooks directory by invoking git rev-parse --git-path hooks.
Introduce path.hooks.absolute and path.hooks.relative keys to git repo info. This exposes the hooks directory as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 9 +++++++++ builtin/repo.c | 22 ++++++++++++++++++++++ t/t1900-repo-info.sh | 28 ++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-)
Documentation/git-repo.adoc +9 -0
@@ -119,6 +119,15 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.hooks.absolute`:: + The canonical absolute path to the repository's hooks directory. + Respects the `core.hooksPath` configuration. If `core.hooksPath` is + set to `/dev/null`, that value is returned unchanged. + +`path.hooks.relative`:: + The path to the repository's hooks directory relative to the current + working directory. Respects the `core.hooksPath` configuration. + `path.superproject-root.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +22 -0
@@ -122,6 +122,26 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf,"" ,PATH_FORMAT_CANONICAL ); +strbuf_release (&hooks_path); +return 0 ; +} + +static int get_path_hooks_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf, repo->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&hooks_path); +return 0 ; +} + static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -188,6 +208,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.hooks.absolute", get_path_hooks_absolute }, + { "path.hooks.relative", get_path_hooks_relative }, { "path.superproject-root.absolute", get_path_superproject_absolute }, { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +26 -2
@@ -174,7 +174,11 @@ test_repo_info_path () { cd repo/sub && ROOT="$(test-tool path-utils real_path ..)" && export ROOT && eval "$init_command" && - echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect && + case "$expected_dir" in + /*) EXPECT_ABS="$expected_dir" ;; + *) EXPECT_ABS="$ROOT/$expected_dir" ;; + esac && + echo "path.$field_name.absolute=$EXPECT_ABS" >expect && git repo info "path.$field_name.absolute" >actual && test_cmp expect actual )
@@ -188,7 +192,11 @@ test_repo_info_path () { cd repo/sub && ROOT="$(test-tool path-utils real_path ..)" && export ROOT && eval "$init_command" && - echo "path.$field_name.relative=../$expected_dir" >expect && + case "$expected_dir" in + /*) EXPECT_REL="$(test-tool path-utils relative_path "$expected_dir" "$PWD")" ;; + *) EXPECT_REL="../$expected_dir" ;; + esac && + echo "path.$field_name.relative=$EXPECT_REL" >expect && git repo info "path.$field_name.relative" >actual && test_cmp expect actual )
@@ -213,6 +221,22 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'hooks standard' 'hooks' '.git/hooks' + +test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ + 'custom-hooks' \ + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' + +# /dev/null is not a real, canonicalizable filesystem path on Windows, +# so path resolution for core.hooksPath=/dev/null cannot be expected to +# produce a literal "/dev/null" the way it does on POSIX systems. +if ! test_have_prereq MINGW +then + test_repo_info_path 'hooks with core.hooksPath=/dev/null' 'hooks' \ + '/dev/null' \ + 'git config core.hooksPath /dev/null' +fi + test_expect_success 'path.superproject-root absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.55.GIT
PATCH v4 4/7 repo: add path.index with absolute and relative suffixes
In reply to K JayatheerthThe repository index is a fundamental component used by Git and related tooling to track the working tree state. Scripts that interact with the index currently retrieve its location by invokinggit rev-parse --git-path index.
Introduce path.index.absolute and path.index.relative keys to git repo info. This exposes the index file location as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 12 ++++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 59 insertions(+)
Documentation/git-repo.adoc +12 -0
@@ -128,6 +128,18 @@ values that they return: The path to the repository's hooks directory relative to the current working directory. Respects the `core.hooksPath` configuration. +`path.index.absolute`:: + The canonical absolute path to the repository's current index file. + Respects the `GIT_INDEX_FILE` environment override. Returns the + configured index path even if the repository is bare or the file does + not exist. + +`path.index.relative`:: + The path to the repository's current index file relative to the current + working directory. Respects the `GIT_INDEX_FILE` environment override. + Returns the configured index path even if the repository is bare or the + file does not exist. + `path.superproject-root.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +24 -0
@@ -142,6 +142,28 @@ static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_index_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_index_relative (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} + static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -210,6 +232,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.gitdir.relative", get_path_gitdir_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, + { "path.index.absolute", get_path_index_absolute }, + { "path.index.relative", get_path_index_relative }, { "path.superproject-root.absolute", get_path_superproject_absolute }, { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +23 -0
@@ -237,6 +237,29 @@ then 'git config core.hooksPath /dev/null' fi +test_repo_info_path 'index standard' 'index' '.git/index' + +test_repo_info_path 'index with GIT_INDEX_FILE override' 'index' \ + 'custom-index-file' \ + 'GIT_INDEX_FILE="$ROOT/custom-index-file" && export GIT_INDEX_FILE' + +test_expect_success 'path.index in a bare repository returns default index location' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + ROOT="$(test-tool path-utils real_path .)" && + + echo "path.index.absolute=$ROOT/index" >expect.abs && + git repo info path.index.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.index.relative=index" >expect.rel && + git repo info path.index.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_expect_success 'path.superproject-root absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.55.GIT
PATCH v4 5/7 repo: add path.grafts with absolute and relative suffixes
In reply to K JayatheerthThe repository grafts file specifies alternate parent relationships for commits and may be used by repository tooling that needs to inspect or manage grafts. Scripts currently retrieve its location by invoking git rev-parse --git-path info/grafts.
Introduce path.grafts.absolute and path.grafts.relative keys to git repo info. This exposes the grafts file location as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 11 +++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 6 ++++++ 3 files changed, 41 insertions(+)
Documentation/git-repo.adoc +11 -0
@@ -119,6 +119,17 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.grafts.absolute`:: + The canonical absolute path to the repository's graft file. + Respects the `GIT_GRAFT_FILE` environment override. The path is + returned regardless of whether the file currently exists on disk. + +`path.grafts.relative`:: + The path to the repository's graft file relative to the current + working directory. Respects the `GIT_GRAFT_FILE` environment + override. The path is returned regardless of whether the file + currently exists on disk. + `path.hooks.absolute`:: The canonical absolute path to the repository's hooks directory. Respects the `core.hooksPath` configuration. If `core.hooksPath` is
builtin/repo.c +24 -0
@@ -122,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_grafts_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_grafts_relative (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf hooks_path =STRBUF_INIT ;
@@ -230,6 +252,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.grafts.absolute", get_path_grafts_absolute }, + { "path.grafts.relative", get_path_grafts_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, { "path.index.absolute", get_path_index_absolute },
t/t1900-repo-info.sh +6 -0
@@ -221,6 +221,12 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'grafts standard' 'grafts' '.git/info/grafts' + +test_repo_info_path 'grafts with GIT_GRAFT_FILE override' 'grafts' \ + 'custom-graft-file' \ + 'GIT_GRAFT_FILE="$ROOT/custom-graft-file" && export GIT_GRAFT_FILE' + test_repo_info_path 'hooks standard' 'hooks' '.git/hooks' test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
Signature · 1 line
2.55.GIT
PATCH v4 6/7 repo: add path.git-prefix
In reply to K JayatheerthScripts sometimes need the path from the repository's working tree root to the current working directory. While this information can be derived through existing Git commands, git repo info does not currently expose it as a scriptable key.
Introduce the path.git-prefix key to git repo info. The key returns the path from the working tree root to the current working directory, returning the empty string when invoked from the working tree root.
--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 11 +++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+)
Documentation/git-repo.adoc +5 -0
@@ -113,6 +113,11 @@ values that they return: The path to the Git repository's common directory relative to the current working directory. +`path.git-prefix`:: + The path from the root of the working tree to the current working + directory. Returns the empty string when the current working directory + is the root of the working tree. + `path.gitdir.absolute`:: The canonical absolute path to the Git repository directory (the `.git` directory).
builtin/repo.c +11 -0
@@ -100,6 +100,16 @@ static int get_path_commondir_relative(struct repository *repo, struct strbuf *breturn 0 ; } +static int get_path_git_prefix (struct repository *repo,struct strbuf *buf) +{ +/* +* repo->prefix is NULL when the current working directory is +* the worktree root. +*/ +strbuf_addstr (buf, repo->prefix ? repo->prefix :"" ); +return 0 ; +} +static int get_path_gitdir_absolute (struct repository *repo,struct strbuf *buf) {const char *git_dir =repo_get_git_dir (repo);
@@ -250,6 +260,7 @@ static const struct repo_info_field repo_info_field[] = { { "object.format", get_object_format }, { "path.commondir.absolute", get_path_commondir_absolute }, { "path.commondir.relative", get_path_commondir_relative }, + { "path.git-prefix", get_path_git_prefix }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, { "path.grafts.absolute", get_path_grafts_absolute },
t/t1900-repo-info.sh +23 -0
@@ -215,6 +215,29 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.git-prefix at repository root' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.git-prefix=" >expect && + git repo info path.git-prefix >actual && + test_cmp expect actual + ) +' + +test_expect_success 'path.git-prefix in subdirectory' ' + test_when_finished "rm -rf repo" && + git init repo && + mkdir -p repo/sub/dir && + ( + cd repo/sub/dir && + echo "path.git-prefix=sub/dir/" >expect && + git repo info path.git-prefix >actual && + test_cmp expect actual + ) +' + test_repo_info_path 'gitdir standard' 'gitdir' '.git' test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
Signature · 1 line
2.55.GIT
Re: [GSoC PATCH v4 6/7] repo: add path.git-prefix
Quoted 5 lines
Scripts sometimes need the path from the repository's working tree root to the current working directory. While this information can be derived through existing Git commands,
git repo infodoes not currently expose it as a scriptable key.
Even though I understand that this is a relevant info, it seems to me that it's a little bit out of place here... This is a "current directory information", not a "repository information".
Quoted 1 line
Re: [GSoC PATCH v4 6/7] repo: add path.git-prefix
Quoted 11 lines · Lucas Seiki Oshiro
Quoted 6 lines
Scripts sometimes need the path from the repository's working tree root to the current working directory. While this information can be derived through existing Git commands,
git repo infodoes not currently expose it as a scriptable key.Even though I understand that this is a relevant info, it seems to me that it's a little bit out of place here... This is a "current directory information", not a "repository information".
Quoted 1 line
I agree that path.git-prefix is technically current-directory information rather than repository information.
I included it because it is useful path information for scripts operating within a repository,
and it is already exposed by git rev-parse --show-prefix. I thought it would fit the purpose of this series, but I can drop it if you think it is better kept separate.
Re: [GSoC PATCH v4 6/7] repo: add path.git-prefix
Quoted 9 lines · K Jayatheerth
Quoted 7 lines · Lucas Seiki Oshiro
Quoted 6 lines
Scripts sometimes need the path from the repository's working tree root to the current working directory. While this information can be derived through existing Git commands,
git repo infodoes not currently expose it as a scriptable key.
Quoted 6 lines
Quoted 3 lines
Even though I understand that this is a relevant info, it seems to me that it's a little bit out of place here... This is a "current directory information", not a "repository information".
I agree that path.git-prefix is technically current-directory information rather than repository information.
The same thing can be said about "git rev-parse --show-cdup"; you can complain that it is about the current working directory, but in reality it is about how to get to the root of the working tree you are currently working in, which means that it is very much about repository information, only given as a relative path. Nobody would complain that you have 'path.commondir.relative' when you already offer its '.absolute' counterpart, saying that '.relative' is about your current working directory and not about the repository, right?
The same story holds for 'path.git-prefix', I would think. View it, and "git rev-parse --show-prefix", as the inverse version of a 'path.root-of-the-working-tree.relative' (aka 'path.cdup') rather than as being about the "current directory".
Oh, and if you are offering git-prefix, you should offer cdup as well.
Thanks.
Re: [GSoC PATCH v4 6/7] repo: add path.git-prefix
Quoted 19 lines · Junio C Hamano
Quoted 9 lines · K Jayatheerth
Quoted 7 lines · Lucas Seiki Oshiro
Quoted 6 lines
Scripts sometimes need the path from the repository's working tree root to the current working directory. While this information can be derived through existing Git commands,
git repo infodoes not currently expose it as a scriptable key.Quoted 6 lines
Quoted 3 lines
Even though I understand that this is a relevant info, it seems to me that it's a little bit out of place here... This is a "current directory information", not a "repository information".
I agree that path.git-prefix is technically current-directory information rather than repository information.
Quoted 9 lines
The same thing can be said about "git rev-parse --show-cdup"; you can complain that it is about the current working directory, but in reality it is about how to get to the root of the working tree you are currently working in, which means that it is very much about repository information, only given as a relative path. Nobody would complain that you have 'path.commondir.relative' when you already offer its '.absolute' counterpart, saying that '.relative' is about your current working directory and not about the repository, right?
Very true, I agree with you. I believe cdup and git-prefix complement each other well, so it makes sense to expose both.
Quoted 8 lines
The same story holds for 'path.git-prefix', I would think. View it, and "git rev-parse --show-prefix", as the inverse version of a 'path.root-of-the-working-tree.relative' (aka 'path.cdup') rather than as being about the "current directory".
Oh, and if you are offering git-prefix, you should offer cdup as well.
Sure, I will add cdup in the next version and send it.
Thank you!
- K Jayatheerth
PATCH v4 7/7 repo: remove unused setup.h include
In reply to K JayatheerthThe repository prefix is now stored in struct repository, so builtin/repo.c no longer uses any declarations from setup.h.
Remove the now-unused include.
--- builtin/repo.c | 1 - 1 file changed, 1 deletion(-)
builtin/repo.c +0 -1
@@ -14,7 +14,6 @@#include "ref-filter.h" #include "refs.h" #include "revision.h" -#include "setup.h" #include "strbuf.h" #include "string-list.h" #include "shallow.h"
Signature · 1 line
2.55.GIT
v5 cover add more path keys to git repo info
In reply to K JayatheerthSeries adds keys to git repo info.
Keys output paths of repository components:
* path.toplevel: repository tree.
* path.superproject-root: superproject tree from submodules.
* path.hooks: repository hooks.
* path.index: repository index.
* path.grafts: repository grafts.
* path.git-prefix: prefix offset.
* path.cdup: relative path to top level from subdirectory.
Keys support suffixes for format.
Commits contain documentation and tests.
changes since v4:
* Add path.cdup in git repo.
* Drop unused header cleanup patch as it will be sent in the next set of cleanup only patches.
K Jayatheerth (7):
repo: add path.toplevel with absolute and relative suffix formatting
repo: add path.superproject-root with absolute and relative suffixes
repo: add path.hooks with absolute and relative suffixes
repo: add path.index with absolute and relative suffixes
repo: add path.grafts with absolute and relative suffixes
repo: add path.git-prefix
repo: add path.cdup
Documentation/git-repo.adoc | 62 +++++++++++++ builtin/repo.c | 151 ++++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 177 +++++++++++++++++++++++++++++++++++- 3 files changed, 388 insertions(+), 2 deletions(-)
Range-diff against v4:
1: db54cf2177 = 1: 3880485020 repo: add path.toplevel with absolute and relative suffix formatting 2: 5f5ab2b844 = 2: 1b7b0d286c repo: add path.superproject-root with absolute and relative suffixes 3: a8c3526958 = 3: 517f621eb0 repo: add path.hooks with absolute and relative suffixes 4: a419389911 = 4: 37d28712de repo: add path.index with absolute and relative suffixes 5: a5a28f2e92 = 5: d88340f5a6 repo: add path.grafts with absolute and relative suffixes 6: 39775f8d2f = 6: 38b19d8bfd repo: add path.git-prefix 7: 74dbca6f17 ! 7: d6ce98e25e repo: remove unused setup.h include
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: remove unused setup.h include
+ repo: add path.cdup
- The repository prefix is now stored in struct repository, so
- builtin/repo.c no longer uses any declarations from setup.h.
+ Scripts sometimes need the relative path from the current working
+ directory to the repository's working tree root (cdup). While this
+ information can be retrieved through git rev-parse --show-cdup,
+ git repo info does not currently expose it as a scriptable key.
- Remove the now-unused include.
+ Introduce the path.cdup key to git repo info. The key returns the
+ path from the current working directory to the root of the working tree,
+ returning the empty string when invoked from the working tree root.
+ ## Documentation/git-repo.adoc ##
+@@ Documentation/git-repo.adoc: values that they return:
+ object.format::
+ The object format (hash algorithm) used in the repository.
+
++path.cdup::
++ The path to the root of the working tree relative to the current
++ working directory. Returns the empty string when the current
++ working directory is the root of the working tree.
++
+ path.commondir.absolute::
+ The canonical absolute path to the Git repository's common
+ directory (the shared .git directory containing objects,
+
## builtin/repo.c ##
-@@
- #include "ref-filter.h"
- #include "refs.h"
- #include "revision.h"
--#include "setup.h"
- #include "strbuf.h"
- #include "string-list.h"
- #include "shallow.h"
+@@ builtin/repo.c: static int get_object_format(struct repository *repo, struct strbuf *buf)
+ return 0;
+ }
+
++static int get_path_cdup(struct repository *repo, struct strbuf *buf)
++{
++ const char *pfx = repo->prefix;
++
++ while (pfx) {
++ pfx = strchr(pfx, '/');
++ if (pfx) {
++ pfx++;
++ strbuf_addstr(buf, "../");
++ }
++ }
++ return 0;
++}
++
+ static int get_path_commondir_absolute(struct repository *repo, struct strbuf *buf)
+ {
+ const char *common_dir = repo_get_common_dir(repo);
+@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
+ { "layout.bare", get_layout_bare },
+ { "layout.shallow", get_layout_shallow },
+ { "object.format", get_object_format },
++ { "path.cdup", get_path_cdup },
+ { "path.commondir.absolute", get_path_commondir_absolute },
+ { "path.commondir.relative", get_path_commondir_relative },
+ { "path.git-prefix", get_path_git_prefix },
+
+ ## t/t1900-repo-info.sh ##
+@@ t/t1900-repo-info.sh: test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \
+ '.git' \
+ 'GIT_DIR="../.git" && export GIT_DIR'
+
++test_expect_success 'path.cdup at repository root' '
++ test_when_finished "rm -rf repo" &&
++ git init repo &&
++ (
++ cd repo &&
++ echo "path.cdup=" >expect &&
++ git repo info path.cdup >actual &&
++ test_cmp expect actual
++ )
++'
++
++test_expect_success 'path.cdup in subdirectory' '
++ test_when_finished "rm -rf repo" &&
++ git init repo &&
++ mkdir -p repo/sub/dir &&
++ (
++ cd repo/sub/dir &&
++ echo "path.cdup=../../" >expect &&
++ git repo info path.cdup >actual &&
++ test_cmp expect actual
++ )
++'
++
+ test_expect_success 'path.git-prefix at repository root' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
Signature · 1 line
2.55.GIT
PATCH v5 1/7 repo: add path.toplevel with absolute and relative suffix formatting
Scripts frequently need to find the root directory of a repository's working tree. Currently, this requires using git rev-parse --show-toplevel or inferring it from other repository information.
Introduce path.toplevel.absolute and path.toplevel.relative keys to git repo info. This allows scripts to retrieve the top-level working tree path in a predictable, strictly formatted manner without relying on rev-parse.
If requested in a bare repository where no working tree exists, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.toplevel.absolute`:: + The canonical absolute path to the top-level directory of the + repository's working tree. Outputs an empty string if the repository + is bare. + +`path.toplevel.relative`:: + The path to the top-level directory of the repository's working + tree relative to the current working directory. Outputs an empty + string if the repository is bare. + `references.format`:: The reference storage format. The valid values are: +
builtin/repo.c +24 -0
@@ -121,6 +121,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) +return 0 ; + +format_path (buf, work_tree,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_toplevel_relative (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) +return 0 ; + +format_path (buf, work_tree, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_references_format (struct repository *repo,struct strbuf *buf) { strbuf_addstr(buf,
@@ -137,6 +159,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.toplevel.absolute", get_path_toplevel_absolute }, + { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format }, };
t/t1900-repo-info.sh +35 -0
@@ -213,4 +213,39 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.toplevel absolute and relative' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.toplevel.absolute=$ROOT" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=../" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.toplevel absolute and relative in a bare repository' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + + echo "path.toplevel.absolute=" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_done
Signature · 1 line
2.55.GIT
PATCH v5 2/7 repo: add path.superproject-root with absolute and relative suffixes
In reply to K JayatheerthScripts working in multi-repository setups often need to identify the top-level working tree of a superproject from within a submodule. Currently, this is only exposed via git rev-parse --show-superproject-working-tree.
Introduce path.superproject-root.absolute and path.superproject-root.relative keys to git repo info. This exposes the core submodule context via a scriptable config-like key using standard format rules.
If requested when not inside a submodule, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 31 +++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.superproject-root.absolute`:: + The canonical absolute path to the working tree root of the superproject + if the current repository is an initialized submodule. Outputs an empty + string if not in a submodule. + +`path.superproject-root.relative`:: + The path to the working tree root of the superproject relative to the + current working directory if the current repository is an initialized + submodule. Outputs an empty string if not in a submodule. + `path.toplevel.absolute`:: The canonical absolute path to the top-level directory of the repository's working tree. Outputs an empty string if the repository
builtin/repo.c +31 -0
@@ -18,6 +18,7 @@#include "strbuf.h" #include "string-list.h" #include "shallow.h" +#include "submodule.h" #include "tree.h" #include "tree-walk.h" #include "utf8.h"
@@ -121,6 +122,34 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +return 0 ; + } + +format_path (buf, superproject.buf,"" ,PATH_FORMAT_CANONICAL ); +strbuf_release (&superproject); +return 0 ; +} + +static int get_path_superproject_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +return 0 ; + } + +format_path (buf, superproject.buf, repo->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&superproject); +return 0 ; +} +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) {const char *work_tree =repo_get_work_tree (repo);
@@ -159,6 +188,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.superproject-root.absolute", get_path_superproject_absolute }, + { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute }, { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format },
t/t1900-repo-info.sh +39 -0
@@ -213,6 +213,45 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.superproject-root absolute and relative' ' + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + cd sub && + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.superproject-root.absolute=$ROOT" >expect.abs && + git repo info path.superproject-root.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superproject-root.relative=../" >expect.rel && + git repo info path.superproject-root.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.superproject-root returns empty when not in a submodule' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + echo "path.superproject-root.absolute=" >expect.abs && + git repo info path.superproject-root.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superproject-root.relative=" >expect.rel && + git repo info path.superproject-root.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_expect_success 'path.toplevel absolute and relative' ' test_when_finished "rm -rf repo" && git init repo &&
Signature · 1 line
2.55.GIT
Re: [GSoC Patch v5 2/7] repo: add path.superproject-root with absolute and relative suffixes
Quoted 12 lines · K Jayatheerth
builtin/repo.c +12
-0+static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +return 0 ; + } + +format_path (buf, superproject.buf,"" ,PATH_FORMAT_CANONICAL ); +strbuf_release (&superproject); +return 0 ;
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 146
Quoted 10 lines
builtin/repo.c +10
-0+} + +static int get_path_superproject_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +return 0 ; + }
Here get_superproject_working_tree() does not care what repository we are working on. Shouldn't it be updated to take "repo" as a parameter?
Since it begins like this:
int get_superproject_working_tree(struct strbuf *buf)
{
struct child_process cp = CHILD_PROCESS_INIT;
struct strbuf sb = STRBUF_INIT;
struct strbuf one_up = STRBUF_INIT;
char *cwd = xgetcwd();
int ret = 0;I suspect that it based its decision on where you happen to be.
It means that when I have a checkout of "git", with a submodule "sha1collisiondetection" at its top level already populated, in, say, /var/tmp/x/ directory, the following happens.
$ cd /var/tmp/x/git
$ git repo info path.gitdir.absolute
path.gitdir.absolute=/var/tmp/x/git/.git
$ git -C sha1collisiondetection repo info path.gitdir.absolute
path.gitdir.absolute=/var/tmp/x/git/.git/modules/sha1collisiondetection $ D=/var/tmp/x/git/.git/modules/sha1collisiondetection
$ git --git-dir="$D" repo info path.superproject-root.absolute
path.superproject-root.absolute=
$ git -C sha1collisiondetection repo info path.superproject-root.absolute
path.superproject-root.absolute=/var/tmp/x/gitThe last two ought to match, but only the latter works correctly.
Before this series starts reporting path.superproject-root, get_superproject_working_tree() needs to be corrected to work on the repository in question (instead of relying on where the process happens to be), no?
Re: [GSoC Patch v5 2/7] repo: add path.superproject-root with absolute and relative suffixes
Quoted 58 lines · Junio C Hamano
Quoted 12 lines · K Jayatheerth
builtin/repo.c +12
-0+static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +return 0 ; + } + +format_path (buf, superproject.buf,"" ,PATH_FORMAT_CANONICAL ); +strbuf_release (&superproject); +return 0 ;builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 146
Quoted 10 lines
builtin/repo.c +10
-0+} + +static int get_path_superproject_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (&superproject)) { +strbuf_release (&superproject); +return 0 ; + }Here
get_superproject_working_tree()does not care what repository we are working on. Shouldn't it be updated to take "repo" as a parameter?Since it begins like this:
int get_superproject_working_tree(struct strbuf *buf) { struct child_process cp = CHILD_PROCESS_INIT; struct strbuf sb = STRBUF_INIT; struct strbuf one_up = STRBUF_INIT; char *cwd = xgetcwd(); int ret = 0;I suspect that it based its decision on where you happen to be.
It means that when I have a checkout of "git", with a submodule "sha1collisiondetection" at its top level already populated, in, say,
/var/tmp/x/directory, the following happens.$ cd /var/tmp/x/git $ git repo info path.gitdir.absolute path.gitdir.absolute=/var/tmp/x/git/.git $ git -C sha1collisiondetection repo info path.gitdir.absolute path.gitdir.absolute=/var/tmp/x/git/.git/modules/sha1collisiondetection$ D=/var/tmp/x/git/.git/modules/sha1collisiondetection $ git --git-dir="$D" repo info path.superproject-root.absolute path.superproject-root.absolute= $ git -C sha1collisiondetection repo info path.superproject-root.absolute path.superproject-root.absolute=/var/tmp/x/git
Quoted 6 lines
The last two ought to match, but only the latter works correctly.
Before this series starts reporting path.superproject-root,
get_superproject_working_tree()needs to be corrected to work on the repository in question (instead of relying on where the process happens to be), no?
Yes, precisely.
I didn't think of it that way.
get_superproject_working_tree() currently relies on xgetcwd() rather than inspecting the target repository, which causes explicit repository contexts like --git-dir to break.
I will update get_superproject_working_tree() to take repo and update its callers accordingly, along with adding test coverage for --git-dir in v6.
Regards,
- K Jayatheerth
PATCH v5 3/7 repo: add path.hooks with absolute and relative suffixes
In reply to K JayatheerthHooks are an integral part of a repository's configuration and are commonly used by tooling to automate repository-specific workflows. Currently, scripts typically retrieve the hooks directory by invoking git rev-parse --git-path hooks.
Introduce path.hooks.absolute and path.hooks.relative keys to git repo info. This exposes the hooks directory as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 9 +++++++++ builtin/repo.c | 22 ++++++++++++++++++++++ t/t1900-repo-info.sh | 28 ++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-)
Documentation/git-repo.adoc +9 -0
@@ -119,6 +119,15 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.hooks.absolute`:: + The canonical absolute path to the repository's hooks directory. + Respects the `core.hooksPath` configuration. If `core.hooksPath` is + set to `/dev/null`, that value is returned unchanged. + +`path.hooks.relative`:: + The path to the repository's hooks directory relative to the current + working directory. Respects the `core.hooksPath` configuration. + `path.superproject-root.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +22 -0
@@ -122,6 +122,26 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf,"" ,PATH_FORMAT_CANONICAL ); +strbuf_release (&hooks_path); +return 0 ; +} + +static int get_path_hooks_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf, repo->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&hooks_path); +return 0 ; +} + static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -188,6 +208,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.hooks.absolute", get_path_hooks_absolute }, + { "path.hooks.relative", get_path_hooks_relative }, { "path.superproject-root.absolute", get_path_superproject_absolute }, { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +26 -2
@@ -174,7 +174,11 @@ test_repo_info_path () { cd repo/sub && ROOT="$(test-tool path-utils real_path ..)" && export ROOT && eval "$init_command" && - echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect && + case "$expected_dir" in + /*) EXPECT_ABS="$expected_dir" ;; + *) EXPECT_ABS="$ROOT/$expected_dir" ;; + esac && + echo "path.$field_name.absolute=$EXPECT_ABS" >expect && git repo info "path.$field_name.absolute" >actual && test_cmp expect actual )
@@ -188,7 +192,11 @@ test_repo_info_path () { cd repo/sub && ROOT="$(test-tool path-utils real_path ..)" && export ROOT && eval "$init_command" && - echo "path.$field_name.relative=../$expected_dir" >expect && + case "$expected_dir" in + /*) EXPECT_REL="$(test-tool path-utils relative_path "$expected_dir" "$PWD")" ;; + *) EXPECT_REL="../$expected_dir" ;; + esac && + echo "path.$field_name.relative=$EXPECT_REL" >expect && git repo info "path.$field_name.relative" >actual && test_cmp expect actual )
@@ -213,6 +221,22 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'hooks standard' 'hooks' '.git/hooks' + +test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ + 'custom-hooks' \ + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' + +# /dev/null is not a real, canonicalizable filesystem path on Windows, +# so path resolution for core.hooksPath=/dev/null cannot be expected to +# produce a literal "/dev/null" the way it does on POSIX systems. +if ! test_have_prereq MINGW +then + test_repo_info_path 'hooks with core.hooksPath=/dev/null' 'hooks' \ + '/dev/null' \ + 'git config core.hooksPath /dev/null' +fi + test_expect_success 'path.superproject-root absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.55.GIT
PATCH v5 4/7 repo: add path.index with absolute and relative suffixes
In reply to K JayatheerthThe repository index is a fundamental component used by Git and related tooling to track the working tree state. Scripts that interact with the index currently retrieve its location by invokinggit rev-parse --git-path index.
Introduce path.index.absolute and path.index.relative keys to git repo info. This exposes the index file location as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 12 ++++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 59 insertions(+)
Documentation/git-repo.adoc +12 -0
@@ -128,6 +128,18 @@ values that they return: The path to the repository's hooks directory relative to the current working directory. Respects the `core.hooksPath` configuration. +`path.index.absolute`:: + The canonical absolute path to the repository's current index file. + Respects the `GIT_INDEX_FILE` environment override. Returns the + configured index path even if the repository is bare or the file does + not exist. + +`path.index.relative`:: + The path to the repository's current index file relative to the current + working directory. Respects the `GIT_INDEX_FILE` environment override. + Returns the configured index path even if the repository is bare or the + file does not exist. + `path.superproject-root.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +24 -0
@@ -142,6 +142,28 @@ static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_index_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_index_relative (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} + static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -210,6 +232,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.gitdir.relative", get_path_gitdir_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, + { "path.index.absolute", get_path_index_absolute }, + { "path.index.relative", get_path_index_relative }, { "path.superproject-root.absolute", get_path_superproject_absolute }, { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +23 -0
@@ -237,6 +237,29 @@ then 'git config core.hooksPath /dev/null' fi +test_repo_info_path 'index standard' 'index' '.git/index' + +test_repo_info_path 'index with GIT_INDEX_FILE override' 'index' \ + 'custom-index-file' \ + 'GIT_INDEX_FILE="$ROOT/custom-index-file" && export GIT_INDEX_FILE' + +test_expect_success 'path.index in a bare repository returns default index location' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + ROOT="$(test-tool path-utils real_path .)" && + + echo "path.index.absolute=$ROOT/index" >expect.abs && + git repo info path.index.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.index.relative=index" >expect.rel && + git repo info path.index.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_expect_success 'path.superproject-root absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.55.GIT
PATCH v5 5/7 repo: add path.grafts with absolute and relative suffixes
In reply to K JayatheerthThe repository grafts file specifies alternate parent relationships for commits and may be used by repository tooling that needs to inspect or manage grafts. Scripts currently retrieve its location by invoking git rev-parse --git-path info/grafts.
Introduce path.grafts.absolute and path.grafts.relative keys to git repo info. This exposes the grafts file location as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 11 +++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 6 ++++++ 3 files changed, 41 insertions(+)
Documentation/git-repo.adoc +11 -0
@@ -119,6 +119,17 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.grafts.absolute`:: + The canonical absolute path to the repository's graft file. + Respects the `GIT_GRAFT_FILE` environment override. The path is + returned regardless of whether the file currently exists on disk. + +`path.grafts.relative`:: + The path to the repository's graft file relative to the current + working directory. Respects the `GIT_GRAFT_FILE` environment + override. The path is returned regardless of whether the file + currently exists on disk. + `path.hooks.absolute`:: The canonical absolute path to the repository's hooks directory. Respects the `core.hooksPath` configuration. If `core.hooksPath` is
builtin/repo.c +24 -0
@@ -122,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_grafts_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_grafts_relative (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf hooks_path =STRBUF_INIT ;
@@ -230,6 +252,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.grafts.absolute", get_path_grafts_absolute }, + { "path.grafts.relative", get_path_grafts_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, { "path.index.absolute", get_path_index_absolute },
t/t1900-repo-info.sh +6 -0
@@ -221,6 +221,12 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'grafts standard' 'grafts' '.git/info/grafts' + +test_repo_info_path 'grafts with GIT_GRAFT_FILE override' 'grafts' \ + 'custom-graft-file' \ + 'GIT_GRAFT_FILE="$ROOT/custom-graft-file" && export GIT_GRAFT_FILE' + test_repo_info_path 'hooks standard' 'hooks' '.git/hooks' test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
Signature · 1 line
2.55.GIT
PATCH v5 6/7 repo: add path.git-prefix
In reply to K JayatheerthScripts sometimes need the path from the repository's working tree root to the current working directory. While this information can be derived through existing Git commands, git repo info does not currently expose it as a scriptable key.
Introduce the path.git-prefix key to git repo info. The key returns the path from the working tree root to the current working directory, returning the empty string when invoked from the working tree root.
--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 11 +++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+)
Documentation/git-repo.adoc +5 -0
@@ -113,6 +113,11 @@ values that they return: The path to the Git repository's common directory relative to the current working directory. +`path.git-prefix`:: + The path from the root of the working tree to the current working + directory. Returns the empty string when the current working directory + is the root of the working tree. + `path.gitdir.absolute`:: The canonical absolute path to the Git repository directory (the `.git` directory).
builtin/repo.c +11 -0
@@ -100,6 +100,16 @@ static int get_path_commondir_relative(struct repository *repo, struct strbuf *breturn 0 ; } +static int get_path_git_prefix (struct repository *repo,struct strbuf *buf) +{ +/* +* repo->prefix is NULL when the current working directory is +* the worktree root. +*/ +strbuf_addstr (buf, repo->prefix ? repo->prefix :"" ); +return 0 ; +} +static int get_path_gitdir_absolute (struct repository *repo,struct strbuf *buf) {const char *git_dir =repo_get_git_dir (repo);
@@ -250,6 +260,7 @@ static const struct repo_info_field repo_info_field[] = { { "object.format", get_object_format }, { "path.commondir.absolute", get_path_commondir_absolute }, { "path.commondir.relative", get_path_commondir_relative }, + { "path.git-prefix", get_path_git_prefix }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, { "path.grafts.absolute", get_path_grafts_absolute },
t/t1900-repo-info.sh +23 -0
@@ -215,6 +215,29 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.git-prefix at repository root' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.git-prefix=" >expect && + git repo info path.git-prefix >actual && + test_cmp expect actual + ) +' + +test_expect_success 'path.git-prefix in subdirectory' ' + test_when_finished "rm -rf repo" && + git init repo && + mkdir -p repo/sub/dir && + ( + cd repo/sub/dir && + echo "path.git-prefix=sub/dir/" >expect && + git repo info path.git-prefix >actual && + test_cmp expect actual + ) +' + test_repo_info_path 'gitdir standard' 'gitdir' '.git' test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
Signature · 1 line
2.55.GIT
PATCH v5 7/7 repo: add path.cdup
In reply to K JayatheerthScripts sometimes need the relative path from the current working directory to the repository's working tree root (cdup). While this information can be retrieved through git rev-parse --show-cdup, git repo info does not currently expose it as a scriptable key.
Introduce the path.cdup key to git repo info. The key returns the path from the current working directory to the root of the working tree, returning the empty string when invoked from the working tree root.
--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 15 +++++++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 43 insertions(+)
Documentation/git-repo.adoc +5 -0
@@ -104,6 +104,11 @@ values that they return: `object.format`:: The object format (hash algorithm) used in the repository. +`path.cdup`:: + The path to the root of the working tree relative to the current + working directory. Returns the empty string when the current + working directory is the root of the working tree. + `path.commondir.absolute`:: The canonical absolute path to the Git repository's common directory (the shared `.git` directory containing objects,
builtin/repo.c +15 -0
@@ -78,6 +78,20 @@ static int get_object_format(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_cdup (struct repository *repo,struct strbuf *buf) +{ +const char *pfx = repo->prefix; + +while (pfx) { + pfx =strchr (pfx,'/' ); +if (pfx) { + pfx++; +strbuf_addstr (buf,"../" ); + } + } +return 0 ; +} +static int get_path_commondir_absolute (struct repository *repo,struct strbuf *buf) {const char *common_dir =repo_get_common_dir (repo);
@@ -258,6 +272,7 @@ static const struct repo_info_field repo_info_field[] = { { "layout.bare", get_layout_bare }, { "layout.shallow", get_layout_shallow }, { "object.format", get_object_format }, + { "path.cdup", get_path_cdup }, { "path.commondir.absolute", get_path_commondir_absolute }, { "path.commondir.relative", get_path_commondir_relative }, { "path.git-prefix", get_path_git_prefix },
t/t1900-repo-info.sh +23 -0
@@ -215,6 +215,29 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.cdup at repository root' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.cdup=" >expect && + git repo info path.cdup >actual && + test_cmp expect actual + ) +' + +test_expect_success 'path.cdup in subdirectory' ' + test_when_finished "rm -rf repo" && + git init repo && + mkdir -p repo/sub/dir && + ( + cd repo/sub/dir && + echo "path.cdup=../../" >expect && + git repo info path.cdup >actual && + test_cmp expect actual + ) +' + test_expect_success 'path.git-prefix at repository root' ' test_when_finished "rm -rf repo" && git init repo &&
Signature · 1 line
2.55.GIT
Re: [GSoC Patch v5 7/7] repo: add path.cdup
builtin/repo.c static int get_object_format(struct repository *repo, struct strbuf *buf) · line 93
Quoted 13 lines · K Jayatheerth
builtin/repo.c +13
-0+static int get_path_cdup (struct repository *repo,struct strbuf *buf) +{ +const char *pfx = repo->prefix; + +while (pfx) { + pfx =strchr (pfx,'/' ); +if (pfx) { + pfx++; +strbuf_addstr (buf,"../" ); + } + } +return 0 ; +}
Can we have a small common helper library (e.g., repo-info.c at the top level) shared between this code and builtin/rev-parse.c so that we have only a single implementation of 'cdup'?
The same comment applies to all the other features that duplicate implementations from rev-parse and elsewhere in the repo-info file.
Re: [GSoC Patch v5 7/7] repo: add path.cdup
Hey Junio,
Quoted 21 lines · Junio C Hamano
builtin/repo.c static int get_object_format(struct repository *repo, struct strbuf *buf) · line 93
Quoted 13 lines · K Jayatheerth
builtin/repo.c +13
-0+static int get_path_cdup (struct repository *repo,struct strbuf *buf) +{ +const char *pfx = repo->prefix; + +while (pfx) { + pfx =strchr (pfx,'/' ); +if (pfx) { + pfx++; +strbuf_addstr (buf,"../" ); + } + } +return 0 ; +}Can we have a small common helper library (e.g.,
repo-info.cat the top level) shared between this code andbuiltin/rev-parse.cso that we have only a single implementation of 'cdup'?
Quoted 2 lines
The same comment applies to all the other features that duplicate implementations from rev-parse and elsewhere in the repo-info file.
Apologies for the late response, I had a hectic exam week : )
I started working on this, but I wanted to check how to structure the commits cleanly.
Would it be okay to queue this path.* series as-is first, and then address the deduplication in a follow-up refactoring series right after (provided there are no other concerns)?
Grouping the new git repo info keys with the cleanup of git rev-parse in a single series would mix feature additions with legacy refactoring. Additionally, since earlier path keys are already merged, moving the shared library to a follow-up series keeps both topics clear.
In that follow-up set, I can introduce the library alongside porting the first command to use it, and then port the remaining overlapping commands one by one in subsequent commits so each patch remains a self-contained, bisectable change.
Please let me know if this works for you!
Regards,
- K Jayatheerth
Re: [GSoC Patch v5 0/7] add more path keys to git repo info
In reply to K JayatheerthJunio,
Quoted 7 lines · K Jayatheerth
+@@
builtin/repo.c: static intget_object_format(struct repository *repo, struct strbuf *buf)
+ return 0;
+ }
+
++static intget_path_cdup(struct repository *repo, struct strbuf *buf)
++{
++ const char *pfx =repo->prefix;
This patch series depends on "repo->prefix", but it's queued on top of 41365c2a9b (The 4th batch for Git 2.56, 2026-07-16), where this field doesn't exist yet, resulting in not buildable commits.
The series introducing "repo->prefix" was merged in 2688b28699 (Merge branch 'ps/setup-split-discovery-and-setup', 2026-07-19).
Re: [GSoC Patch v5 0/7] add more path keys to git repo info
Quoted 3 lines · SZEDER Gábor
This patch series depends on "
repo->prefix", but it's queued on top of41365c2a9b(The 4th batch for Git 2.56, 2026-07-16), where this field doesn't exist yet, resulting in not buildable commits.
Thanks. Will queue on top of more recent master.
v6 cover add more path keys to git repo info
In reply to K JayatheerthSeries adds keys to git repo info.
Keys output paths of repository components:
* path.toplevel: repository tree.
* path.superproject-root: superproject tree from submodules.
* path.hooks: repository hooks.
* path.index: repository index.
* path.grafts: repository grafts.
* path.git-prefix: prefix offset.
* path.cdup: relative path to top level from subdirectory.
Keys support suffixes for format.
Commits contain documentation and tests.
changes since v5:
* Refactored get_superproject_working_tree(struct repository *r, ...): Updated function signature and callers (builtin/rev-parse.c, builtin/repo.c) to accept repo, eliminating xgetcwd().
Note on path.cdup duplication:
As discussed in v5, path.cdup currently duplicates the prefix-counting logic from rev-parse to keep this feature arc self-contained. A follow-up refactoring series will be sent immediately after this to introduce a shared repo-info helper library, deduplicating this and other overlapping path logic across repo and rev-parse.
K Jayatheerth (7):
repo: add path.toplevel with absolute and relative suffix formatting
repo: add path.superproject-root with absolute and relative suffixes
repo: add path.hooks with absolute and relative suffixes
repo: add path.index with absolute and relative suffixes
repo: add path.grafts with absolute and relative suffixes
repo: add path.git-prefix
repo: add path.cdup
Documentation/git-repo.adoc | 62 ++++++++++++ builtin/repo.c | 151 ++++++++++++++++++++++++++++ builtin/rev-parse.c | 2 +- submodule.c | 43 ++++---- submodule.h | 2 +- t/t1900-repo-info.sh | 195 +++++++++++++++++++++++++++++++++++- 6 files changed, 430 insertions(+), 25 deletions(-)
Range-diff against v5:
1: 4ce9dcb24e = 1: 3880485020 repo: add path.toplevel with absolute and relative suffix formatting
2: c431008d40 ! 2: e75e17b44e repo: add path.superproject-root with absolute and relative suffixes
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
return 0;
}
-+static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf)
++static int get_path_superproject_absolute(struct repository *repo, struct strbuf *buf)
+{
+ struct strbuf superproject = STRBUF_INIT;
+
-+ if (!get_superproject_working_tree(&superproject)) {
++ if (!get_superproject_working_tree(repo, &superproject)) {
+ strbuf_release(&superproject);
+ return 0;
+ }
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+{
+ struct strbuf superproject = STRBUF_INIT;
+
-+ if (!get_superproject_working_tree(&superproject)) {
++ if (!get_superproject_working_tree(repo, &superproject)) {
+ strbuf_release(&superproject);
+ return 0;
+ }
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
{ "path.toplevel.relative", get_path_toplevel_relative },
{ "references.format", get_references_format },
+ ## builtin/rev-parse.c ##
+@@ builtin/rev-parse.c: int cmd_rev_parse(int argc,
+ }
+ if (!strcmp(arg, "--show-superproject-working-tree")) {
+ struct strbuf superproject = STRBUF_INIT;
+- if (get_superproject_working_tree(&superproject))
++ if (get_superproject_working_tree(the_repository, &superproject))
+ print_path(superproject.buf, prefix, format, DEFAULT_UNMODIFIED);
+ strbuf_release(&superproject);
+ continue;
+
+ ## submodule.c ##
+@@ submodule.c: void absorb_git_dir_into_superproject(const char *path,
+ absorb_git_dir_into_superproject_recurse(path, super_prefix);
+ }
+
+-int get_superproject_working_tree(struct strbuf *buf)
++int get_superproject_working_tree(struct repository *r, struct strbuf *buf)
+ {
+ struct child_process cp = CHILD_PROCESS_INIT;
+ struct strbuf sb = STRBUF_INIT;
+ struct strbuf one_up = STRBUF_INIT;
+- char *cwd = xgetcwd();
++ struct strbuf target_wt = STRBUF_INIT;
++ const char *worktree;
+ int ret = 0;
+ const char *subpath;
+ int code;
+ ssize_t len;
+
+- if (!is_inside_work_tree(the_repository))
+- /*
+- * FIXME:
+- * We might have a superproject, but it is harder
+- * to determine.
+- */
++ worktree = repo_get_work_tree(r);
++ if (!worktree)
++ goto out;
++
++ if (!strbuf_realpath(&target_wt, worktree, 0))
+ goto out;
+
+- if (!strbuf_realpath(&one_up, "../", 0))
++ strbuf_addf(&one_up, "%s/..", target_wt.buf);
++ if (!strbuf_realpath(&one_up, one_up.buf, 0))
+ goto out;
+
+- subpath = relative_path(cwd, one_up.buf, &sb);
++ subpath = relative_path(target_wt.buf, one_up.buf, &sb);
+
+ prepare_submodule_repo_env(&cp.env);
+ strvec_pop(&cp.env);
+
+- strvec_pushl(&cp.args, "--literal-pathspecs", "-C", "..",
++ strvec_pushl(&cp.args, "--literal-pathspecs", "-C", one_up.buf,
+ "ls-files", "-z", "--stage", "--full-name", "--",
+ subpath, NULL);
+ strbuf_reset(&sb);
+@@ submodule.c: int get_superproject_working_tree(struct strbuf *buf)
+ cp.git_cmd = 1;
+
+ if (start_command(&cp))
+- die(_("could not start ls-files in .."));
++ die(_("could not start ls-files in %s"), one_up.buf);
+
+ len = strbuf_read(&sb, cp.out, PATH_MAX);
+ close(cp.out);
+
+ if (starts_with(sb.buf, "160000")) {
+ int super_sub_len;
+- int cwd_len = strlen(cwd);
++ int wt_len = target_wt.len;
+ char *super_sub, *super_wt;
+
+ /*
+@@ submodule.c: int get_superproject_working_tree(struct strbuf *buf)
+ super_sub = strchr(sb.buf, '\t') + 1;
+ super_sub_len = strlen(super_sub);
+
+- if (super_sub_len > cwd_len ||
+- strcmp(&cwd[cwd_len - super_sub_len], super_sub))
+- BUG("returned path string doesn't match cwd?");
++ if (super_sub_len > wt_len ||
++ strcmp(&target_wt.buf[wt_len - super_sub_len], super_sub))
++ BUG("returned path string doesn't match worktree?");
+
+- super_wt = xstrdup(cwd);
+- super_wt[cwd_len - super_sub_len] = '\0';
++ super_wt = xstrdup(target_wt.buf);
++ super_wt[wt_len - super_sub_len] = '\0';
+
+ strbuf_realpath(buf, super_wt, 1);
+ ret = 1;
+@@ submodule.c: int get_superproject_working_tree(struct strbuf *buf)
+ code = finish_command(&cp);
+
+ if (code == 128)
+- /* '../' is not a git repository */
++ /* parent directory is not a git repository */
+ ret = 0;
+ else if (code == 0 && len == 0)
+- /* There is an unrelated git repository at '../' */
++ /* There is an unrelated git repository at parent directory */
+ ret = 0;
+ else if (code)
+ die(_("ls-tree returned unexpected return code %d"), code);
+@@ submodule.c: int get_superproject_working_tree(struct strbuf *buf)
+ out:
+ strbuf_release(&sb);
+ strbuf_release(&one_up);
+- free(cwd);
++ strbuf_release(&target_wt);
+ return ret;
+ }
+
+
+ ## submodule.h ##
+@@ submodule.h: void absorb_git_dir_into_superproject(const char *path,
+ * project is a submodule of. If this repository is not a submodule of
+ * another repository, return 0.
+ */
+-int get_superproject_working_tree(struct strbuf *buf);
++int get_superproject_working_tree(struct repository *r, struct strbuf *buf);
+
+ #endif
+
## t/t1900-repo-info.sh ##
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
'.git' \
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
test_expect_success 'path.toplevel absolute and relative' '
test_when_finished "rm -rf repo" &&
git init repo &&
+@@ t/t1900-repo-info.sh: test_expect_success 'path.toplevel absolute and relative in a bare repository' '
+ )
+ '
+
++test_expect_success 'path.superproject-root works with --git-dir' '
++ test_when_finished "rm -rf sub super" &&
++ git init sub &&
++ test_commit -C sub initial &&
++ git init super &&
++ (
++ cd super &&
++ git -c protocol.file.allow=always submodule add "../sub" sub &&
++ git commit -m "add submodule" &&
++
++ SUPER_ROOT="$(test-tool path-utils real_path .)" &&
++ MODULE_DIR="$SUPER_ROOT/.git/modules/sub" &&
++
++ echo "path.superproject-root.absolute=$SUPER_ROOT" >expect &&
++ git --git-dir="$MODULE_DIR" repo info path.superproject-root.absolute >actual &&
++ test_cmp expect actual
++ )
++'
+ test_done
3: 8664f8aaae ! 3: ae8a2592b3 repo: add path.hooks with absolute and relative suffixes
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+ return 0;
+}
+
- static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf)
+ static int get_path_superproject_absolute(struct repository *repo, struct strbuf *buf)
{
struct strbuf superproject = STRBUF_INIT;
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
4: 438f7e4e16 ! 4: 7f27bf14b9 repo: add path.index with absolute and relative suffixes
@@ builtin/repo.c: static int get_path_hooks_relative(struct repository *repo, stru
+ return 0;
+}
+
- static int get_path_superproject_absolute(struct repository *repo UNUSED, struct strbuf *buf)
+ static int get_path_superproject_absolute(struct repository *repo, struct strbuf *buf)
{
struct strbuf superproject = STRBUF_INIT;
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
5: 82be68426c = 5: cc52587980 repo: add path.grafts with absolute and relative suffixes
6: 346f1654d3 = 6: 77bf284a05 repo: add path.git-prefix
7: 3ccdd9b5e4 = 7: e30d98f5da repo: add path.cdupSignature · 1 line
2.55.GIT
PATCH v6 1/7 repo: add path.toplevel with absolute and relative suffix formatting
Scripts frequently need to find the root directory of a repository's working tree. Currently, this requires using git rev-parse --show-toplevel or inferring it from other repository information.
Introduce path.toplevel.absolute and path.toplevel.relative keys to git repo info. This allows scripts to retrieve the top-level working tree path in a predictable, strictly formatted manner without relying on rev-parse.
If requested in a bare repository where no working tree exists, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.toplevel.absolute`:: + The canonical absolute path to the top-level directory of the + repository's working tree. Outputs an empty string if the repository + is bare. + +`path.toplevel.relative`:: + The path to the top-level directory of the repository's working + tree relative to the current working directory. Outputs an empty + string if the repository is bare. + `references.format`:: The reference storage format. The valid values are: +
builtin/repo.c +24 -0
@@ -121,6 +121,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) +return 0 ; + +format_path (buf, work_tree,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_toplevel_relative (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) +return 0 ; + +format_path (buf, work_tree, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_references_format (struct repository *repo,struct strbuf *buf) { strbuf_addstr(buf,
@@ -137,6 +159,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.toplevel.absolute", get_path_toplevel_absolute }, + { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format }, };
t/t1900-repo-info.sh +35 -0
@@ -213,4 +213,39 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.toplevel absolute and relative' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.toplevel.absolute=$ROOT" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=../" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.toplevel absolute and relative in a bare repository' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + + echo "path.toplevel.absolute=" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_done
Signature · 1 line
2.55.GIT
PATCH v6 2/7 repo: add path.superproject-root with absolute and relative suffixes
In reply to K JayatheerthScripts working in multi-repository setups often need to identify the top-level working tree of a superproject from within a submodule. Currently, this is only exposed via git rev-parse --show-superproject-working-tree.
Introduce path.superproject-root.absolute and path.superproject-root.relative keys to git repo info. This exposes the core submodule context via a scriptable config-like key using standard format rules.
If requested when not inside a submodule, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 +++++++ builtin/repo.c | 31 ++++++++++++++++++++ builtin/rev-parse.c | 2 +- submodule.c | 43 ++++++++++++++-------------- submodule.h | 2 +- t/t1900-repo-info.sh | 57 +++++++++++++++++++++++++++++++++++++ 6 files changed, 122 insertions(+), 23 deletions(-)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.superproject-root.absolute`:: + The canonical absolute path to the working tree root of the superproject + if the current repository is an initialized submodule. Outputs an empty + string if not in a submodule. + +`path.superproject-root.relative`:: + The path to the working tree root of the superproject relative to the + current working directory if the current repository is an initialized + submodule. Outputs an empty string if not in a submodule. + `path.toplevel.absolute`:: The canonical absolute path to the top-level directory of the repository's working tree. Outputs an empty string if the repository
builtin/repo.c +31 -0
@@ -18,6 +18,7 @@#include "strbuf.h" #include "string-list.h" #include "shallow.h" +#include "submodule.h" #include "tree.h" #include "tree-walk.h" #include "utf8.h"
@@ -121,6 +122,34 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_superproject_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (repo, &superproject)) { +strbuf_release (&superproject); +return 0 ; + } + +format_path (buf, superproject.buf,"" ,PATH_FORMAT_CANONICAL ); +strbuf_release (&superproject); +return 0 ; +} + +static int get_path_superproject_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (repo, &superproject)) { +strbuf_release (&superproject); +return 0 ; + } + +format_path (buf, superproject.buf, repo->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&superproject); +return 0 ; +} +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) {const char *work_tree =repo_get_work_tree (repo);
@@ -159,6 +188,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.superproject-root.absolute", get_path_superproject_absolute }, + { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute }, { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format },
builtin/rev-parse.c +1 -1
@@ -997,7 +997,7 @@ int cmd_rev_parse(int argc, }if (!strcmp (arg,"--show-superproject-working-tree" )) {struct strbuf superproject =STRBUF_INIT ; -if (get_superproject_working_tree (&superproject)) +if (get_superproject_working_tree (the_repository, &superproject))print_path (superproject.buf, prefix, format,DEFAULT_UNMODIFIED );strbuf_release (&superproject);continue ;
submodule.c +22 -21
99 lines not on this page · raw message
submodule.h +1 -1
@@ -170,6 +170,6 @@ void absorb_git_dir_into_superproject(const char *path,* project is a submodule of. If this repository is not a submodule of * another repository, return 0. */ -int get_superproject_working_tree (struct strbuf *buf); +int get_superproject_working_tree (struct repository *r,struct strbuf *buf);#endif
t/t1900-repo-info.sh +57 -0
67 lines not on this page · raw message
Signature · 1 line
2.55.GIT
Re: [GSoC Patch v6 2/7] repo: add path.superproject-root with absolute and relative suffixes
Quoted 16 lines · K Jayatheerth
Scripts working in multi-repository setups often need to identify the top-level working tree of a superproject from within a submodule. Currently, this is only exposed via
git rev-parse --show-superproject-working-tree.Introduce
path.superproject-root.absoluteandpath.superproject-root.relativekeys togit repo info. This exposes the core submodule context via a scriptable config-like key using standard format rules.If requested when not inside a submodule, the command returns an empty string.
Mentored-by Justin Tobler <[email protected]>Mentored-by Lucas Seiki Oshiro <[email protected]>Signed-off-by K Jayatheerth <[email protected]>
Quoted 8 lines
--- Documentation/git-repo.adoc | 10 +++++++ builtin/repo.c | 31 ++++++++++++++++++++ builtin/rev-parse.c | 2 +- submodule.c | 43 ++++++++++++++-------------- submodule.h | 2 +- t/t1900-repo-info.sh | 57 +++++++++++++++++++++++++++++++++++++ 6 files changed, 122 insertions(+), 23 deletions(-)
Correcting get_superproject_working_tree(), which was introduced by bf0231c661 (rev-parse: add --show-superproject-working-tree, 2017-03-08), is a major part of this step. The old commit added a single test for very basic use but this step makes not-so-basic use cases to also work correctly, right?
It may be a good idea to split this step into two patches:
- a patch that corrects get_superproject_working_tree(), that adds a new test or two to t1500-rev-parse.sh, next to where bf0231c661 (rev-parse: add --show-superproject-working-tree, 2017-03-08) added its test. The test would fail without the code fix to demonstrate what we improved.
- another patch that uses improved get_superproject_working_tree() to add path.superproject-root.* keys, together with the updates to t1900-repo-info.sh to add tests for the new feature.
Re: [GSoC Patch v6 2/7] repo: add path.superproject-root with absolute and relative suffixes
Quoted 16 lines · Junio C Hamano
Correcting
get_superproject_working_tree(), which was introduced bybf0231c661(rev-parse: add --show-superproject-working-tree, 2017-03-08), is a major part of this step. The old commit added a single test for very basic use but this step makes not-so-basic use cases to also work correctly, right?It may be a good idea to split this step into two patches:
- a patch that corrects
get_superproject_working_tree(), that adds a new test or two tot1500-rev-parse.sh, next to wherebf0231c661(rev-parse: add --show-superproject-working-tree, 2017-03-08) added its test. The test would fail without the code fix to demonstrate what we improved.
Quoted 3 lines
- another patch that uses improved
get_superproject_working_tree()to add path.superproject-root.* keys, together with the updates tot1900-repo-info.shto add tests for the new feature.
Fair enough. Will do, but I don't think t1500 is a good location tho Cause the bug affects repo as well
I will find a good location.
PATCH v6 3/7 repo: add path.hooks with absolute and relative suffixes
In reply to K JayatheerthHooks are an integral part of a repository's configuration and are commonly used by tooling to automate repository-specific workflows. Currently, scripts typically retrieve the hooks directory by invoking git rev-parse --git-path hooks.
Introduce path.hooks.absolute and path.hooks.relative keys to git repo info. This exposes the hooks directory as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 9 +++++++++ builtin/repo.c | 22 ++++++++++++++++++++++ t/t1900-repo-info.sh | 28 ++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-)
Documentation/git-repo.adoc +9 -0
@@ -119,6 +119,15 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.hooks.absolute`:: + The canonical absolute path to the repository's hooks directory. + Respects the `core.hooksPath` configuration. If `core.hooksPath` is + set to `/dev/null`, that value is returned unchanged. + +`path.hooks.relative`:: + The path to the repository's hooks directory relative to the current + working directory. Respects the `core.hooksPath` configuration. + `path.superproject-root.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +22 -0
@@ -122,6 +122,26 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf,"" ,PATH_FORMAT_CANONICAL ); +strbuf_release (&hooks_path); +return 0 ; +} + +static int get_path_hooks_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf, repo->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&hooks_path); +return 0 ; +} +static int get_path_superproject_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -188,6 +208,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.hooks.absolute", get_path_hooks_absolute }, + { "path.hooks.relative", get_path_hooks_relative }, { "path.superproject-root.absolute", get_path_superproject_absolute }, { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +26 -2
@@ -174,7 +174,11 @@ test_repo_info_path () { cd repo/sub && ROOT="$(test-tool path-utils real_path ..)" && export ROOT && eval "$init_command" && - echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect && + case "$expected_dir" in + /*) EXPECT_ABS="$expected_dir" ;; + *) EXPECT_ABS="$ROOT/$expected_dir" ;; + esac && + echo "path.$field_name.absolute=$EXPECT_ABS" >expect && git repo info "path.$field_name.absolute" >actual && test_cmp expect actual )
@@ -188,7 +192,11 @@ test_repo_info_path () { cd repo/sub && ROOT="$(test-tool path-utils real_path ..)" && export ROOT && eval "$init_command" && - echo "path.$field_name.relative=../$expected_dir" >expect && + case "$expected_dir" in + /*) EXPECT_REL="$(test-tool path-utils relative_path "$expected_dir" "$PWD")" ;; + *) EXPECT_REL="../$expected_dir" ;; + esac && + echo "path.$field_name.relative=$EXPECT_REL" >expect && git repo info "path.$field_name.relative" >actual && test_cmp expect actual )
@@ -213,6 +221,22 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'hooks standard' 'hooks' '.git/hooks' + +test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ + 'custom-hooks' \ + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' + +# /dev/null is not a real, canonicalizable filesystem path on Windows, +# so path resolution for core.hooksPath=/dev/null cannot be expected to +# produce a literal "/dev/null" the way it does on POSIX systems. +if ! test_have_prereq MINGW +then + test_repo_info_path 'hooks with core.hooksPath=/dev/null' 'hooks' \ + '/dev/null' \ + 'git config core.hooksPath /dev/null' +fi + test_expect_success 'path.superproject-root absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.55.GIT
PATCH v6 4/7 repo: add path.index with absolute and relative suffixes
In reply to K JayatheerthThe repository index is a fundamental component used by Git and related tooling to track the working tree state. Scripts that interact with the index currently retrieve its location by invokinggit rev-parse --git-path index.
Introduce path.index.absolute and path.index.relative keys to git repo info. This exposes the index file location as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 12 ++++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 59 insertions(+)
Documentation/git-repo.adoc +12 -0
@@ -128,6 +128,18 @@ values that they return: The path to the repository's hooks directory relative to the current working directory. Respects the `core.hooksPath` configuration. +`path.index.absolute`:: + The canonical absolute path to the repository's current index file. + Respects the `GIT_INDEX_FILE` environment override. Returns the + configured index path even if the repository is bare or the file does + not exist. + +`path.index.relative`:: + The path to the repository's current index file relative to the current + working directory. Respects the `GIT_INDEX_FILE` environment override. + Returns the configured index path even if the repository is bare or the + file does not exist. + `path.superproject-root.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +24 -0
@@ -142,6 +142,28 @@ static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_index_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_index_relative (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_superproject_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -210,6 +232,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.gitdir.relative", get_path_gitdir_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, + { "path.index.absolute", get_path_index_absolute }, + { "path.index.relative", get_path_index_relative }, { "path.superproject-root.absolute", get_path_superproject_absolute }, { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +23 -0
@@ -237,6 +237,29 @@ then 'git config core.hooksPath /dev/null' fi +test_repo_info_path 'index standard' 'index' '.git/index' + +test_repo_info_path 'index with GIT_INDEX_FILE override' 'index' \ + 'custom-index-file' \ + 'GIT_INDEX_FILE="$ROOT/custom-index-file" && export GIT_INDEX_FILE' + +test_expect_success 'path.index in a bare repository returns default index location' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + ROOT="$(test-tool path-utils real_path .)" && + + echo "path.index.absolute=$ROOT/index" >expect.abs && + git repo info path.index.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.index.relative=index" >expect.rel && + git repo info path.index.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_expect_success 'path.superproject-root absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.55.GIT
Re: [GSoC Patch v6 4/7] repo: add path.index with absolute and relative suffixes
builtin/repo.c static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf) · line 150
Quoted 6 lines · K Jayatheerth
builtin/repo.c +6
-0+static int get_path_index_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" ));
This is a dead code, as repo_get_index_file() calls BUG("") when it finds that the repo instance is not ready to return this information.
Hence I am debating myself if this is a better alternative:
const char *index_file = repo->index_file; if (!index_file) return error(...);
I dunno.
builtin/repo.c static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf) · line 165
Quoted 10 lines
builtin/repo.c +10
-0+static int get_path_index_relative (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +}
Ditto.
Re: [GSoC Patch v6 4/7] repo: add path.index with absolute and relative suffixes
Quoted 6 lines
Review
Quoted 2 lines
(quoted diff) +2
-0+ if (!index_file) + return error(_("unable to get index file"));This is a dead code, as
repo_get_index_file()callsBUG("")when it finds that the repo instance is not ready to return this information.
Quoted 9 lines
Hence I am debating myself if this is a better alternative:
const char *index_file = repo->index_file; if (!index_file) return error(...);I dunno.
I think I am just gonna remove the if condition from get_path_index_relative() and let repo_get_index_file handle the bug instead of rewriting the logic.
Quoted 4 lines
Quoted 4 lines
builtin/repo.c +4
-0+static int get_path_index_relative (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); +
Quoted 8 lines
builtin/repo.c static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf) · line 165
Quoted 6 lines
builtin/repo.c +6
-0+if (!index_file) +return error (_ ("unable to get index file" )); + +format_path (buf, index_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +}Ditto.
Same for this.
PATCH v6 5/7 repo: add path.grafts with absolute and relative suffixes
In reply to K JayatheerthThe repository grafts file specifies alternate parent relationships for commits and may be used by repository tooling that needs to inspect or manage grafts. Scripts currently retrieve its location by invoking git rev-parse --git-path info/grafts.
Introduce path.grafts.absolute and path.grafts.relative keys to git repo info. This exposes the grafts file location as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 11 +++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 6 ++++++ 3 files changed, 41 insertions(+)
Documentation/git-repo.adoc +11 -0
@@ -119,6 +119,17 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.grafts.absolute`:: + The canonical absolute path to the repository's graft file. + Respects the `GIT_GRAFT_FILE` environment override. The path is + returned regardless of whether the file currently exists on disk. + +`path.grafts.relative`:: + The path to the repository's graft file relative to the current + working directory. Respects the `GIT_GRAFT_FILE` environment + override. The path is returned regardless of whether the file + currently exists on disk. + `path.hooks.absolute`:: The canonical absolute path to the repository's hooks directory. Respects the `core.hooksPath` configuration. If `core.hooksPath` is
builtin/repo.c +24 -0
@@ -122,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_grafts_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_grafts_relative (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf hooks_path =STRBUF_INIT ;
@@ -230,6 +252,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.grafts.absolute", get_path_grafts_absolute }, + { "path.grafts.relative", get_path_grafts_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, { "path.index.absolute", get_path_index_absolute },
t/t1900-repo-info.sh +6 -0
@@ -221,6 +221,12 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'grafts standard' 'grafts' '.git/info/grafts' + +test_repo_info_path 'grafts with GIT_GRAFT_FILE override' 'grafts' \ + 'custom-graft-file' \ + 'GIT_GRAFT_FILE="$ROOT/custom-graft-file" && export GIT_GRAFT_FILE' + test_repo_info_path 'hooks standard' 'hooks' '.git/hooks' test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
Signature · 1 line
2.55.GIT
PATCH v6 6/7 repo: add path.git-prefix
In reply to K JayatheerthScripts sometimes need the path from the repository's working tree root to the current working directory. While this information can be derived through existing Git commands, git repo info does not currently expose it as a scriptable key.
Introduce the path.git-prefix key to git repo info. The key returns the path from the working tree root to the current working directory, returning the empty string when invoked from the working tree root.
--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 11 +++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+)
Documentation/git-repo.adoc +5 -0
@@ -113,6 +113,11 @@ values that they return: The path to the Git repository's common directory relative to the current working directory. +`path.git-prefix`:: + The path from the root of the working tree to the current working + directory. Returns the empty string when the current working directory + is the root of the working tree. + `path.gitdir.absolute`:: The canonical absolute path to the Git repository directory (the `.git` directory).
builtin/repo.c +11 -0
@@ -100,6 +100,16 @@ static int get_path_commondir_relative(struct repository *repo, struct strbuf *breturn 0 ; } +static int get_path_git_prefix (struct repository *repo,struct strbuf *buf) +{ +/* +* repo->prefix is NULL when the current working directory is +* the worktree root. +*/ +strbuf_addstr (buf, repo->prefix ? repo->prefix :"" ); +return 0 ; +} +static int get_path_gitdir_absolute (struct repository *repo,struct strbuf *buf) {const char *git_dir =repo_get_git_dir (repo);
@@ -250,6 +260,7 @@ static const struct repo_info_field repo_info_field[] = { { "object.format", get_object_format }, { "path.commondir.absolute", get_path_commondir_absolute }, { "path.commondir.relative", get_path_commondir_relative }, + { "path.git-prefix", get_path_git_prefix }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, { "path.grafts.absolute", get_path_grafts_absolute },
t/t1900-repo-info.sh +23 -0
@@ -215,6 +215,29 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.git-prefix at repository root' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.git-prefix=" >expect && + git repo info path.git-prefix >actual && + test_cmp expect actual + ) +' + +test_expect_success 'path.git-prefix in subdirectory' ' + test_when_finished "rm -rf repo" && + git init repo && + mkdir -p repo/sub/dir && + ( + cd repo/sub/dir && + echo "path.git-prefix=sub/dir/" >expect && + git repo info path.git-prefix >actual && + test_cmp expect actual + ) +' + test_repo_info_path 'gitdir standard' 'gitdir' '.git' test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
Signature · 1 line
2.55.GIT
PATCH v6 7/7 repo: add path.cdup
In reply to K JayatheerthScripts sometimes need the relative path from the current working directory to the repository's working tree root (cdup). While this information can be retrieved through git rev-parse --show-cdup, git repo info does not currently expose it as a scriptable key.
Introduce the path.cdup key to git repo info. The key returns the path from the current working directory to the root of the working tree, returning the empty string when invoked from the working tree root.
--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 15 +++++++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 43 insertions(+)
Documentation/git-repo.adoc +5 -0
@@ -104,6 +104,11 @@ values that they return: `object.format`:: The object format (hash algorithm) used in the repository. +`path.cdup`:: + The path to the root of the working tree relative to the current + working directory. Returns the empty string when the current + working directory is the root of the working tree. + `path.commondir.absolute`:: The canonical absolute path to the Git repository's common directory (the shared `.git` directory containing objects,
builtin/repo.c +15 -0
@@ -78,6 +78,20 @@ static int get_object_format(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_cdup (struct repository *repo,struct strbuf *buf) +{ +const char *pfx = repo->prefix; + +while (pfx) { + pfx =strchr (pfx,'/' ); +if (pfx) { + pfx++; +strbuf_addstr (buf,"../" ); + } + } +return 0 ; +} +static int get_path_commondir_absolute (struct repository *repo,struct strbuf *buf) {const char *common_dir =repo_get_common_dir (repo);
@@ -258,6 +272,7 @@ static const struct repo_info_field repo_info_field[] = { { "layout.bare", get_layout_bare }, { "layout.shallow", get_layout_shallow }, { "object.format", get_object_format }, + { "path.cdup", get_path_cdup }, { "path.commondir.absolute", get_path_commondir_absolute }, { "path.commondir.relative", get_path_commondir_relative }, { "path.git-prefix", get_path_git_prefix },
t/t1900-repo-info.sh +23 -0
@@ -215,6 +215,29 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.cdup at repository root' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.cdup=" >expect && + git repo info path.cdup >actual && + test_cmp expect actual + ) +' + +test_expect_success 'path.cdup in subdirectory' ' + test_when_finished "rm -rf repo" && + git init repo && + mkdir -p repo/sub/dir && + ( + cd repo/sub/dir && + echo "path.cdup=../../" >expect && + git repo info path.cdup >actual && + test_cmp expect actual + ) +' + test_expect_success 'path.git-prefix at repository root' ' test_when_finished "rm -rf repo" && git init repo &&
Signature · 1 line
2.55.GIT
Re: [GSoC Patch v6 7/7] repo: add path.cdup
Quoted 23 lines · K Jayatheerth
Scripts sometimes need the relative path from the current working directory to the repository's working tree root (cdup). While this information can be retrieved through
git rev-parse --show-cdup,git repo infodoes not currently expose it as a scriptable key.Introduce the
path.cdupkey togit repo info. The key returns the path from the current working directory to the root of the working tree, returning the empty string when invoked from the working tree root.Mentored-by Justin Tobler <[email protected]>Mentored-by Lucas Seiki Oshiro <[email protected]>Signed-off-by K Jayatheerth <[email protected]>--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 15 +++++++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 43 insertions(+)Documentation/git-repo.adoc +0
-0
Documentation/git-repo.adoc values that they return: · line 110
Quoted 7 lines
Documentation/git-repo.adoc +4
-0@@ -104,6 +104,11 @@ values that they return: `object.format`:: The object format (hash algorithm) used in the repository. +`path.cdup`:: + The path to the root of the working tree relative to the current + working directory. Returns the empty string when the current + working directory is the root of the working tree.
What happens when the current working directory is outside the working tree? For example:
$ GIT_WORK_TREE=/tmp/x; export GIT_WORK_TREE
$ GIT_DIR=$(pwd)/.git; export GIT_DIRThe current implementation yields an empty string:
$ git repo info path.cdup
path.cdup=However, 'git rev-parse --show-cdup' produces:
$ git rev-parse --show-cdup
/var/tmp/xWhether this discrepancy matters is unclear. However, if the goal is to consolidate all repository path-related items under the 'git repo info' umbrella, this difference sticks out.
Re: [GSoC Patch v6 7/7] repo: add path.cdup
Quoted 24 lines · Junio C Hamano
Documentation/git-repo.adoc values that they return: · line 110
Quoted 9 lines · K Jayatheerth
Scripts sometimes need the relative path from the current working directory to the repository's working tree root (cdup). While this information can be retrieved through
git rev-parse --show-cdup,git repo infodoes not currently expose it as a scriptable key.
[...]
+path.cdup::Documentation/git-repo.adoc +3
-0+ The path to the root of the working tree relative to the current + working directory. Returns the empty string when the current + working directory is the root of the working tree.What happens when the current working directory is outside the working tree? For example:
$ GIT_WORK_TREE=/tmp/x; export GIT_WORK_TREE $ GIT_DIR=$(pwd)/.git; export GIT_DIRThe current implementation yields an empty string:
$ git repo info path.cdup path.cdup=
Quoted 8 lines
However, 'git rev-parse --show-cdup' produces:
$ git rev-parse --show-cdup /var/tmp/xWhether this discrepancy matters is unclear. However, if the goal is to consolidate all repository path-related items under the 'git repo info' umbrella, this difference sticks out.
yeah
in rev-parse i could find this
if (!is_inside_work_tree(the_repository)) {
const char *work_tree =repo_get_work_tree(the_repository);
if (work_tree)printf("%s\n", work_tree);
continue;
}
adding this logic in repo.c should fix it!
Thanks
v7 cover add more path keys to git repo info
In reply to K JayatheerthSeries adds keys to git repo info.
Keys output paths of repository components:
* path.toplevel: repository tree.
* path.superproject-root: superproject tree from submodules.
* path.hooks: repository hooks.
* path.index: repository index.
* path.grafts: repository grafts.
* path.git-prefix: prefix offset.
* path.cdup: relative path to top level from subdirectory.
Keys support suffixes for format.
Commits contain documentation and tests.
fix a superproject bug where it now takes repo parameter instead of just depending on cwd.
changes since v6:
* The superproject bug fix is now a commit of its own.
* The dead code in index is removed, we simply rely on the helper itself and not write any new conditions.
* cdup now works even when the worktree is outside the current working directory.
K Jayatheerth (8):
repo: add path.toplevel with absolute and relative suffix formatting
submodule: use repository to find superproject
repo: add path.superproject-root with absolute and relative suffixes
repo: add path.hooks with absolute and relative suffixes
repo: add path.index with absolute and relative suffixes
repo: add path.grafts with absolute and relative suffixes
repo: add path.git-prefix
repo: add path.cdup
Documentation/git-repo.adoc | 62 ++++++++++++ builtin/repo.c | 153 ++++++++++++++++++++++++++++ builtin/rev-parse.c | 2 +- submodule.c | 43 ++++---- submodule.h | 2 +- t/t1900-repo-info.sh | 194 +++++++++++++++++++++++++++++++++++- t/t7400-submodule-basic.sh | 19 ++++ 7 files changed, 450 insertions(+), 25 deletions(-)
Range-diff against v6:
-: ---------- > 1: 27b9811163 repo: add path.toplevel with absolute and relative suffix formatting 1: d4f3253256 ! 2: 7c90603a1b repo: add path.superproject-root with absolute and relative suffixes
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: add path.superproject-root with absolute and relative suffixes
+ submodule: use repository to find superproject
- Scripts working in multi-repository setups often need to identify the
- top-level working tree of a superproject from within a submodule.
- Currently, this is only exposed via `git rev-parse
- --show-superproject-working-tree`.
+ get_superproject_working_tree() currently uses xgetcwd() to
+ determine the repository whose superproject should be checked.
- Introduce path.superproject-root.absolute and
- path.superproject-root.relative keys to git repo info.
- This exposes the core submodule context via a scriptable config-like key
- using standard format rules.
+ This is incorrect when --git-dir points to a repository different
+ from the one associated with the current working directory. In that
+ case, the current working directory may cause the function to return
+ the wrong superproject or an empty result.
- If requested when not inside a submodule, the command returns an empty
- string.
+ Pass the repository to get_superproject_working_tree() so that the
+ superproject is determined from the repository being inspected rather
+ than the current working directory.
- ## Documentation/git-repo.adoc ##
-@@ Documentation/git-repo.adoc: values that they return:
- path.gitdir.relative::
- The path to the Git repository directory relative to the current working directory.
-
-+path.superproject-root.absolute::
-+ The canonical absolute path to the working tree root of the superproject
-+ if the current repository is an initialized submodule. Outputs an empty
-+ string if not in a submodule.
-+
-+path.superproject-root.relative::
-+ The path to the working tree root of the superproject relative to the
-+ current working directory if the current repository is an initialized
-+ submodule. Outputs an empty string if not in a submodule.
-+
- path.toplevel.absolute::
- The canonical absolute path to the top-level directory of the
- repository's working tree. Outputs an empty string if the repository
-
- ## builtin/repo.c ##
-@@
- #include "strbuf.h"
- #include "string-list.h"
- #include "shallow.h"
-+#include "submodule.h"
- #include "tree.h"
- #include "tree-walk.h"
- #include "utf8.h"
-@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)
- return 0;
- }
-
-+static int get_path_superproject_absolute(struct repository *repo, struct strbuf *buf) -+{
-+ struct strbuf superproject = STRBUF_INIT;
-+
-+ if (!get_superproject_working_tree(repo, &superproject)) {
-+ strbuf_release(&superproject);
-+ return 0;
-+ }
-+
-+ format_path(buf, superproject.buf, "", PATH_FORMAT_CANONICAL);
-+ strbuf_release(&superproject);
-+ return 0;
-+}
-+
-+static int get_path_superproject_relative(struct repository *repo, struct strbuf *buf) -+{
-+ struct strbuf superproject = STRBUF_INIT;
-+
-+ if (!get_superproject_working_tree(repo, &superproject)) {
-+ strbuf_release(&superproject);
-+ return 0;
-+ }
-+
-+ format_path(buf, superproject.buf, repo->prefix, PATH_FORMAT_RELATIVE);
-+ strbuf_release(&superproject);
-+ return 0;
-+}
-+
- static int get_path_toplevel_absolute(struct repository *repo, struct strbuf *buf)
- {
- const char *work_tree = repo_get_work_tree(repo);
-@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
- { "path.commondir.relative", get_path_commondir_relative },
- { "path.gitdir.absolute", get_path_gitdir_absolute },
- { "path.gitdir.relative", get_path_gitdir_relative },
-+ { "path.superproject-root.absolute", get_path_superproject_absolute },
-+ { "path.superproject-root.relative", get_path_superproject_relative },
- { "path.toplevel.absolute", get_path_toplevel_absolute },
- { "path.toplevel.relative", get_path_toplevel_relative },
- { "references.format", get_references_format },
-
## builtin/rev-parse.c ##
@@ builtin/rev-parse.c: int cmd_rev_parse(int argc,
}
@@ submodule.h: void absorb_git_dir_into_superproject(const char *path,
#endif
- ## t/t1900-repo-info.sh ##
-@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
- '.git' \
- 'GIT_DIR="../.git" && export GIT_DIR'
-
-+test_expect_success 'path.superproject-root absolute and relative' '
-+ test_when_finished "rm -rf sub super" &&
-+ git init sub &&
-+ test_commit -C sub initial &&
-+ git init super &&
-+ (
-+ cd super &&
-+ git -c protocol.file.allow=always submodule add "../sub" sub &&
-+ git commit -m "add submodule" &&
-+
-+ cd sub &&
-+ ROOT="$(test-tool path-utils real_path ..)" &&
-+
-+ echo "path.superproject-root.absolute=$ROOT" >expect.abs &&
-+ git repo info path.superproject-root.absolute >actual.abs &&
-+ test_cmp expect.abs actual.abs &&
-+
-+ echo "path.superproject-root.relative=../" >expect.rel &&
-+ git repo info path.superproject-root.relative >actual.rel &&
-+ test_cmp expect.rel actual.rel
-+ )
-+'
-+
-+test_expect_success 'path.superproject-root returns empty when not in a submodule' '
-+ test_when_finished "rm -rf repo" &&
-+ git init repo &&
-+ (
-+ cd repo &&
-+
-+ echo "path.superproject-root.absolute=" >expect.abs &&
-+ git repo info path.superproject-root.absolute >actual.abs &&
-+ test_cmp expect.abs actual.abs &&
-+
-+ echo "path.superproject-root.relative=" >expect.rel &&
-+ git repo info path.superproject-root.relative >actual.rel &&
-+ test_cmp expect.rel actual.rel
-+ )
-+'
-+
- test_expect_success 'path.toplevel absolute and relative' '
- test_when_finished "rm -rf repo" &&
- git init repo &&
-@@ t/t1900-repo-info.sh: test_expect_success 'path.toplevel absolute and relative in a bare repository' '
+ ## t/t7400-submodule-basic.sh ##
+@@ t/t7400-submodule-basic.sh: test_expect_success 'submodule add fails when name is reused' '
)
'
@@ t/t1900-repo-info.sh: test_expect_success 'path.toplevel absolute and relative i
+ test_cmp expect actual
+ )
+'
++
test_done
3: 1860d19d01 ! 3: 1bfb0c8c1d repo: add path.index with absolute and relative suffixes
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: add path.index with absolute and relative suffixes
+ repo: add path.superproject-root with absolute and relative suffixes
- The repository index is a fundamental component used by Git and related
- tooling to track the working tree state. Scripts that interact with the
- index currently retrieve its location by invoking
- `git rev-parse --git-path index`.
+ Scripts working in multi-repository setups often need to identify the
+ top-level working tree of a superproject from within a submodule.
+ Currently, this is only exposed via `git rev-parse
+ --show-superproject-working-tree`.
- Introduce `path.index.absolute` and `path.index.relative` keys to
- `git repo info`. This exposes the index file location as a scriptable
- config-like key using standard format rules, allowing scripts to
- retrieve it through the same interface as other repository path
- information.
+ Introduce `path.superproject-root.absolute` and
+ `path.superproject-root.relative` keys to `git repo info`.
+ This exposes the core submodule context via a scriptable config-like key
+ using standard format rules.
+
+ If requested when not inside a submodule, the command returns an empty
+ string.
Mentored-by: Justin Tobler <[email protected]>
Mentored-by: Lucas Seiki Oshiro <[email protected]>
@@ Commit message
## Documentation/git-repo.adoc ##
@@ Documentation/git-repo.adoc: values that they return:
- The path to the repository's hooks directory relative to the current
- working directory. Respects the `core.hooksPath` configuration.
+ `path.gitdir.relative`::
+ The path to the Git repository directory relative to the current working directory.
-+`path.index.absolute`::
-+ The canonical absolute path to the repository's current index file.
-+ Respects the `GIT_INDEX_FILE` environment override. Returns the
-+ configured index path even if the repository is bare or the file does
-+ not exist.
++`path.superproject-root.absolute`::
++ The canonical absolute path to the working tree root of the superproject
++ if the current repository is an initialized submodule. Outputs an empty
++ string if not in a submodule.
+
-+`path.index.relative`::
-+ The path to the repository's current index file relative to the current
-+ working directory. Respects the `GIT_INDEX_FILE` environment override.
-+ Returns the configured index path even if the repository is bare or the
-+ file does not exist.
++`path.superproject-root.relative`::
++ The path to the working tree root of the superproject relative to the
++ current working directory if the current repository is an initialized
++ submodule. Outputs an empty string if not in a submodule.
+
- `path.superproject-root.absolute`::
- The canonical absolute path to the working tree root of the superproject
- if the current repository is an initialized submodule. Outputs an empty
+ `path.toplevel.absolute`::
+ The canonical absolute path to the top-level directory of the
+ repository's working tree. Outputs an empty string if the repository
## builtin/repo.c ##
-@@ builtin/repo.c: static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf)
+@@
+ #include "strbuf.h"
+ #include "string-list.h"
+ #include "shallow.h"
++#include "submodule.h"
+ #include "tree.h"
+ #include "tree-walk.h"
+ #include "utf8.h"
+@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)
return 0;
}
-+static int get_path_index_absolute(struct repository *repo, struct strbuf *buf)
++static int get_path_superproject_absolute(struct repository *repo, struct strbuf *buf)
+{
-+ const char *index_file = repo_get_index_file(repo);
++ struct strbuf superproject = STRBUF_INIT;
+
-+ if (!index_file)
-+ return error(_("unable to get index file"));
++ if (!get_superproject_working_tree(repo, &superproject)) {
++ strbuf_release(&superproject);
++ return 0;
++ }
+
-+ format_path(buf, index_file, "", PATH_FORMAT_CANONICAL);
++ format_path(buf, superproject.buf, "", PATH_FORMAT_CANONICAL);
++ strbuf_release(&superproject);
+ return 0;
+}
+
-+static int get_path_index_relative(struct repository *repo, struct strbuf *buf)
++static int get_path_superproject_relative(struct repository *repo, struct strbuf *buf)
+{
-+ const char *index_file = repo_get_index_file(repo);
++ struct strbuf superproject = STRBUF_INIT;
+
-+ if (!index_file)
-+ return error(_("unable to get index file"));
++ if (!get_superproject_working_tree(repo, &superproject)) {
++ strbuf_release(&superproject);
++ return 0;
++ }
+
-+ format_path(buf, index_file, repo->prefix, PATH_FORMAT_RELATIVE);
++ format_path(buf, superproject.buf, repo->prefix, PATH_FORMAT_RELATIVE);
++ strbuf_release(&superproject);
+ return 0;
+}
+
- static int get_path_superproject_absolute(struct repository *repo, struct strbuf *buf)
+ static int get_path_toplevel_absolute(struct repository *repo, struct strbuf *buf)
{
- struct strbuf superproject = STRBUF_INIT;
+ const char *work_tree = repo_get_work_tree(repo);
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
+ { "path.commondir.relative", get_path_commondir_relative },
+ { "path.gitdir.absolute", get_path_gitdir_absolute },
{ "path.gitdir.relative", get_path_gitdir_relative },
- { "path.hooks.absolute", get_path_hooks_absolute },
- { "path.hooks.relative", get_path_hooks_relative },
-+ { "path.index.absolute", get_path_index_absolute },
-+ { "path.index.relative", get_path_index_relative },
- { "path.superproject-root.absolute", get_path_superproject_absolute },
- { "path.superproject-root.relative", get_path_superproject_relative },
++ { "path.superproject-root.absolute", get_path_superproject_absolute },
++ { "path.superproject-root.relative", get_path_superproject_relative },
{ "path.toplevel.absolute", get_path_toplevel_absolute },
+ { "path.toplevel.relative", get_path_toplevel_relative },
+ { "references.format", get_references_format },
## t/t1900-repo-info.sh ##
-@@ t/t1900-repo-info.sh: then
- 'git config core.hooksPath /dev/null'
- fi
+@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
+ '.git' \
+ 'GIT_DIR="../.git" && export GIT_DIR'
-+test_repo_info_path 'index standard' 'index' '.git/index'
++test_expect_success 'path.superproject-root absolute and relative' '
++ test_when_finished "rm -rf sub super" &&
++ git init sub &&
++ test_commit -C sub initial &&
++ git init super &&
++ (
++ cd super &&
++ git -c protocol.file.allow=always submodule add "../sub" sub &&
++ git commit -m "add submodule" &&
++
++ cd sub &&
++ ROOT="$(test-tool path-utils real_path ..)" &&
++
++ echo "path.superproject-root.absolute=$ROOT" >expect.abs &&
++ git repo info path.superproject-root.absolute >actual.abs &&
++ test_cmp expect.abs actual.abs &&
+
-+test_repo_info_path 'index with GIT_INDEX_FILE override' 'index' \
-+ 'custom-index-file' \
-+ 'GIT_INDEX_FILE="$ROOT/custom-index-file" && export GIT_INDEX_FILE'
++ echo "path.superproject-root.relative=../" >expect.rel &&
++ git repo info path.superproject-root.relative >actual.rel &&
++ test_cmp expect.rel actual.rel
++ )
++'
+
-+test_expect_success 'path.index in a bare repository returns default index location' '
-+ test_when_finished "rm -rf bare.git" &&
-+ git init --bare bare.git &&
++test_expect_success 'path.superproject-root returns empty when not in a submodule' '
++ test_when_finished "rm -rf repo" &&
++ git init repo &&
+ (
-+ cd bare.git &&
-+ ROOT="$(test-tool path-utils real_path .)" &&
++ cd repo &&
+
-+ echo "path.index.absolute=$ROOT/index" >expect.abs &&
-+ git repo info path.index.absolute >actual.abs &&
++ echo "path.superproject-root.absolute=" >expect.abs &&
++ git repo info path.superproject-root.absolute >actual.abs &&
+ test_cmp expect.abs actual.abs &&
+
-+ echo "path.index.relative=index" >expect.rel &&
-+ git repo info path.index.relative >actual.rel &&
++ echo "path.superproject-root.relative=" >expect.rel &&
++ git repo info path.superproject-root.relative >actual.rel &&
+ test_cmp expect.rel actual.rel
+ )
+'
+
- test_expect_success 'path.superproject-root absolute and relative' '
- test_when_finished "rm -rf sub super" &&
- git init sub &&
+ test_expect_success 'path.toplevel absolute and relative' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
2: dcbaf1cb96 = 4: 09d2937fcd repo: add path.hooks with absolute and relative suffixes
-: ---------- > 5: d0c186f150 repo: add path.index with absolute and relative suffixes
4: ced5b0cb8b = 6: 351b4b7de7 repo: add path.grafts with absolute and relative suffixes
5: ac766e49e3 = 7: ef69d4aa8c repo: add path.git-prefix
6: 0a0c3dd924 ! 8: 3e61728dba repo: add path.cdup
@@ Documentation/git-repo.adoc: values that they return:
The object format (hash algorithm) used in the repository.
+`path.cdup`::
-+ The path to the root of the working tree relative to the current
-+ working directory. Returns the empty string when the current
-+ working directory is the root of the working tree.
++ When the command is invoked from a subdirectory, show the
++ path of the top-level directory relative to the current
++ directory (typically a sequence of "../", or an empty string).
+
`path.commondir.absolute`::
The canonical absolute path to the Git repository's common
@@ builtin/repo.c: static int get_object_format(struct repository *repo, struct str
+{
+ const char *pfx = repo->prefix;
+
++ if (!is_inside_work_tree(repo)) {
++ const char *worktree = repo_get_work_tree(repo);
++
++ if (worktree) {
++ strbuf_addstr(buf, worktree);
++ }
++ }
++
+ while (pfx) {
+ pfx = strchr(pfx, '/');
+ if (pfx) {
@@ t/t1900-repo-info.sh: test_repo_info_path 'commondir with only GIT_DIR' 'commond
+ test_cmp expect actual
+ )
+'
++
++test_expect_success 'path.cdup cwd outside the working tree' '
++ test_when_finished "rm -rf repo" &&
++ mkdir -p repo/tmp/x &&
++ cd repo &&
++ git init test &&
++ (
++ echo path.cdup=$(pwd)/tmp/x >./test/expect &&
++ cd test &&
++ GIT_WORK_TREE=../tmp/x &&
++ export GIT_WORK_TREE &&
++ GIT_DIR=$(pwd)/.git &&
++ export GIT_DIR &&
++ git repo info path.cdup >actual &&
++ test_cmp expect actual
++ )
++'
+
test_expect_success 'path.git-prefix at repository root' '
test_when_finished "rm -rf repo" &&Signature · 1 line
2.56.0-rc2
PATCH v7 1/8 repo: add path.toplevel with absolute and relative suffix formatting
Scripts frequently need to find the root directory of a repository's working tree. Currently, this requires using git rev-parse --show-toplevel or inferring it from other repository information.
Introduce path.toplevel.absolute and path.toplevel.relative keys to git repo info. This allows scripts to retrieve the top-level working tree path in a predictable, strictly formatted manner without relying on rev-parse.
If requested in a bare repository where no working tree exists, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.toplevel.absolute`:: + The canonical absolute path to the top-level directory of the + repository's working tree. Outputs an empty string if the repository + is bare. + +`path.toplevel.relative`:: + The path to the top-level directory of the repository's working + tree relative to the current working directory. Outputs an empty + string if the repository is bare. + `references.format`:: The reference storage format. The valid values are: +
builtin/repo.c +24 -0
@@ -121,6 +121,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) +return 0 ; + +format_path (buf, work_tree,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_toplevel_relative (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) +return 0 ; + +format_path (buf, work_tree, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_references_format (struct repository *repo,struct strbuf *buf) { strbuf_addstr(buf,
@@ -137,6 +159,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.toplevel.absolute", get_path_toplevel_absolute }, + { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format }, };
t/t1900-repo-info.sh +35 -0
@@ -213,4 +213,39 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.toplevel absolute and relative' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.toplevel.absolute=$ROOT" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=../" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.toplevel absolute and relative in a bare repository' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + + echo "path.toplevel.absolute=" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_done
Signature · 1 line
2.56.0-rc2
PATCH v7 2/8 submodule: use repository to find superproject
In reply to K Jayatheerthget_superproject_working_tree() currently uses xgetcwd() to determine the repository whose superproject should be checked.
This is incorrect when --git-dir points to a repository different from the one associated with the current working directory. In that case, the current working directory may cause the function to return the wrong superproject or an empty result.
Pass the repository to get_superproject_working_tree() so that the superproject is determined from the repository being inspected rather than the current working directory.
--- builtin/rev-parse.c | 2 +- submodule.c | 43 +++++++++++++++++++------------------- submodule.h | 2 +- t/t7400-submodule-basic.sh | 19 +++++++++++++++++ 4 files changed, 43 insertions(+), 23 deletions(-)
builtin/rev-parse.c +1 -1
@@ -997,7 +997,7 @@ int cmd_rev_parse(int argc, }if (!strcmp (arg,"--show-superproject-working-tree" )) {struct strbuf superproject =STRBUF_INIT ; -if (get_superproject_working_tree (&superproject)) +if (get_superproject_working_tree (the_repository, &superproject))print_path (superproject.buf, prefix, format,DEFAULT_UNMODIFIED );strbuf_release (&superproject);continue ;
submodule.c +22 -21
99 lines not on this page · raw message
submodule.h +1 -1
@@ -170,6 +170,6 @@ void absorb_git_dir_into_superproject(const char *path,* project is a submodule of. If this repository is not a submodule of * another repository, return 0. */ -int get_superproject_working_tree (struct strbuf *buf); +int get_superproject_working_tree (struct repository *r,struct strbuf *buf);#endif
t/t7400-submodule-basic.sh +19 -0
@@ -1549,4 +1549,23 @@ test_expect_success 'submodule add fails when name is reused' ' ) ' +test_expect_success 'path.superproject-root works with --git-dir' ' + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + SUPER_ROOT="$(test-tool path-utils real_path .)" && + MODULE_DIR="$SUPER_ROOT/.git/modules/sub" && + + echo "path.superproject-root.absolute=$SUPER_ROOT" >expect && + git --git-dir="$MODULE_DIR" repo info path.superproject-root.absolute >actual && + test_cmp expect actual + ) +' + test_done
Signature · 1 line
2.56.0-rc2
Re: [GSoC Patch v7 2/8] submodule: use repository to find superproject
Quoted 7 lines · K Jayatheerth
get_superproject_working_tree()currently usesxgetcwd()to determine the repository whose superproject should be checked.This is incorrect when
--git-dirpoints to a repository different from the one associated with the current working directory. In that case, the current working directory may cause the function to return the wrong superproject or an empty result.
Ok, so we are not taking into account here that the git dir location could be different than the current working directory.
Quoted 3 lines
Pass the
repositorytoget_superproject_working_tree()so that the superproject is determined from the repository being inspected rather than the current working directory.
Makes sense.
Quoted 42 lines
Mentored-by Justin Tobler <[email protected]>Mentored-by Lucas Seiki Oshiro <[email protected]>Signed-off-by K Jayatheerth <[email protected]>--- builtin/rev-parse.c | 2 +- submodule.c | 43 +++++++++++++++++++------------------- submodule.h | 2 +- t/t7400-submodule-basic.sh | 19 +++++++++++++++++ 4 files changed, 43 insertions(+), 23 deletions(-)builtin/rev-parse.c +1
-1@@ -997,7 +997,7 @@ int cmd_rev_parse(int argc, }if (!strcmp (arg,"--show-superproject-working-tree" )) {struct strbuf superproject =STRBUF_INIT ; -if (get_superproject_working_tree (&superproject)) +if (get_superproject_working_tree (the_repository, &superproject))print_path (superproject.buf, prefix, format,DEFAULT_UNMODIFIED );strbuf_release (&superproject);continue ;submodule.c +3
-2@@ -2610,34 +2610,35 @@ void absorb_git_dir_into_superproject(const char *path,absorb_git_dir_into_superproject_recurse (path, super_prefix); } -int get_superproject_working_tree (struct strbuf *buf) +int get_superproject_working_tree (struct repository *r,struct strbuf *buf) {struct child_process cp =CHILD_PROCESS_INIT ;struct strbuf sb =STRBUF_INIT ;struct strbuf one_up =STRBUF_INIT ; -char *cwd =xgetcwd (); +struct strbuf target_wt =STRBUF_INIT ; +const char *worktree;int ret =0 ;const char *subpath;
submodule.c void absorb_git_dir_into_superproject(const char *path, · line 2625
Quoted 10 lines
submodule.c +1
-6int code;ssize_t len; -if (!is_inside_work_tree (the_repository)) -/* -* FIXME: -* We might have a superproject, but it is harder -* to determine. -*/ + worktree =repo_get_work_tree (r);
We now use the passed repository to get the working tree instead of relying getting the current working directory and checking if we are inside a worktree. Looks good.
submodule.c void absorb_git_dir_into_superproject(const char *path, · line 2633
Quoted 9 lines
submodule.c +6
-1+if (!worktree) + goto out; + +if (!strbuf_realpath (&target_wt, worktree,0 )) goto out; -if (!strbuf_realpath (&one_up,"../" ,0 )) +strbuf_addf (&one_up,"%s/.." , target_wt.buf); +if (!strbuf_realpath (&one_up, one_up.buf,0 ))
I was confused at first why we bother invoking strbuf_realpath() here since it's just an intermediate step, but I assume that is so we can use it in the error statement later on.
Quoted 30 lines
submodule.c +4
-4goto out; - subpath =relative_path (cwd, one_up.buf, &sb); + subpath =relative_path (target_wt.buf, one_up.buf, &sb);prepare_submodule_repo_env (&cp.env);strvec_pop (&cp.env); -strvec_pushl (&cp.args,"--literal-pathspecs" ,"-C" ,".." , +strvec_pushl (&cp.args,"--literal-pathspecs" ,"-C" , one_up.buf,"ls-files" ,"-z" ,"--stage" ,"--full-name" ,"--" , subpath,NULL );strbuf_reset (&sb);@@ -2648,14 +2649,14 @@ int get_superproject_working_tree(struct strbuf *buf) cp.git_cmd =1 ;if (start_command (&cp)) -die (_ ("could not start ls-files in .." )); +die (_ ("could not start ls-files in %s" ), one_up.buf); len =strbuf_read (&sb, cp.out,PATH_MAX );close (cp.out);if (starts_with (sb.buf,"160000" )) {int super_sub_len; -int cwd_len =strlen (cwd); +int wt_len = target_wt.len;char *super_sub, *super_wt;/*
[snip]
Quoted 5 lines
submodule.c +5
-0+test_expect_success 'path.superproject-root works with --git-dir' ' + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super &&
submodule.c
Quoted 10 lines
submodule.c +10
-0+ ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + +SUPER_ROOT ="$(test-tool path-utils real_path .)" && +MODULE_DIR ="$SUPER_ROOT/.git/modules/sub" && + + echo"path.superproject-root.absolute=$SUPER_ROOT" >expect && + git --git-dir="$MODULE_DIR" repo info path.superproject-root.absolute >actual &&
path.superproject-root isn't introduced until the next patch, so this test fails at this commit. Maybe the test should exercise the existing git --git-dir=... rev-parse --show-superproject-working-tree caller in t1500 instead?
-Justin
Re: [GSoC Patch v7 2/8] submodule: use repository to find superproject
Quoted 17 lines · Justin Tobler
Quoted 7 lines · K Jayatheerth
get_superproject_working_tree()currently usesxgetcwd()to determine the repository whose superproject should be checked.This is incorrect when
--git-dirpoints to a repository different from the one associated with the current working directory. In that case, the current working directory may cause the function to return the wrong superproject or an empty result.Ok, so we are not taking into account here that the git dir location could be different than the current working directory.
Quoted 3 lines
Pass the
repositorytoget_superproject_working_tree()so that the superproject is determined from the repository being inspected rather than the current working directory.
[snip]
Quoted 13 lines
[snip]
Quoted 12 lines
t/t7400-submodule-basic.sh +12
-0+test_expect_success 'path.superproject-root works with --git-dir' ' + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + SUPER_ROOT="$(test-tool path-utils real_path .)" && + MODULE_DIR="$SUPER_ROOT/.git/modules/sub" &&
Quoted 9 lines
t/t7400-submodule-basic.sh test_expect_success 'submodule add fails when name is reused' ' · line 1566
Quoted 3 lines
t/t7400-submodule-basic.sh +3
-0+ + echo "path.superproject-root.absolute=$SUPER_ROOT" >expect && + git --git-dir="$MODULE_DIR" repo info path.superproject-root.absolute >actual &&
path.superproject-rootisn't introduced until the next patch, so this test fails at this commit. Maybe the test should exercise the existinggit --git-dir=... rev-parse --show-superproject-working-treecaller in t1500 instead?
Right, It was meant to use rev-parse. I will make the change.
- K Jayatheerth
PATCH v7 3/8 repo: add path.superproject-root with absolute and relative suffixes
In reply to K JayatheerthScripts working in multi-repository setups often need to identify the top-level working tree of a superproject from within a submodule. Currently, this is only exposed via git rev-parse --show-superproject-working-tree.
Introduce path.superproject-root.absolute and path.superproject-root.relative keys to git repo info. This exposes the core submodule context via a scriptable config-like key using standard format rules.
If requested when not inside a submodule, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 31 +++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 80 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.superproject-root.absolute`:: + The canonical absolute path to the working tree root of the superproject + if the current repository is an initialized submodule. Outputs an empty + string if not in a submodule. + +`path.superproject-root.relative`:: + The path to the working tree root of the superproject relative to the + current working directory if the current repository is an initialized + submodule. Outputs an empty string if not in a submodule. + `path.toplevel.absolute`:: The canonical absolute path to the top-level directory of the repository's working tree. Outputs an empty string if the repository
builtin/repo.c +31 -0
@@ -18,6 +18,7 @@#include "strbuf.h" #include "string-list.h" #include "shallow.h" +#include "submodule.h" #include "tree.h" #include "tree-walk.h" #include "utf8.h"
@@ -121,6 +122,34 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_superproject_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (repo, &superproject)) { +strbuf_release (&superproject); +return 0 ; + } + +format_path (buf, superproject.buf,"" ,PATH_FORMAT_CANONICAL ); +strbuf_release (&superproject); +return 0 ; +} + +static int get_path_superproject_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (repo, &superproject)) { +strbuf_release (&superproject); +return 0 ; + } + +format_path (buf, superproject.buf, repo->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&superproject); +return 0 ; +} +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) {const char *work_tree =repo_get_work_tree (repo);
@@ -159,6 +188,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.superproject-root.absolute", get_path_superproject_absolute }, + { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute }, { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format },
t/t1900-repo-info.sh +39 -0
@@ -213,6 +213,45 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.superproject-root absolute and relative' ' + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + cd sub && + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.superproject-root.absolute=$ROOT" >expect.abs && + git repo info path.superproject-root.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superproject-root.relative=../" >expect.rel && + git repo info path.superproject-root.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.superproject-root returns empty when not in a submodule' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + echo "path.superproject-root.absolute=" >expect.abs && + git repo info path.superproject-root.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superproject-root.relative=" >expect.rel && + git repo info path.superproject-root.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_expect_success 'path.toplevel absolute and relative' ' test_when_finished "rm -rf repo" && git init repo &&
Signature · 1 line
2.56.0-rc2
Re: [GSoC Patch v7 3/8] repo: add path.superproject-root with absolute and relative suffixes
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 131
Quoted 7 lines · K Jayatheerth
builtin/repo.c +7
-0+static int get_path_superproject_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (repo, &superproject)) { +strbuf_release (&superproject); +return 0 ;
nit: The early return isn't really need here. This instead could be:
if (get_superproject_working_tree(repo, &superproject))
format_path(buf, superproject.buf, "", PATH_FORMAT_CANONICAL);Quoted 4 lines
builtin/repo.c +4
-0+ } + +format_path (buf, superproject.buf,"" ,PATH_FORMAT_CANONICAL ); +strbuf_release (&superproject);
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 145
Quoted 10 lines
builtin/repo.c +10
-0+return 0 ; +} + +static int get_path_superproject_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (repo, &superproject)) { +strbuf_release (&superproject); +return 0 ;
Same thing here.
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 151
Quoted 6 lines
builtin/repo.c +6
-0+ } + +format_path (buf, superproject.buf, repo->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&superproject); +return 0 ; +}
The rest of this patch looks good to me.
-Justin
Re: [GSoC Patch v7 3/8] repo: add path.superproject-root with absolute and relative suffixes
Quoted 12 lines · Justin Tobler
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 131
Quoted 7 lines · K Jayatheerth
builtin/repo.c +7
-0+static int get_path_superproject_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (repo, &superproject)) { +strbuf_release (&superproject); +return 0 ;nit: The early return isn't really need here. This instead could be:
Neat, I will use it!
Quoted 20 lines
if (get_superproject_working_tree(repo, &superproject)) format_path(buf, superproject.buf, "", PATH_FORMAT_CANONICAL);Quoted 4 lines
builtin/repo.c +4
-0+ } + +format_path (buf, superproject.buf,"" ,PATH_FORMAT_CANONICAL ); +strbuf_release (&superproject);builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 145
Quoted 10 lines
builtin/repo.c +10
-0+return 0 ; +} + +static int get_path_superproject_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (!get_superproject_working_tree (repo, &superproject)) { +strbuf_release (&superproject); +return 0 ;Same thing here.
Sure thing.
Quoted 9 lines
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 151
Quoted 6 lines
builtin/repo.c +6
-0+ } + +format_path (buf, superproject.buf, repo->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&superproject); +return 0 ; +}The rest of this patch looks good to me.
Thanks!
- K Jayatheerth
PATCH v7 4/8 repo: add path.hooks with absolute and relative suffixes
In reply to K JayatheerthHooks are an integral part of a repository's configuration and are commonly used by tooling to automate repository-specific workflows. Currently, scripts typically retrieve the hooks directory by invoking git rev-parse --git-path hooks.
Introduce path.hooks.absolute and path.hooks.relative keys to git repo info. This exposes the hooks directory as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 9 +++++++++ builtin/repo.c | 22 ++++++++++++++++++++++ t/t1900-repo-info.sh | 28 ++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-)
Documentation/git-repo.adoc +9 -0
@@ -119,6 +119,15 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.hooks.absolute`:: + The canonical absolute path to the repository's hooks directory. + Respects the `core.hooksPath` configuration. If `core.hooksPath` is + set to `/dev/null`, that value is returned unchanged. + +`path.hooks.relative`:: + The path to the repository's hooks directory relative to the current + working directory. Respects the `core.hooksPath` configuration. + `path.superproject-root.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +22 -0
@@ -122,6 +122,26 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf,"" ,PATH_FORMAT_CANONICAL ); +strbuf_release (&hooks_path); +return 0 ; +} + +static int get_path_hooks_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +format_path (buf, hooks_path.buf, repo->prefix,PATH_FORMAT_RELATIVE ); +strbuf_release (&hooks_path); +return 0 ; +} +static int get_path_superproject_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -188,6 +208,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.hooks.absolute", get_path_hooks_absolute }, + { "path.hooks.relative", get_path_hooks_relative }, { "path.superproject-root.absolute", get_path_superproject_absolute }, { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +26 -2
@@ -174,7 +174,11 @@ test_repo_info_path () { cd repo/sub && ROOT="$(test-tool path-utils real_path ..)" && export ROOT && eval "$init_command" && - echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect && + case "$expected_dir" in + /*) EXPECT_ABS="$expected_dir" ;; + *) EXPECT_ABS="$ROOT/$expected_dir" ;; + esac && + echo "path.$field_name.absolute=$EXPECT_ABS" >expect && git repo info "path.$field_name.absolute" >actual && test_cmp expect actual )
@@ -188,7 +192,11 @@ test_repo_info_path () { cd repo/sub && ROOT="$(test-tool path-utils real_path ..)" && export ROOT && eval "$init_command" && - echo "path.$field_name.relative=../$expected_dir" >expect && + case "$expected_dir" in + /*) EXPECT_REL="$(test-tool path-utils relative_path "$expected_dir" "$PWD")" ;; + *) EXPECT_REL="../$expected_dir" ;; + esac && + echo "path.$field_name.relative=$EXPECT_REL" >expect && git repo info "path.$field_name.relative" >actual && test_cmp expect actual )
@@ -213,6 +221,22 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'hooks standard' 'hooks' '.git/hooks' + +test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ + 'custom-hooks' \ + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' + +# /dev/null is not a real, canonicalizable filesystem path on Windows, +# so path resolution for core.hooksPath=/dev/null cannot be expected to +# produce a literal "/dev/null" the way it does on POSIX systems. +if ! test_have_prereq MINGW +then + test_repo_info_path 'hooks with core.hooksPath=/dev/null' 'hooks' \ + '/dev/null' \ + 'git config core.hooksPath /dev/null' +fi + test_expect_success 'path.superproject-root absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.56.0-rc2
Re: [GSoC Patch v7 4/8] repo: add path.hooks with absolute and relative suffixes
Quoted 26 lines · K Jayatheerth
Hooks are an integral part of a repository's configuration and are commonly used by tooling to automate repository-specific workflows. Currently, scripts typically retrieve the hooks directory by invoking
git rev-parse --git-path hooks.Introduce
path.hooks.absoluteandpath.hooks.relativekeys togit repo info. This exposes the hooks directory as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.Mentored-by Justin Tobler <[email protected]>Mentored-by Lucas Seiki Oshiro <[email protected]>Signed-off-by K Jayatheerth <[email protected]>--- Documentation/git-repo.adoc | 9 +++++++++ builtin/repo.c | 22 ++++++++++++++++++++++ t/t1900-repo-info.sh | 28 ++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-)Documentation/git-repo.adoc +0
-0@@ -119,6 +119,15 @@ values that they return: `path.gitdir.relative`::
Documentation/git-repo.adoc values that they return: · line 129
Quoted 10 lines
Documentation/git-repo.adoc +8
-0The path to the Git repository directory relative to the current working directory. +`path.hooks.absolute`:: + The canonical absolute path to the repository's hooks directory. + Respects the `core.hooksPath` configuration. If `core.hooksPath` is + set to `/dev/null`, that value is returned unchanged. + +`path.hooks.relative`:: + The path to the repository's hooks directory relative to the current + working directory. Respects the `core.hooksPath` configuration.
So if a repository has core.hooksPath set to "/dev/null", the relative path output here would be something like "../../../../dev/null". I recognize that this matches the current behavior:
$ git -c core.hooksPath=/dev/null rev-parse --path-format=relative --git-path hooks ../../../../dev/null
...but I'm still not really convinced that is is a behavior we would want to carry over as it makes it harder to users to figure out when hooks are disabled.
I would suggest we print the "/dev/null" here even when the relative path is requested and document the behavior.
[snip]
Quoted 20 lines
t/t1900-repo-info.sh +5
-1@@ -174,7 +174,11 @@ test_repo_info_path () { cd repo/sub && ROOT="$(test-tool path-utils real_path ..)" && export ROOT && eval "$init_command" && - echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect && + case "$expected_dir" in + /*) EXPECT_ABS="$expected_dir" ;; + *) EXPECT_ABS="$ROOT/$expected_dir" ;; + esac && + echo "path.$field_name.absolute=$EXPECT_ABS" >expect && git repo info "path.$field_name.absolute" >actual && test_cmp expect actual )@@ -188,7 +192,11 @@ test_repo_info_path () { cd repo/sub && ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
t/t1900-repo-info.sh test_repo_info_path () { · line 202
Quoted 10 lines
t/t1900-repo-info.sh +5
-1eval "$init_command" && - echo "path.$field_name.relative=../$expected_dir" >expect && + case "$expected_dir" in + /*) EXPECT_REL="$(test-tool path-utils relative_path "$expected_dir" "$PWD")" ;; + *) EXPECT_REL="../$expected_dir" ;; + esac && + echo "path.$field_name.relative=$EXPECT_REL" >expect && git repo info "path.$field_name.relative" >actual && test_cmp expect actual )
From what I can gather, the code changes to this test helper is really only required for the "/dev/null" test case. IMO, this helper function has now become quite unwieldy and rather difficult to parse.
I think we would be better off writing the "/dev/null" test case by hand.
Quoted 9 lines
t/t1900-repo-info.sh +5
-0@@ -213,6 +221,22 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'hooks standard' 'hooks' '.git/hooks' + +test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ + 'custom-hooks' \ + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"'
t/t1900-repo-info.sh test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ · line 238
Quoted 10 lines
t/t1900-repo-info.sh +10
-0+ +# /dev/null is not a real, canonicalizable filesystem path on Windows, +# so path resolution for core.hooksPath=/dev/null cannot be expected to +# produce a literal "/dev/null" the way it does on POSIX systems. +if ! test_have_prereq MINGW +then + test_repo_info_path 'hooks with core.hooksPath=/dev/null' 'hooks' \ + '/dev/null' \ + 'git config core.hooksPath /dev/null' +fi
I'm not quite sure I follow here. Are we saying that the git-repo-info command won't work on windows if the hooks are set to "/dev/null"? Or is it just some issue with how the test is written? If its the latter, maybe this is something we can work around if the test is written without the use of the test_repo_info_path helper?
-Justin
Re: [GSoC Patch v7 4/8] repo: add path.hooks with absolute and relative suffixes
Quoted 46 lines · Justin Tobler
Quoted 26 lines · K Jayatheerth
Hooks are an integral part of a repository's configuration and are commonly used by tooling to automate repository-specific workflows. Currently, scripts typically retrieve the hooks directory by invoking
git rev-parse --git-path hooks.Introduce
path.hooks.absoluteandpath.hooks.relativekeys togit repo info. This exposes the hooks directory as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.Mentored-by Justin Tobler <[email protected]>Mentored-by Lucas Seiki Oshiro <[email protected]>Signed-off-by K Jayatheerth <[email protected]>--- Documentation/git-repo.adoc | 9 +++++++++ builtin/repo.c | 22 ++++++++++++++++++++++ t/t1900-repo-info.sh | 28 ++++++++++++++++++++++++++-- 3 files changed, 57 insertions(+), 2 deletions(-)Documentation/git-repo.adoc +0
-0@@ -119,6 +119,15 @@ values that they return: `path.gitdir.relative`::Documentation/git-repo.adoc values that they return: · line 129
Quoted 10 lines
Documentation/git-repo.adoc +8
-0The path to the Git repository directory relative to the current working directory. +`path.hooks.absolute`:: + The canonical absolute path to the repository's hooks directory. + Respects the `core.hooksPath` configuration. If `core.hooksPath` is + set to `/dev/null`, that value is returned unchanged. + +`path.hooks.relative`:: + The path to the repository's hooks directory relative to the current + working directory. Respects the `core.hooksPath` configuration.So if a repository has
core.hooksPathset to "/dev/null", the relative path output here would be something like "../../../../dev/null". I recognize that this matches the current behavior:$ git -c core.hooksPath=/dev/null rev-parse --path-format=relative --git-path hooks ../../../../dev/null
Quoted 7 lines
...but I'm still not really convinced that is is a behavior we would want to carry over as it makes it harder to users to figure out when hooks are disabled.
I would suggest we print the "
/dev/null" here even when the relative path is requested and document the behavior.
I am more inclined with you, and
I see how returning "/dev/null" for the relative key makes it much easier for scripts to detect when hooks are disabled.
One thing I wanted to check: in a follow-up series, Junio suggested extracting a common helper library to share implementations between git rev-parse and git repo info. If git repo info special-cases "/dev/null" for path.hooks.relative while rev-parse --git-path hooks continues to relative-format it, would that divergence be an issue for sharing the underlying helper, or should we special-case it only in the path.hooks getter?
Quoted 36 lines
[snip]
Quoted 20 lines
t/t1900-repo-info.sh +5
-1@@ -174,7 +174,11 @@ test_repo_info_path () { cd repo/sub && ROOT="$(test-tool path-utils real_path ..)" && export ROOT && eval "$init_command" && - echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect && + case "$expected_dir" in + /*) EXPECT_ABS="$expected_dir" ;; + *) EXPECT_ABS="$ROOT/$expected_dir" ;; + esac && + echo "path.$field_name.absolute=$EXPECT_ABS" >expect && git repo info "path.$field_name.absolute" >actual && test_cmp expect actual )@@ -188,7 +192,11 @@ test_repo_info_path () { cd repo/sub && ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&t/t1900-repo-info.sh test_repo_info_path () { · line 202
Quoted 10 lines
t/t1900-repo-info.sh +5
-1eval "$init_command" && - echo "path.$field_name.relative=../$expected_dir" >expect && + case "$expected_dir" in + /*) EXPECT_REL="$(test-tool path-utils relative_path "$expected_dir" "$PWD")" ;; + *) EXPECT_REL="../$expected_dir" ;; + esac && + echo "path.$field_name.relative=$EXPECT_REL" >expect && git repo info "path.$field_name.relative" >actual && test_cmp expect actual )From what I can gather, the code changes to this test helper is really only required for the "
/dev/null" test case. IMO, this helper function has now become quite unwieldy and rather difficult to parse.
Quoted 2 lines
I think we would be better off writing the "
/dev/null" test case by hand.
Agreed, reverting the changes to test_repo_info_path and writing the /dev/null test as a standalone test block will be much cleaner.
Quoted 17 lines
Quoted 17 lines
t/t1900-repo-info.sh +13
-0@@ -213,6 +221,22 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'hooks standard' 'hooks' '.git/hooks' + +test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ + 'custom-hooks' \ + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' + +# /dev/null is not a real, canonicalizable filesystem path on Windows, +# so path resolution for core.hooksPath=/dev/null cannot be expected to +# produce a literal "/dev/null" the way it does on POSIX systems. +if ! test_have_prereq MINGW +then + test_repo_info_path 'hooks with core.hooksPath=/dev/null' 'hooks' \ + '/dev/null' \
Quoted 9 lines
t/t1900-repo-info.sh test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ · line 238
Quoted 2 lines
t/t1900-repo-info.sh +2
-0+ 'git config core.hooksPath /dev/null' +fiI'm not quite sure I follow here. Are we saying that the git-repo-info command won't work on windows if the hooks are set to "
/dev/null"? Or is it just some issue with how the test is written? If its the latter, maybe this is something we can work around if the test is written without the use of thetest_repo_info_pathhelper?
It was both the command and the test helper on Windows, /dev/null is not an actual filesystem path, so passing it through format_path() (and test-tool path-utils relative_path in the test) does not resolve the same way as on POSIX systems (where $PWD on Windows has a drive letter like C:/...).
However, if we special-case /dev/null in the C code so that both path.hooks.absolute and path.hooks.relative output /dev/null directly without passing it through format_path(), and write the test by hand, it will work consistently on Windows too and we can drop the !MINGW prerequisite entirely.
Quoted 1 line
-Justin
Thank you,
- K Jayatheerth
Re: [GSoC Patch v7 4/8] repo: add path.hooks with absolute and relative suffixes
Quoted 21 lines · K Jayatheerth
Quoted 8 lines · Justin Tobler
So if a repository has
core.hooksPathset to "/dev/null", the relative path output here would be something like "../../../../dev/null". I recognize that this matches the current behavior:$ git -c core.hooksPath=/dev/null rev-parse --path-format=relative --git-path hooks ../../../../dev/nullQuoted 7 lines
...but I'm still not really convinced that is is a behavior we would want to carry over as it makes it harder to users to figure out when hooks are disabled.
I would suggest we print the "
/dev/null" here even when the relative path is requested and document the behavior.I am more inclined with you, and
I see how returning "/dev/null" for the relative key makes it much easier for scripts to detect when hooks are disabled.
Quoted 7 lines
One thing I wanted to check: in a follow-up series, Junio suggested extracting a common helper library to share implementations between
git rev-parseandgit repo info. Ifgit repo infospecial-cases "/dev/null" forpath.hooks.relativewhilerev-parse --git-path hookscontinues to relative-format it, would that divergence be an issue for sharing the underlying helper, or should we special-case it only in thepath.hooksgetter?
I don't really think that would be an issue. Regarding the follow-up series, I figure you could just not use a shared helper here if the behavior is diverged, or special case it some way.
-Justin
Re: [GSoC Patch v7 4/8] repo: add path.hooks with absolute and relative suffixes
Quoted 31 lines · Justin Tobler
Quoted 21 lines · K Jayatheerth
Quoted 8 lines · Justin Tobler
So if a repository has
core.hooksPathset to "/dev/null", the relative path output here would be something like "../../../../dev/null". I recognize that this matches the current behavior:$ git -c core.hooksPath=/dev/null rev-parse --path-format=relative --git-path hooks ../../../../dev/nullQuoted 7 lines
...but I'm still not really convinced that is is a behavior we would want to carry over as it makes it harder to users to figure out when hooks are disabled.
I would suggest we print the "
/dev/null" here even when the relative path is requested and document the behavior.I am more inclined with you, and
I see how returning "/dev/null" for the relative key makes it much easier for scripts to detect when hooks are disabled.Quoted 7 lines
One thing I wanted to check: in a follow-up series, Junio suggested extracting a common helper library to share implementations between
git rev-parseandgit repo info. Ifgit repo infospecial-cases "/dev/null" forpath.hooks.relativewhilerev-parse --git-path hookscontinues to relative-format it, would that divergence be an issue for sharing the underlying helper, or should we special-case it only in thepath.hooksgetter?
Quoted 4 lines
I don't really think that would be an issue. Regarding the follow-up series, I figure you could just not use a shared helper here if the behavior is diverged, or special case it some way.
Sure, then setting a case for /dev/null makes sense I suppose. I can always as you mentioned make it a special case.
Quoted 1 line
-Justin
Thanks,
- K Jayatheerth
PATCH v7 5/8 repo: add path.index with absolute and relative suffixes
In reply to K JayatheerthThe repository index is a fundamental component used by Git and related tooling to track the working tree state. Scripts that interact with the index currently retrieve its location by invokinggit rev-parse --git-path index.
Introduce path.index.absolute and path.index.relative keys to git repo info. This exposes the index file location as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 12 ++++++++++++ builtin/repo.c | 18 ++++++++++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 53 insertions(+)
Documentation/git-repo.adoc +12 -0
@@ -128,6 +128,18 @@ values that they return: The path to the repository's hooks directory relative to the current working directory. Respects the `core.hooksPath` configuration. +`path.index.absolute`:: + The canonical absolute path to the repository's current index file. + Respects the `GIT_INDEX_FILE` environment override. Returns the + configured index path even if the repository is bare or the file does + not exist. + +`path.index.relative`:: + The path to the repository's current index file relative to the current + working directory. Respects the `GIT_INDEX_FILE` environment override. + Returns the configured index path even if the repository is bare or the + file does not exist. + `path.superproject-root.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +18 -0
@@ -142,6 +142,22 @@ static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_index_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +format_path (buf, index_file,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_index_relative (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +format_path (buf, index_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_superproject_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -210,6 +226,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.gitdir.relative", get_path_gitdir_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, + { "path.index.absolute", get_path_index_absolute }, + { "path.index.relative", get_path_index_relative }, { "path.superproject-root.absolute", get_path_superproject_absolute }, { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +23 -0
@@ -237,6 +237,29 @@ then 'git config core.hooksPath /dev/null' fi +test_repo_info_path 'index standard' 'index' '.git/index' + +test_repo_info_path 'index with GIT_INDEX_FILE override' 'index' \ + 'custom-index-file' \ + 'GIT_INDEX_FILE="$ROOT/custom-index-file" && export GIT_INDEX_FILE' + +test_expect_success 'path.index in a bare repository returns default index location' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + ROOT="$(test-tool path-utils real_path .)" && + + echo "path.index.absolute=$ROOT/index" >expect.abs && + git repo info path.index.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.index.relative=index" >expect.rel && + git repo info path.index.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_expect_success 'path.superproject-root absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.56.0-rc2
PATCH v7 6/8 repo: add path.grafts with absolute and relative suffixes
In reply to K JayatheerthThe repository grafts file specifies alternate parent relationships for commits and may be used by repository tooling that needs to inspect or manage grafts. Scripts currently retrieve its location by invoking git rev-parse --git-path info/grafts.
Introduce path.grafts.absolute and path.grafts.relative keys to git repo info. This exposes the grafts file location as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 11 +++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 6 ++++++ 3 files changed, 41 insertions(+)
Documentation/git-repo.adoc +11 -0
@@ -119,6 +119,17 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.grafts.absolute`:: + The canonical absolute path to the repository's graft file. + Respects the `GIT_GRAFT_FILE` environment override. The path is + returned regardless of whether the file currently exists on disk. + +`path.grafts.relative`:: + The path to the repository's graft file relative to the current + working directory. Respects the `GIT_GRAFT_FILE` environment + override. The path is returned regardless of whether the file + currently exists on disk. + `path.hooks.absolute`:: The canonical absolute path to the repository's hooks directory. Respects the `core.hooksPath` configuration. If `core.hooksPath` is
builtin/repo.c +24 -0
@@ -122,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_grafts_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_grafts_relative (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" )); + +format_path (buf, graft_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf hooks_path =STRBUF_INIT ;
@@ -224,6 +246,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.grafts.absolute", get_path_grafts_absolute }, + { "path.grafts.relative", get_path_grafts_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, { "path.index.absolute", get_path_index_absolute },
t/t1900-repo-info.sh +6 -0
@@ -221,6 +221,12 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'grafts standard' 'grafts' '.git/info/grafts' + +test_repo_info_path 'grafts with GIT_GRAFT_FILE override' 'grafts' \ + 'custom-graft-file' \ + 'GIT_GRAFT_FILE="$ROOT/custom-graft-file" && export GIT_GRAFT_FILE' + test_repo_info_path 'hooks standard' 'hooks' '.git/hooks' test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
Signature · 1 line
2.56.0-rc2
Re: [GSoC Patch v7 6/8] repo: add path.grafts with absolute and relative suffixes
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 130
Quoted 6 lines · K Jayatheerth
builtin/repo.c +6
-0+static int get_path_grafts_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" ));
nit: Similar to Junio's comment on the previous patch in the previous version, repo_get_graph_file() already BUGs if graft_file is NULL, so the error isn't really doing anything here.
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 141
Quoted 10 lines
builtin/repo.c +10
-0+format_path (buf, graft_file,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_grafts_relative (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" ));
Same here.
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 145
Quoted 3 lines
builtin/repo.c +3
-0+format_path (buf, graft_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +}
The rest of this patch looks fine, but I do wonder if it really makes sense to include this patch at all because graphs are deprecated feature and also slated for removal in "Documentation/BreakingChanges.adoc".
Maybe we should just drop this patch?
-Justin
Re: [GSoC Patch v7 6/8] repo: add path.grafts with absolute and relative suffixes
Quoted 13 lines · Justin Tobler
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 130
Quoted 6 lines · K Jayatheerth
builtin/repo.c +6
-0+static int get_path_grafts_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" ));nit: Similar to Junio's comment on the previous patch in the previous version,
repo_get_graph_file()already BUGs ifgraft_fileis NULL, so the error isn't really doing anything here.
Right, I am going to depend on the original error check.
Quoted 4 lines
Quoted 4 lines
builtin/repo.c +4
-0+format_path (buf, graft_file,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} +
Quoted 9 lines
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 141
Quoted 6 lines
builtin/repo.c +6
-0+static int get_path_grafts_relative (struct repository *repo,struct strbuf *buf) +{ +const char *graft_file =repo_get_graft_file (repo); + +if (!graft_file) +return error (_ ("unable to get graft file" ));Same here.
Yup, will change.
Quoted 10 lines
builtin/repo.c static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) · line 145
Quoted 3 lines
builtin/repo.c +3
-0+format_path (buf, graft_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +}The rest of this patch looks fine, but I do wonder if it really makes sense to include this patch at all because graphs are deprecated feature and also slated for removal in "
Documentation/BreakingChanges.adoc".Maybe we should just drop this patch?
Ohw, that's an interesting question.
If they are being removed, then probably not including is a better choice. I remember including this because on the idea page they added this also I am a bit hazy on where but there was a discussion to include this.
Quoted 1 line
-Justin
- K Jayatheerth
PATCH v7 7/8 repo: add path.git-prefix
In reply to K JayatheerthScripts sometimes need the path from the repository's working tree root to the current working directory. While this information can be derived through existing Git commands, git repo info does not currently expose it as a scriptable key.
Introduce the path.git-prefix key to git repo info. The key returns the path from the working tree root to the current working directory, returning the empty string when invoked from the working tree root.
--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 11 +++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+)
Documentation/git-repo.adoc +5 -0
@@ -113,6 +113,11 @@ values that they return: The path to the Git repository's common directory relative to the current working directory. +`path.git-prefix`:: + The path from the root of the working tree to the current working + directory. Returns the empty string when the current working directory + is the root of the working tree. + `path.gitdir.absolute`:: The canonical absolute path to the Git repository directory (the `.git` directory).
builtin/repo.c +11 -0
@@ -100,6 +100,16 @@ static int get_path_commondir_relative(struct repository *repo, struct strbuf *breturn 0 ; } +static int get_path_git_prefix (struct repository *repo,struct strbuf *buf) +{ +/* +* repo->prefix is NULL when the current working directory is +* the worktree root. +*/ +strbuf_addstr (buf, repo->prefix ? repo->prefix :"" ); +return 0 ; +} +static int get_path_gitdir_absolute (struct repository *repo,struct strbuf *buf) {const char *git_dir =repo_get_git_dir (repo);
@@ -244,6 +254,7 @@ static const struct repo_info_field repo_info_field[] = { { "object.format", get_object_format }, { "path.commondir.absolute", get_path_commondir_absolute }, { "path.commondir.relative", get_path_commondir_relative }, + { "path.git-prefix", get_path_git_prefix }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, { "path.grafts.absolute", get_path_grafts_absolute },
t/t1900-repo-info.sh +23 -0
@@ -215,6 +215,29 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.git-prefix at repository root' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.git-prefix=" >expect && + git repo info path.git-prefix >actual && + test_cmp expect actual + ) +' + +test_expect_success 'path.git-prefix in subdirectory' ' + test_when_finished "rm -rf repo" && + git init repo && + mkdir -p repo/sub/dir && + ( + cd repo/sub/dir && + echo "path.git-prefix=sub/dir/" >expect && + git repo info path.git-prefix >actual && + test_cmp expect actual + ) +' + test_repo_info_path 'gitdir standard' 'gitdir' '.git' test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
Signature · 1 line
2.56.0-rc2
PATCH v7 8/8 repo: add path.cdup
In reply to K JayatheerthScripts sometimes need the relative path from the current working directory to the repository's working tree root (cdup). While this information can be retrieved through git rev-parse --show-cdup, git repo info does not currently expose it as a scriptable key.
Introduce the path.cdup key to git repo info. The key returns the path from the current working directory to the root of the working tree, returning the empty string when invoked from the working tree root.
--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 23 +++++++++++++++++++++ t/t1900-repo-info.sh | 40 +++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+)
Documentation/git-repo.adoc +5 -0
@@ -104,6 +104,11 @@ values that they return: `object.format`:: The object format (hash algorithm) used in the repository. +`path.cdup`:: + When the command is invoked from a subdirectory, show the + path of the top-level directory relative to the current + directory (typically a sequence of "../", or an empty string). + `path.commondir.absolute`:: The canonical absolute path to the Git repository's common directory (the shared `.git` directory containing objects,
builtin/repo.c +23 -0
@@ -78,6 +78,28 @@ static int get_object_format(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_cdup (struct repository *repo,struct strbuf *buf) +{ +const char *pfx = repo->prefix; + +if (!is_inside_work_tree (repo)) { +const char *worktree =repo_get_work_tree (repo); + +if (worktree) { +strbuf_addstr (buf, worktree); + } + } + +while (pfx) { + pfx =strchr (pfx,'/' ); +if (pfx) { + pfx++; +strbuf_addstr (buf,"../" ); + } + } +return 0 ; +} +static int get_path_commondir_absolute (struct repository *repo,struct strbuf *buf) {const char *common_dir =repo_get_common_dir (repo);
@@ -252,6 +274,7 @@ static const struct repo_info_field repo_info_field[] = { { "layout.bare", get_layout_bare }, { "layout.shallow", get_layout_shallow }, { "object.format", get_object_format }, + { "path.cdup", get_path_cdup }, { "path.commondir.absolute", get_path_commondir_absolute }, { "path.commondir.relative", get_path_commondir_relative }, { "path.git-prefix", get_path_git_prefix },
t/t1900-repo-info.sh +40 -0
@@ -215,6 +215,46 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.cdup at repository root' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.cdup=" >expect && + git repo info path.cdup >actual && + test_cmp expect actual + ) +' + +test_expect_success 'path.cdup in subdirectory' ' + test_when_finished "rm -rf repo" && + git init repo && + mkdir -p repo/sub/dir && + ( + cd repo/sub/dir && + echo "path.cdup=../../" >expect && + git repo info path.cdup >actual && + test_cmp expect actual + ) +' + +test_expect_success 'path.cdup cwd outside the working tree' ' + test_when_finished "rm -rf repo" && + mkdir -p repo/tmp/x && + cd repo && + git init test && + ( + echo path.cdup=$(pwd)/tmp/x >./test/expect && + cd test && + GIT_WORK_TREE=../tmp/x && + export GIT_WORK_TREE && + GIT_DIR=$(pwd)/.git && + export GIT_DIR && + git repo info path.cdup >actual && + test_cmp expect actual + ) +' + test_expect_success 'path.git-prefix at repository root' ' test_when_finished "rm -rf repo" && git init repo &&
Signature · 1 line
2.56.0-rc2
Re: [GSoC Patch v7 8/8] repo: add path.cdup
On 26/09/27 05:14PM, K Jayatheerth wrote:
[snip]
builtin/repo.c static int get_object_format(struct repository *repo, struct strbuf *buf) · line 90
Quoted 10 lines
builtin/repo.c +10
-0+static int get_path_cdup (struct repository *repo,struct strbuf *buf) +{ +const char *pfx = repo->prefix; + +if (!is_inside_work_tree (repo)) { +const char *worktree =repo_get_work_tree (repo); + +if (worktree) { +strbuf_addstr (buf, worktree); + }
nit: The curly braces on a single line if statement are not needed.
Also, should we just return early if we are not inside a worktree?
Quoted 12 lines
builtin/repo.c +12
-0+ } + +while (pfx) { + pfx =strchr (pfx,'/' ); +if (pfx) { + pfx++; +strbuf_addstr (buf,"../" ); + } + } +return 0 ; +} +
[snip]
t/t1900-repo-info.sh test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ · line 244
Quoted 4 lines
t/t1900-repo-info.sh +4
-0+test_expect_success 'path.cdup cwd outside the working tree' ' + test_when_finished "rm -rf repo" && + mkdir -p repo/tmp/x && + cd repo &&
This cd isn't in a subshell, so it changes the working directory for every following test, which I don't think was intended.
t/t1900-repo-info.sh test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ · line 255
Quoted 11 lines
t/t1900-repo-info.sh +11
-0+ git init test && + ( + echo path.cdup=$(pwd)/tmp/x >./test/expect && + cd test && + GIT_WORK_TREE=../tmp/x && + export GIT_WORK_TREE && + GIT_DIR=$(pwd)/.git && + export GIT_DIR && + git repo info path.cdup >actual && + test_cmp expect actual + )
-Justin
Re: [GSoC Patch v7 8/8] repo: add path.cdup
Quoted 16 lines · Justin Tobler
On 26/09/27 05:14PM, K Jayatheerth wrote:
[snip]builtin/repo.c static int get_object_format(struct repository *repo, struct strbuf *buf) · line 90
Quoted 10 lines
builtin/repo.c +10
-0+static int get_path_cdup (struct repository *repo,struct strbuf *buf) +{ +const char *pfx = repo->prefix; + +if (!is_inside_work_tree (repo)) { +const char *worktree =repo_get_work_tree (repo); + +if (worktree) { +strbuf_addstr (buf, worktree); + }nit: The curly braces on a single line if statement are not needed.
Quoted 2 lines
Also, should we just return early if we are not inside a worktree?
We should just return early. You are right.
I will do that.
Quoted 13 lines
Quoted 12 lines
builtin/repo.c +12
-0+ } + +while (pfx) { + pfx =strchr (pfx,'/' ); +if (pfx) { + pfx++; +strbuf_addstr (buf,"../" ); + } + } +return 0 ; +} +[snip]
Quoted 8 lines
t/t1900-repo-info.sh test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ · line 244
Quoted 4 lines
t/t1900-repo-info.sh +4
-0+test_expect_success 'path.cdup cwd outside the working tree' ' + test_when_finished "rm -rf repo" && + mkdir -p repo/tmp/x && + cd repo &&This cd isn't in a subshell, so it changes the working directory for every following test, which I don't think was intended.
Oh whoops, that wasn't intended.
Yeah this clearly just cds into non test env altering common files.
Will fix it.
Quoted 12 lines
t/t1900-repo-info.sh test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ · line 255
Quoted 11 lines
t/t1900-repo-info.sh +11
-0+ git init test && + ( + echo path.cdup=$(pwd)/tmp/x >./test/expect && + cd test && + GIT_WORK_TREE=../tmp/x && + export GIT_WORK_TREE && + GIT_DIR=$(pwd)/.git && + export GIT_DIR && + git repo info path.cdup >actual && + test_cmp expect actual + )
Quoted 1 line
-Justin
Thank you for the review!
- K Jayatheerth
Re: [GSoC Patch v7 0/8] add more path keys to git repo info
In reply to K JayatheerthQuoted 14 lines · K Jayatheerth
Series adds keys to git repo info.
Keys output paths of repository components:
* path.toplevel: repository tree.
* path.superproject-root: superproject tree from submodules.
* path.hooks: repository hooks.
* path.index: repository index.
* path.grafts: repository grafts.
* path.git-prefix: prefix offset.
* path.cdup: relative path to top level from subdirectory.Keys support suffixes for format.
Commits contain documentation and tests.
Quoted 8 lines
fix a superproject bug where it now takes repo parameter instead of just depending on cwd.
changes since v6:
* The superproject bug fix is now a commit of its own.
* The dead code in index is removed, we simply rely on the helper itself and not write any new conditions.
* cdup now works even when the worktree is outside the current working directory.
This unfortunately has seen no interest and no review since it was posted for a full month.
Unless we see some volunteers to give it a final review in a few weeks, I will discard the topic out of my tree, as 'seen' has been crowded with topics that have been collecting dust without getting many reviews.
Re: [GSoC Patch v7 0/8] add more path keys to git repo info
Quoted 4 lines · Junio C Hamano
Unless we see some volunteers to give it a final review in a few weeks, I will discard the topic out of my tree, as 'seen' has been crowded with topics that have been collecting dust without getting many reviews.
I've been meaning to come back to this topic, but have gotten recently distracted with some other topics. I'll take a look at it tomorrow though.
Thanks,
-Justin
Re: [GSoC Patch v7 0/8] add more path keys to git repo info
In reply to K JayatheerthQuoted 14 lines · K Jayatheerth
Series adds keys to git repo info.
Keys output paths of repository components:
* path.toplevel: repository tree.
* path.superproject-root: superproject tree from submodules.
* path.hooks: repository hooks.
* path.index: repository index.
* path.grafts: repository grafts.
* path.git-prefix: prefix offset.
* path.cdup: relative path to top level from subdirectory.Keys support suffixes for format.
Commits contain documentation and tests.
Quoted 8 lines
fix a superproject bug where it now takes repo parameter instead of just depending on cwd.
changes since v6:
* The superproject bug fix is now a commit of its own.
* The dead code in index is removed, we simply rely on the helper itself and not write any new conditions.
* cdup now works even when the worktree is outside the current working directory.
This unfortunately has seen no interest and no review since it was posted for a full month.
Unless we see some volunteers to give it a review in a few weeks, I will discard the topic out of my tree, as 'seen' has been crowded with topics that have been collecting dust without getting many reviews.
v8 cover repo: add path keys to repo info
In reply to K JayatheerthThis patch series continues the work to expose repository paths and metadata via the git repo info command. It introduces several keys for querying repository paths in standard absolute and relative formats, as well as refactoring get_superproject_working_tree() to operate on a struct repository *.
The path keys added in this series are:
- path.toplevel.absolute / path.toplevel.relative: The root directory of the working tree (or an empty string in bare repositories).
- path.superproject-root.absolute / path.superproject-root.relative:
The root of the superproject when inside a submodule.
- path.hooks.absolute / path.hooks.relative: The repository's hooks directory (respecting core.hooksPath, including /dev/null).
- path.index.absolute / path.index.relative: The repository's active index file.
- path.git-prefix: The prefix from the worktree root to the current working directory.
- path.cdup: The relative path from the current directory up to the worktree root.
Changes since v7:
- Dropped path.grafts.
- In patch 2 (submodule: use repository to find superproject), moved the test for --git-dir to t/t1500-rev-parse.sh exercising the existing rev-parse --show-superproject-working-tree interface (since path.superproject-root is only added in patch 3), and ensured clean isolation of test directories (sub and super).
- In patch 3 (path.superproject-root), simplified the getter functions by eliminating redundant early returns.
- In patch 4 (path.hooks):
- Special-cased /dev/null in both path.hooks.absolute and path.hooks.relative to output /dev/null directly, making it easy for scripts to detect when hooks are disabled. Documented this behavior in Documentation/git-repo.adoc.
- Reverted changes to the test_repo_info_path helper in t/t1900-repo-info.sh and wrote a standalone test block for the /dev/null case.
- Set hooksPath = /dev/null directly in the config file rather than passing it through git config core.hooksPath /dev/null to prevent MSYS2 argument mangling on Windows (which rewrites /dev/null to nul), allowing the test to run portably on all platforms without requiring !MINGW.
- In patch 7 (path.cdup), removed unnecessary braces on the single-line if, added an early return when invoked outside a worktree, and ensured cd repo in the test runs within a subshell.
Thanks to Justin Tobler and Lucas Seiki Oshiro for their reviews and mentorship.
K Jayatheerth (7):
repo: add path.toplevel with absolute and relative suffix formatting
submodule: use repository to find superproject
repo: add path.superproject-root with absolute and relative suffixes
repo: add path.hooks with absolute and relative suffixes
repo: add path.index with absolute and relative suffixes
repo: add path.git-prefix
repo: add path.cdup
Documentation/git-repo.adoc | 52 ++++++++++ builtin/repo.c | 131 +++++++++++++++++++++++++ builtin/rev-parse.c | 2 +- submodule.c | 43 +++++---- submodule.h | 2 +- t/t1500-rev-parse.sh | 20 ++++ t/t1900-repo-info.sh | 185 ++++++++++++++++++++++++++++++++++++ 7 files changed, 412 insertions(+), 23 deletions(-)
Range-diff against v7:
5: 351b4b7de7 ! 1: 27b9811163 repo: add path.grafts with absolute and relative suffixes
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: add path.grafts with absolute and relative suffixes
+ repo: add path.toplevel with absolute and relative suffix formatting
- The repository grafts file specifies alternate parent relationships for
- commits and may be used by repository tooling that needs to inspect or
- manage grafts. Scripts currently retrieve its location by invoking
- `git rev-parse --git-path info/grafts`.
+ Scripts frequently need to find the root directory of a repository's
+ working tree. Currently, this requires using `git rev-parse --show-toplevel`
+ or inferring it from other repository information.
- Introduce `path.grafts.absolute` and `path.grafts.relative` keys to
- `git repo info`. This exposes the grafts file location as a scriptable
- config-like key using standard format rules, allowing scripts to
- retrieve it through the same interface as other repository path
- information.
+ Introduce `path.toplevel.absolute` and `path.toplevel.relative` keys
+ to `git repo info`. This allows scripts to retrieve the top-level
+ working tree path in a predictable, strictly formatted manner without
+ relying on `rev-parse`.
+
+ If requested in a bare repository where no working tree exists, the
+ command returns an empty string.
Mentored-by: Justin Tobler <[email protected]>
Mentored-by: Lucas Seiki Oshiro <[email protected]>
@@ Documentation/git-repo.adoc: values that they return:
`path.gitdir.relative`::
The path to the Git repository directory relative to the current working directory.
-+`path.grafts.absolute`::
-+ The canonical absolute path to the repository's graft file.
-+ Respects the `GIT_GRAFT_FILE` environment override. The path is
-+ returned regardless of whether the file currently exists on disk.
++`path.toplevel.absolute`::
++ The canonical absolute path to the top-level directory of the
++ repository's working tree. Outputs an empty string if the repository
++ is bare.
+
-+`path.grafts.relative`::
-+ The path to the repository's graft file relative to the current
-+ working directory. Respects the `GIT_GRAFT_FILE` environment
-+ override. The path is returned regardless of whether the file
-+ currently exists on disk.
++`path.toplevel.relative`::
++ The path to the top-level directory of the repository's working
++ tree relative to the current working directory. Outputs an empty
++ string if the repository is bare.
+
- `path.hooks.absolute`::
- The canonical absolute path to the repository's hooks directory.
- Respects the `core.hooksPath` configuration. If `core.hooksPath` is
+ `references.format`::
+ The reference storage format. The valid values are:
+ +
## builtin/repo.c ##
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)
return 0;
}
-+static int get_path_grafts_absolute(struct repository *repo, struct strbuf *buf)
++static int get_path_toplevel_absolute(struct repository *repo, struct strbuf *buf)
+{
-+ const char *graft_file = repo_get_graft_file(repo);
++ const char *work_tree = repo_get_work_tree(repo);
+
-+ if (!graft_file)
-+ return error(_("unable to get graft file"));
++ if (!work_tree)
++ return 0;
+
-+ format_path(buf, graft_file, "", PATH_FORMAT_CANONICAL);
++ format_path(buf, work_tree, "", PATH_FORMAT_CANONICAL);
+ return 0;
+}
+
-+static int get_path_grafts_relative(struct repository *repo, struct strbuf *buf)
++static int get_path_toplevel_relative(struct repository *repo, struct strbuf *buf)
+{
-+ const char *graft_file = repo_get_graft_file(repo);
++ const char *work_tree = repo_get_work_tree(repo);
+
-+ if (!graft_file)
-+ return error(_("unable to get graft file"));
++ if (!work_tree)
++ return 0;
+
-+ format_path(buf, graft_file, repo->prefix, PATH_FORMAT_RELATIVE);
++ format_path(buf, work_tree, repo->prefix, PATH_FORMAT_RELATIVE);
+ return 0;
+}
+
- static int get_path_hooks_absolute(struct repository *repo, struct strbuf *buf)
+ static int get_references_format(struct repository *repo, struct strbuf *buf)
{
- struct strbuf hooks_path = STRBUF_INIT;
+ strbuf_addstr(buf,
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
{ "path.commondir.relative", get_path_commondir_relative },
{ "path.gitdir.absolute", get_path_gitdir_absolute },
{ "path.gitdir.relative", get_path_gitdir_relative },
-+ { "path.grafts.absolute", get_path_grafts_absolute },
-+ { "path.grafts.relative", get_path_grafts_relative },
- { "path.hooks.absolute", get_path_hooks_absolute },
- { "path.hooks.relative", get_path_hooks_relative },
- { "path.index.absolute", get_path_index_absolute },
++ { "path.toplevel.absolute", get_path_toplevel_absolute },
++ { "path.toplevel.relative", get_path_toplevel_relative },
+ { "references.format", get_references_format },
+ };
+
## t/t1900-repo-info.sh ##
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
'.git' \
'GIT_DIR="../.git" && export GIT_DIR'
-+test_repo_info_path 'grafts standard' 'grafts' '.git/info/grafts'
++test_expect_success 'path.toplevel absolute and relative' '
++ test_when_finished "rm -rf repo" &&
++ git init repo &&
++ (
++ mkdir -p repo/sub &&
++ cd repo/sub &&
+
-+test_repo_info_path 'grafts with GIT_GRAFT_FILE override' 'grafts' \
-+ 'custom-graft-file' \
-+ 'GIT_GRAFT_FILE="$ROOT/custom-graft-file" && export GIT_GRAFT_FILE'
++ ROOT="$(test-tool path-utils real_path ..)" &&
+
- test_repo_info_path 'hooks standard' 'hooks' '.git/hooks'
-
- test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \
++ echo "path.toplevel.absolute=$ROOT" >expect.abs &&
++ git repo info path.toplevel.absolute >actual.abs &&
++ test_cmp expect.abs actual.abs &&
++
++ echo "path.toplevel.relative=../" >expect.rel &&
++ git repo info path.toplevel.relative >actual.rel &&
++ test_cmp expect.rel actual.rel
++ )
++'
++
++test_expect_success 'path.toplevel absolute and relative in a bare repository' '
++ test_when_finished "rm -rf bare.git" &&
++ git init --bare bare.git &&
++ (
++ cd bare.git &&
++
++ echo "path.toplevel.absolute=" >expect.abs &&
++ git repo info path.toplevel.absolute >actual.abs &&
++ test_cmp expect.abs actual.abs &&
++
++ echo "path.toplevel.relative=" >expect.rel &&
++ git repo info path.toplevel.relative >actual.rel &&
++ test_cmp expect.rel actual.rel
++ )
++'
++
+ test_done
1: 7c90603a1b ! 2: 2274dd8be2 submodule: use repository to find superproject
@@ submodule.h: void absorb_git_dir_into_superproject(const char *path,
#endif
- ## t/t7400-submodule-basic.sh ##
-@@ t/t7400-submodule-basic.sh: test_expect_success 'submodule add fails when name is reused' '
+ ## t/t1500-rev-parse.sh ##
+@@ t/t1500-rev-parse.sh: test_expect_success ':/ and HEAD^{/} favor more recent matching commits' '
)
'
-+test_expect_success 'path.superproject-root works with --git-dir' '
++test_expect_success '--show-superproject-working-tree works with --git-dir' '
++ rm -rf sub super &&
+ test_when_finished "rm -rf sub super" &&
+ git init sub &&
+ test_commit -C sub initial &&
@@ t/t7400-submodule-basic.sh: test_expect_success 'submodule add fails when name i
+ SUPER_ROOT="$(test-tool path-utils real_path .)" &&
+ MODULE_DIR="$SUPER_ROOT/.git/modules/sub" &&
+
-+ echo "path.superproject-root.absolute=$SUPER_ROOT" >expect &&
-+ git --git-dir="$MODULE_DIR" repo info path.superproject-root.absolute >actual &&
++ echo "$SUPER_ROOT" >expect &&
++ git --git-dir="$MODULE_DIR" rev-parse --show-superproject-working-tree >actual &&
+ test_cmp expect actual
+ )
+'
2: 1bfb0c8c1d ! 3: 34c54cdafd repo: add path.superproject-root with absolute and relative suffixes
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+{
+ struct strbuf superproject = STRBUF_INIT;
+
-+ if (!get_superproject_working_tree(repo, &superproject)) {
-+ strbuf_release(&superproject);
-+ return 0;
-+ }
++ if (get_superproject_working_tree(repo, &superproject))
++ format_path(buf, superproject.buf, "", PATH_FORMAT_CANONICAL);
+
-+ format_path(buf, superproject.buf, "", PATH_FORMAT_CANONICAL);
+ strbuf_release(&superproject);
+ return 0;
+}
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+{
+ struct strbuf superproject = STRBUF_INIT;
+
-+ if (!get_superproject_working_tree(repo, &superproject)) {
-+ strbuf_release(&superproject);
-+ return 0;
-+ }
++ if (get_superproject_working_tree(repo, &superproject))
++ format_path(buf, superproject.buf, repo->prefix, PATH_FORMAT_RELATIVE);
+
-+ format_path(buf, superproject.buf, repo->prefix, PATH_FORMAT_RELATIVE);
+ strbuf_release(&superproject);
+ return 0;
+}
3: 09d2937fcd ! 4: 985403c7b3 repo: add path.hooks with absolute and relative suffixes
@@ Documentation/git-repo.adoc: values that they return:
+
+`path.hooks.relative`::
+ The path to the repository's hooks directory relative to the current
-+ working directory. Respects the `core.hooksPath` configuration.
++ working directory. Respects the `core.hooksPath` configuration. If
++ `core.hooksPath` is set to `/dev/null`, that value is returned unchanged.
+
`path.superproject-root.absolute`::
The canonical absolute path to the working tree root of the superproject
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+ struct strbuf hooks_path = STRBUF_INIT;
+
+ repo_git_path_replace(repo, &hooks_path, "hooks");
-+ format_path(buf, hooks_path.buf, "", PATH_FORMAT_CANONICAL);
++ if (!strcmp(hooks_path.buf, "/dev/null"))
++ strbuf_addstr(buf, "/dev/null");
++ else
++ format_path(buf, hooks_path.buf, "", PATH_FORMAT_CANONICAL);
++
+ strbuf_release(&hooks_path);
+ return 0;
+}
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+ struct strbuf hooks_path = STRBUF_INIT;
+
+ repo_git_path_replace(repo, &hooks_path, "hooks");
-+ format_path(buf, hooks_path.buf, repo->prefix, PATH_FORMAT_RELATIVE);
++ if (!strcmp(hooks_path.buf, "/dev/null"))
++ strbuf_addstr(buf, "/dev/null");
++ else
++ format_path(buf, hooks_path.buf, repo->prefix, PATH_FORMAT_RELATIVE);
++
+ strbuf_release(&hooks_path);
+ return 0;
+}
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
{ "path.toplevel.absolute", get_path_toplevel_absolute },
## t/t1900-repo-info.sh ##
-@@ t/t1900-repo-info.sh: test_repo_info_path () {
- cd repo/sub &&
- ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
- eval "$init_command" &&
-- echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect &&
-+ case "$expected_dir" in
-+ /*) EXPECT_ABS="$expected_dir" ;;
-+ *) EXPECT_ABS="$ROOT/$expected_dir" ;;
-+ esac &&
-+ echo "path.$field_name.absolute=$EXPECT_ABS" >expect &&
- git repo info "path.$field_name.absolute" >actual &&
- test_cmp expect actual
- )
-@@ t/t1900-repo-info.sh: test_repo_info_path () {
- cd repo/sub &&
- ROOT="$(test-tool path-utils real_path ..)" && export ROOT &&
- eval "$init_command" &&
-- echo "path.$field_name.relative=../$expected_dir" >expect &&
-+ case "$expected_dir" in
-+ /*) EXPECT_REL="$(test-tool path-utils relative_path "$expected_dir" "$PWD")" ;;
-+ *) EXPECT_REL="../$expected_dir" ;;
-+ esac &&
-+ echo "path.$field_name.relative=$EXPECT_REL" >expect &&
- git repo info "path.$field_name.relative" >actual &&
- test_cmp expect actual
- )
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
'.git' \
'GIT_DIR="../.git" && export GIT_DIR'
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
+ 'custom-hooks' \
+ 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"'
+
-+# /dev/null is not a real, canonicalizable filesystem path on Windows,
-+# so path resolution for core.hooksPath=/dev/null cannot be expected to
-+# produce a literal "/dev/null" the way it does on POSIX systems.
-+if ! test_have_prereq MINGW
-+then
-+ test_repo_info_path 'hooks with core.hooksPath=/dev/null' 'hooks' \
-+ '/dev/null' \
-+ 'git config core.hooksPath /dev/null'
-+fi
++test_expect_success 'hooks with core.hooksPath=/dev/null' '
++ test_when_finished "rm -rf repo" &&
++ git init repo &&
++ (
++ mkdir -p repo/sub &&
++ cd repo/sub &&
++ cat >>../.git/config <<-\EOF &&
++ [core]
++ hooksPath = /dev/null
++ EOF
++ echo "path.hooks.absolute=/dev/null" >expect.abs &&
++ echo "path.hooks.relative=/dev/null" >expect.rel &&
++ git repo info path.hooks.absolute >actual.abs &&
++ git repo info path.hooks.relative >actual.rel &&
++ test_cmp expect.abs actual.abs &&
++ test_cmp expect.rel actual.rel
++ )
++'
+
test_expect_success 'path.superproject-root absolute and relative' '
test_when_finished "rm -rf sub super" &&4: d0c186f150 ! 5: 486836ae52 repo: add path.index with absolute and relative suffixes
@@ Commit message
## Documentation/git-repo.adoc ##
@@ Documentation/git-repo.adoc: values that they return:
- The path to the repository's hooks directory relative to the current
- working directory. Respects the core.hooksPath configuration.
+ working directory. Respects the core.hooksPath configuration. If
+ core.hooksPath is set to /dev/null, that value is returned unchanged.
+path.index.absolute::
+ The canonical absolute path to the repository's current index file.
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
{ "path.toplevel.absolute", get_path_toplevel_absolute },
## t/t1900-repo-info.sh ##
-@@ t/t1900-repo-info.sh: then
- 'git config core.hooksPath /dev/null'
- fi
+@@ t/t1900-repo-info.sh: test_expect_success 'hooks with core.hooksPath=/dev/null' '
+ )
+ '
+test_repo_info_path 'index standard' 'index' '.git/index'
+
6: ef69d4aa8c ! 6: 91a8dc3ab1 repo: add path.git-prefix
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
+ { "path.git-prefix", get_path_git_prefix },
{ "path.gitdir.absolute", get_path_gitdir_absolute },
{ "path.gitdir.relative", get_path_gitdir_relative },
- { "path.grafts.absolute", get_path_grafts_absolute },
+ { "path.hooks.absolute", get_path_hooks_absolute },
## t/t1900-repo-info.sh ##
@@ t/t1900-repo-info.sh: test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \
7: 3e61728dba ! 7: 84a9fb4060 repo: add path.cdup
@@ builtin/repo.c: static int get_object_format(struct repository *repo, struct str
+ if (!is_inside_work_tree(repo)) {
+ const char *worktree = repo_get_work_tree(repo);
+
-+ if (worktree) {
++ if (worktree)
+ strbuf_addstr(buf, worktree);
-+ }
++ return 0;
+ }
+
+ while (pfx) {
@@ t/t1900-repo-info.sh: test_repo_info_path 'commondir with only GIT_DIR' 'commond
+test_expect_success 'path.cdup cwd outside the working tree' '
+ test_when_finished "rm -rf repo" &&
+ mkdir -p repo/tmp/x &&
-+ cd repo &&
-+ git init test &&
+ (
-+ echo path.cdup=$(pwd)/tmp/x >./test/expect &&
++ cd repo &&
++ git init test &&
++ echo "path.cdup=$(pwd)/tmp/x" >test/expect &&
+ cd test &&
+ GIT_WORK_TREE=../tmp/x &&
+ export GIT_WORK_TREE &&Signature · 1 line
2.56.0-rc2
PATCH v8 1/7 repo: add path.toplevel with absolute and relative suffix formatting
Scripts frequently need to find the root directory of a repository's working tree. Currently, this requires using git rev-parse --show-toplevel or inferring it from other repository information.
Introduce path.toplevel.absolute and path.toplevel.relative keys to git repo info. This allows scripts to retrieve the top-level working tree path in a predictable, strictly formatted manner without relying on rev-parse.
If requested in a bare repository where no working tree exists, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.toplevel.absolute`:: + The canonical absolute path to the top-level directory of the + repository's working tree. Outputs an empty string if the repository + is bare. + +`path.toplevel.relative`:: + The path to the top-level directory of the repository's working + tree relative to the current working directory. Outputs an empty + string if the repository is bare. + `references.format`:: The reference storage format. The valid values are: +
builtin/repo.c +24 -0
@@ -121,6 +121,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) +return 0 ; + +format_path (buf, work_tree,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_toplevel_relative (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) +return 0 ; + +format_path (buf, work_tree, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_references_format (struct repository *repo,struct strbuf *buf) { strbuf_addstr(buf,
@@ -137,6 +159,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.toplevel.absolute", get_path_toplevel_absolute }, + { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format }, };
t/t1900-repo-info.sh +35 -0
@@ -213,4 +213,39 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.toplevel absolute and relative' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.toplevel.absolute=$ROOT" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=../" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.toplevel absolute and relative in a bare repository' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + + echo "path.toplevel.absolute=" >expect.abs && + git repo info path.toplevel.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.toplevel.relative=" >expect.rel && + git repo info path.toplevel.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_done
Signature · 1 line
2.56.0-rc2
PATCH v8 2/7 submodule: use repository to find superproject
In reply to K Jayatheerthget_superproject_working_tree() currently uses xgetcwd() to determine the repository whose superproject should be checked.
This is incorrect when --git-dir points to a repository different from the one associated with the current working directory. In that case, the current working directory may cause the function to return the wrong superproject or an empty result.
Pass the repository to get_superproject_working_tree() so that the superproject is determined from the repository being inspected rather than the current working directory.
--- builtin/rev-parse.c | 2 +- submodule.c | 43 ++++++++++++++++++++++--------------------- submodule.h | 2 +- t/t1500-rev-parse.sh | 20 ++++++++++++++++++++ 4 files changed, 44 insertions(+), 23 deletions(-)
builtin/rev-parse.c +1 -1
@@ -997,7 +997,7 @@ int cmd_rev_parse(int argc, }if (!strcmp (arg,"--show-superproject-working-tree" )) {struct strbuf superproject =STRBUF_INIT ; -if (get_superproject_working_tree (&superproject)) +if (get_superproject_working_tree (the_repository, &superproject))print_path (superproject.buf, prefix, format,DEFAULT_UNMODIFIED );strbuf_release (&superproject);continue ;
submodule.c +22 -21
99 lines not on this page · raw message
submodule.h +1 -1
@@ -170,6 +170,6 @@ void absorb_git_dir_into_superproject(const char *path,* project is a submodule of. If this repository is not a submodule of * another repository, return 0. */ -int get_superproject_working_tree (struct strbuf *buf); +int get_superproject_working_tree (struct repository *r,struct strbuf *buf);#endif
t/t1500-rev-parse.sh +20 -0
@@ -383,4 +383,24 @@ test_expect_success ':/ and HEAD^{/} favor more recent matching commits' ' ) ' +test_expect_success '--show-superproject-working-tree works with --git-dir' ' + rm -rf sub super && + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + SUPER_ROOT="$(test-tool path-utils real_path .)" && + MODULE_DIR="$SUPER_ROOT/.git/modules/sub" && + + echo "$SUPER_ROOT" >expect && + git --git-dir="$MODULE_DIR" rev-parse --show-superproject-working-tree >actual && + test_cmp expect actual + ) +' + test_done
Signature · 1 line
2.56.0-rc2
PATCH v8 3/7 repo: add path.superproject-root with absolute and relative suffixes
In reply to K JayatheerthScripts working in multi-repository setups often need to identify the top-level working tree of a superproject from within a submodule. Currently, this is only exposed via git rev-parse --show-superproject-working-tree.
Introduce path.superproject-root.absolute and path.superproject-root.relative keys to git repo info. This exposes the core submodule context via a scriptable config-like key using standard format rules.
If requested when not inside a submodule, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 25 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.superproject-root.absolute`:: + The canonical absolute path to the working tree root of the superproject + if the current repository is an initialized submodule. Outputs an empty + string if not in a submodule. + +`path.superproject-root.relative`:: + The path to the working tree root of the superproject relative to the + current working directory if the current repository is an initialized + submodule. Outputs an empty string if not in a submodule. + `path.toplevel.absolute`:: The canonical absolute path to the top-level directory of the repository's working tree. Outputs an empty string if the repository
builtin/repo.c +25 -0
@@ -18,6 +18,7 @@#include "strbuf.h" #include "string-list.h" #include "shallow.h" +#include "submodule.h" #include "tree.h" #include "tree-walk.h" #include "utf8.h"
@@ -121,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_superproject_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (get_superproject_working_tree (repo, &superproject)) +format_path (buf, superproject.buf,"" ,PATH_FORMAT_CANONICAL ); + +strbuf_release (&superproject); +return 0 ; +} + +static int get_path_superproject_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (get_superproject_working_tree (repo, &superproject)) +format_path (buf, superproject.buf, repo->prefix,PATH_FORMAT_RELATIVE ); + +strbuf_release (&superproject); +return 0 ; +} +static int get_path_toplevel_absolute (struct repository *repo,struct strbuf *buf) {const char *work_tree =repo_get_work_tree (repo);
@@ -159,6 +182,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.superproject-root.absolute", get_path_superproject_absolute }, + { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute }, { "path.toplevel.relative", get_path_toplevel_relative }, { "references.format", get_references_format },
t/t1900-repo-info.sh +39 -0
@@ -213,6 +213,45 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.superproject-root absolute and relative' ' + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + cd sub && + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.superproject-root.absolute=$ROOT" >expect.abs && + git repo info path.superproject-root.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superproject-root.relative=../" >expect.rel && + git repo info path.superproject-root.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.superproject-root returns empty when not in a submodule' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + echo "path.superproject-root.absolute=" >expect.abs && + git repo info path.superproject-root.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superproject-root.relative=" >expect.rel && + git repo info path.superproject-root.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_expect_success 'path.toplevel absolute and relative' ' test_when_finished "rm -rf repo" && git init repo &&
Signature · 1 line
2.56.0-rc2
PATCH v8 4/7 repo: add path.hooks with absolute and relative suffixes
In reply to K JayatheerthHooks are an integral part of a repository's configuration and are commonly used by tooling to automate repository-specific workflows. Currently, scripts typically retrieve the hooks directory by invoking git rev-parse --git-path hooks.
Introduce path.hooks.absolute and path.hooks.relative keys to git repo info. This exposes the hooks directory as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 30 ++++++++++++++++++++++++++++++ t/t1900-repo-info.sh | 25 +++++++++++++++++++++++++ 3 files changed, 65 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.hooks.absolute`:: + The canonical absolute path to the repository's hooks directory. + Respects the `core.hooksPath` configuration. If `core.hooksPath` is + set to `/dev/null`, that value is returned unchanged. + +`path.hooks.relative`:: + The path to the repository's hooks directory relative to the current + working directory. Respects the `core.hooksPath` configuration. If + `core.hooksPath` is set to `/dev/null`, that value is returned unchanged. + `path.superproject-root.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +30 -0
@@ -122,6 +122,34 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_hooks_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +if (!strcmp (hooks_path.buf,"/dev/null" )) +strbuf_addstr (buf,"/dev/null" ); +else +format_path (buf, hooks_path.buf,"" ,PATH_FORMAT_CANONICAL ); + +strbuf_release (&hooks_path); +return 0 ; +} + +static int get_path_hooks_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf hooks_path =STRBUF_INIT ; + +repo_git_path_replace (repo, &hooks_path,"hooks" ); +if (!strcmp (hooks_path.buf,"/dev/null" )) +strbuf_addstr (buf,"/dev/null" ); +else +format_path (buf, hooks_path.buf, repo->prefix,PATH_FORMAT_RELATIVE ); + +strbuf_release (&hooks_path); +return 0 ; +} +static int get_path_superproject_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -182,6 +210,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.hooks.absolute", get_path_hooks_absolute }, + { "path.hooks.relative", get_path_hooks_relative }, { "path.superproject-root.absolute", get_path_superproject_absolute }, { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +25 -0
@@ -213,6 +213,31 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_repo_info_path 'hooks standard' 'hooks' '.git/hooks' + +test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ + 'custom-hooks' \ + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' + +test_expect_success 'hooks with core.hooksPath=/dev/null' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + cat >>../.git/config <<-\EOF && + [core] + hooksPath = /dev/null + EOF + echo "path.hooks.absolute=/dev/null" >expect.abs && + echo "path.hooks.relative=/dev/null" >expect.rel && + git repo info path.hooks.absolute >actual.abs && + git repo info path.hooks.relative >actual.rel && + test_cmp expect.abs actual.abs && + test_cmp expect.rel actual.rel + ) +' + test_expect_success 'path.superproject-root absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.56.0-rc2
PATCH v8 5/7 repo: add path.index with absolute and relative suffixes
In reply to K JayatheerthThe repository index is a fundamental component used by Git and related tooling to track the working tree state. Scripts that interact with the index currently retrieve its location by invokinggit rev-parse --git-path index.
Introduce path.index.absolute and path.index.relative keys to git repo info. This exposes the index file location as a scriptable config-like key using standard format rules, allowing scripts to retrieve it through the same interface as other repository path information.
--- Documentation/git-repo.adoc | 12 ++++++++++++ builtin/repo.c | 18 ++++++++++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 53 insertions(+)
Documentation/git-repo.adoc +12 -0
@@ -129,6 +129,18 @@ values that they return: working directory. Respects the `core.hooksPath` configuration. If `core.hooksPath` is set to `/dev/null`, that value is returned unchanged. +`path.index.absolute`:: + The canonical absolute path to the repository's current index file. + Respects the `GIT_INDEX_FILE` environment override. Returns the + configured index path even if the repository is bare or the file does + not exist. + +`path.index.relative`:: + The path to the repository's current index file relative to the current + working directory. Respects the `GIT_INDEX_FILE` environment override. + Returns the configured index path even if the repository is bare or the + file does not exist. + `path.superproject-root.absolute`:: The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
builtin/repo.c +18 -0
@@ -150,6 +150,22 @@ static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_index_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +format_path (buf, index_file,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_index_relative (struct repository *repo,struct strbuf *buf) +{ +const char *index_file =repo_get_index_file (repo); + +format_path (buf, index_file, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_path_superproject_absolute (struct repository *repo,struct strbuf *buf) {struct strbuf superproject =STRBUF_INIT ;
@@ -212,6 +228,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.gitdir.relative", get_path_gitdir_relative }, { "path.hooks.absolute", get_path_hooks_absolute }, { "path.hooks.relative", get_path_hooks_relative }, + { "path.index.absolute", get_path_index_absolute }, + { "path.index.relative", get_path_index_relative }, { "path.superproject-root.absolute", get_path_superproject_absolute }, { "path.superproject-root.relative", get_path_superproject_relative }, { "path.toplevel.absolute", get_path_toplevel_absolute },
t/t1900-repo-info.sh +23 -0
@@ -238,6 +238,29 @@ test_expect_success 'hooks with core.hooksPath=/dev/null' ' ) ' +test_repo_info_path 'index standard' 'index' '.git/index' + +test_repo_info_path 'index with GIT_INDEX_FILE override' 'index' \ + 'custom-index-file' \ + 'GIT_INDEX_FILE="$ROOT/custom-index-file" && export GIT_INDEX_FILE' + +test_expect_success 'path.index in a bare repository returns default index location' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + ROOT="$(test-tool path-utils real_path .)" && + + echo "path.index.absolute=$ROOT/index" >expect.abs && + git repo info path.index.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.index.relative=index" >expect.rel && + git repo info path.index.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_expect_success 'path.superproject-root absolute and relative' ' test_when_finished "rm -rf sub super" && git init sub &&
Signature · 1 line
2.56.0-rc2
PATCH v8 6/7 repo: add path.git-prefix
In reply to K JayatheerthScripts sometimes need the path from the repository's working tree root to the current working directory. While this information can be derived through existing Git commands, git repo info does not currently expose it as a scriptable key.
Introduce the path.git-prefix key to git repo info. The key returns the path from the working tree root to the current working directory, returning the empty string when invoked from the working tree root.
--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 11 +++++++++++ t/t1900-repo-info.sh | 23 +++++++++++++++++++++++ 3 files changed, 39 insertions(+)
Documentation/git-repo.adoc +5 -0
@@ -113,6 +113,11 @@ values that they return: The path to the Git repository's common directory relative to the current working directory. +`path.git-prefix`:: + The path from the root of the working tree to the current working + directory. Returns the empty string when the current working directory + is the root of the working tree. + `path.gitdir.absolute`:: The canonical absolute path to the Git repository directory (the `.git` directory).
builtin/repo.c +11 -0
@@ -100,6 +100,16 @@ static int get_path_commondir_relative(struct repository *repo, struct strbuf *breturn 0 ; } +static int get_path_git_prefix (struct repository *repo,struct strbuf *buf) +{ +/* +* repo->prefix is NULL when the current working directory is +* the worktree root. +*/ +strbuf_addstr (buf, repo->prefix ? repo->prefix :"" ); +return 0 ; +} +static int get_path_gitdir_absolute (struct repository *repo,struct strbuf *buf) {const char *git_dir =repo_get_git_dir (repo);
@@ -224,6 +234,7 @@ static const struct repo_info_field repo_info_field[] = { { "object.format", get_object_format }, { "path.commondir.absolute", get_path_commondir_absolute }, { "path.commondir.relative", get_path_commondir_relative }, + { "path.git-prefix", get_path_git_prefix }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, { "path.hooks.absolute", get_path_hooks_absolute },
t/t1900-repo-info.sh +23 -0
@@ -207,6 +207,29 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.git-prefix at repository root' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.git-prefix=" >expect && + git repo info path.git-prefix >actual && + test_cmp expect actual + ) +' + +test_expect_success 'path.git-prefix in subdirectory' ' + test_when_finished "rm -rf repo" && + git init repo && + mkdir -p repo/sub/dir && + ( + cd repo/sub/dir && + echo "path.git-prefix=sub/dir/" >expect && + git repo info path.git-prefix >actual && + test_cmp expect actual + ) +' + test_repo_info_path 'gitdir standard' 'gitdir' '.git' test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
Signature · 1 line
2.56.0-rc2
PATCH v8 7/7 repo: add path.cdup
In reply to K JayatheerthScripts sometimes need the relative path from the current working directory to the repository's working tree root (cdup). While this information can be retrieved through git rev-parse --show-cdup, git repo info does not currently expose it as a scriptable key.
Introduce the path.cdup key to git repo info. The key returns the path from the current working directory to the root of the working tree, returning the empty string when invoked from the working tree root.
--- Documentation/git-repo.adoc | 5 +++++ builtin/repo.c | 23 +++++++++++++++++++++ t/t1900-repo-info.sh | 40 +++++++++++++++++++++++++++++++++++++ 3 files changed, 68 insertions(+)
Documentation/git-repo.adoc +5 -0
@@ -104,6 +104,11 @@ values that they return: `object.format`:: The object format (hash algorithm) used in the repository. +`path.cdup`:: + When the command is invoked from a subdirectory, show the + path of the top-level directory relative to the current + directory (typically a sequence of "../", or an empty string). + `path.commondir.absolute`:: The canonical absolute path to the Git repository's common directory (the shared `.git` directory containing objects,
builtin/repo.c +23 -0
@@ -78,6 +78,28 @@ static int get_object_format(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_cdup (struct repository *repo,struct strbuf *buf) +{ +const char *pfx = repo->prefix; + +if (!is_inside_work_tree (repo)) { +const char *worktree =repo_get_work_tree (repo); + +if (worktree) +strbuf_addstr (buf, worktree); +return 0 ; + } + +while (pfx) { + pfx =strchr (pfx,'/' ); +if (pfx) { + pfx++; +strbuf_addstr (buf,"../" ); + } + } +return 0 ; +} +static int get_path_commondir_absolute (struct repository *repo,struct strbuf *buf) {const char *common_dir =repo_get_common_dir (repo);
@@ -232,6 +254,7 @@ static const struct repo_info_field repo_info_field[] = { { "layout.bare", get_layout_bare }, { "layout.shallow", get_layout_shallow }, { "object.format", get_object_format }, + { "path.cdup", get_path_cdup }, { "path.commondir.absolute", get_path_commondir_absolute }, { "path.commondir.relative", get_path_commondir_relative }, { "path.git-prefix", get_path_git_prefix },
t/t1900-repo-info.sh +40 -0
@@ -207,6 +207,46 @@ test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.cdup at repository root' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + echo "path.cdup=" >expect && + git repo info path.cdup >actual && + test_cmp expect actual + ) +' + +test_expect_success 'path.cdup in subdirectory' ' + test_when_finished "rm -rf repo" && + git init repo && + mkdir -p repo/sub/dir && + ( + cd repo/sub/dir && + echo "path.cdup=../../" >expect && + git repo info path.cdup >actual && + test_cmp expect actual + ) +' + +test_expect_success 'path.cdup cwd outside the working tree' ' + test_when_finished "rm -rf repo" && + mkdir -p repo/tmp/x && + ( + cd repo && + git init test && + echo "path.cdup=$(pwd)/tmp/x" >test/expect && + cd test && + GIT_WORK_TREE=../tmp/x && + export GIT_WORK_TREE && + GIT_DIR=$(pwd)/.git && + export GIT_DIR && + git repo info path.cdup >actual && + test_cmp expect actual + ) +' + test_expect_success 'path.git-prefix at repository root' ' test_when_finished "rm -rf repo" && git init repo &&
Signature · 1 line
2.56.0-rc2
Re: [GSoC Patch v8 0/7] repo: add path keys to repo info
In reply to K JayatheerthOn 07/11/2026 16:00, K Jayatheerth wrote:
I'm a bit late to the party, I like the idea of adding some more paths to "git repo", but I have a few comments about the design of this series.
Quoted 9 lines
This patch series continues the work to expose repository paths and metadata via the
git repo infocommand. It introduces several keys for querying repository paths in standard absolute and relative formats, as well as refactoringget_superproject_working_tree()to operate on astruct repository *.The path keys added in this series are:
-path.toplevel.absolute/path.toplevel.relative: The root directory of the working tree (or an empty string in bare repositories).
In our documentation and glossary, we call this directory the "working tree" so I think "path.working-tree.*" would be a better name, rather than copying the name from the equivalent rev-parse option.
Quoted 2 lines
-
path.superproject-root.absolute/path.superproject-root.relative:
The root of the superproject when inside a submodule.
Personally, I'd prefer "path.superproject-working-tree.*" here, though I see Justin thought that was a bit of a mouthful. As this command is for use in scripts I'd rather have a descriptive name.
Quoted 2 lines
-
path.hooks.absolute/path.hooks.relative: The repository's hooks directory (respectingcore.hooksPath, including/dev/null).
Given we have config based hooks now, do we really want to add this? Scripts that want to run hooks should be using "git hook run" and scripts that want to install hooks should be using the config based hooks so that they co-exist with the user's existing hooks.
Quoted 4 lines
-
path.index.absolute/path.index.relative: The repository's active index file.
-path.git-prefix: The prefix from the worktree root to the current working directory.
The "git-" prefix seems a bit odd to me, maybe "path.prefix" would be a better name for an option that returns the prefix to add to paths?
Quoted 2 lines
-
path.cdup: The relative path from the current directory up to the worktree root.
How does this differ from path.working-tree.relative? I've never really understood "git rev-parse --cdup" - if you're in the repository root directory, 'cd "$(git rev-parse --cdup)"' dumps you in your home directory which has always seemed a bit surprising to me.
One note on the tests - our test suite is quite slow, so it would be good to avoid initializing new repositories for each test where we are checking these paths.
Thanks
Phillip
Quoted 440 lines
Changes since v7:
- Droppedpath.grafts.
- In patch 2 (submodule: use repository to find superproject), moved the test for--git-dirtot/t1500-rev-parse.shexercising the existingrev-parse --show-superproject-working-treeinterface (sincepath.superproject-rootis only added in patch 3), and ensured clean isolation of test directories (subandsuper).
- In patch 3 (path.superproject-root), simplified the getter functions by eliminating redundant early returns.
- In patch 4 (path.hooks):
- Special-cased/dev/nullin bothpath.hooks.absoluteandpath.hooks.relativeto output/dev/nulldirectly, making it easy for scripts to detect when hooks are disabled. Documented this behavior inDocumentation/git-repo.adoc.
- Reverted changes to thetest_repo_info_pathhelper int/t1900-repo-info.shand wrote a standalone test block for the/dev/nullcase.
- SethooksPath = /dev/nulldirectly in the config file rather than passing it throughgit config core.hooksPath /dev/nullto prevent MSYS2 argument mangling on Windows (which rewrites/dev/nulltonul), allowing the test to run portably on all platforms without requiring!MINGW.
- In patch 7 (path.cdup), removed unnecessary braces on the single-lineif, added an early return when invoked outside a worktree, and ensuredcd repoin the test runs within a subshell.Thanks to Justin Tobler and Lucas Seiki Oshiro for their reviews and mentorship.
K Jayatheerth (7):
repo: add path.toplevel with absolute and relative suffix formatting
submodule: use repository to find superproject
repo: add path.superproject-root with absolute and relative suffixes
repo: add path.hooks with absolute and relative suffixes
repo: add path.index with absolute and relative suffixes
repo: add path.git-prefix
repo: add path.cdupDocumentation/git-repo.adoc | 52 ++++++++++ builtin/repo.c | 131 +++++++++++++++++++++++++ builtin/rev-parse.c | 2 +- submodule.c | 43 +++++---- submodule.h | 2 +- t/t1500-rev-parse.sh | 20 ++++ t/t1900-repo-info.sh | 185 ++++++++++++++++++++++++++++++++++++ 7 files changed, 412 insertions(+), 23 deletions(-)Range-diff against v7:
5:351b4b7de7! 1:27b9811163repo: add path.grafts with absolute and relative suffixes@@ Metadata Author: K Jayatheerth <[email protected]> ## Commit message ## - repo: add path.grafts with absolute and relative suffixes + repo: add path.toplevel with absolute and relative suffix formatting - The repository grafts file specifies alternate parent relationships for - commits and may be used by repository tooling that needs to inspect or - manage grafts. Scripts currently retrieve its location by invoking - `git rev-parse --git-path info/grafts`. + Scripts frequently need to find the root directory of a repository's + working tree. Currently, this requires using `git rev-parse --show-toplevel` + or inferring it from other repository information. - Introduce `path.grafts.absolute` and `path.grafts.relative` keys to - `git repo info`. This exposes the grafts file location as a scriptable - config-like key using standard format rules, allowing scripts to - retrieve it through the same interface as other repository path - information. + Introduce `path.toplevel.absolute` and `path.toplevel.relative` keys + to `git repo info`. This allows scripts to retrieve the top-level + working tree path in a predictable, strictly formatted manner without + relying on `rev-parse`. + + If requested in a bare repository where no working tree exists, the + command returns an empty string. Mentored-by: Justin Tobler <[email protected]> Mentored-by: Lucas Seiki Oshiro <[email protected]> @@ Documentation/git-repo.adoc: values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. -+`path.grafts.absolute`:: -+ The canonical absolute path to the repository's graft file. -+ Respects the `GIT_GRAFT_FILE` environment override. The path is -+ returned regardless of whether the file currently exists on disk. ++`path.toplevel.absolute`:: ++ The canonical absolute path to the top-level directory of the ++ repository's working tree. Outputs an empty string if the repository ++ is bare. + -+`path.grafts.relative`:: -+ The path to the repository's graft file relative to the current -+ working directory. Respects the `GIT_GRAFT_FILE` environment -+ override. The path is returned regardless of whether the file -+ currently exists on disk. ++`path.toplevel.relative`:: ++ The path to the top-level directory of the repository's working ++ tree relative to the current working directory. Outputs an empty ++ string if the repository is bare. + - `path.hooks.absolute`:: - The canonical absolute path to the repository's hooks directory. - Respects the `core.hooksPath` configuration. If `core.hooksPath` is + `references.format`:: + The reference storage format. The valid values are: + + ## builtin/repo.c ## @@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf) return 0; } -+static int get_path_grafts_absolute(struct repository *repo, struct strbuf *buf) ++static int get_path_toplevel_absolute(struct repository *repo, struct strbuf *buf) +{ -+ const char *graft_file = repo_get_graft_file(repo); ++ const char *work_tree = repo_get_work_tree(repo); + -+ if (!graft_file) -+ return error(_("unable to get graft file")); ++ if (!work_tree) ++ return 0; + -+ format_path(buf, graft_file, "", PATH_FORMAT_CANONICAL); ++ format_path(buf, work_tree, "", PATH_FORMAT_CANONICAL); + return 0; +} + -+static int get_path_grafts_relative(struct repository *repo, struct strbuf *buf) ++static int get_path_toplevel_relative(struct repository *repo, struct strbuf *buf) +{ -+ const char *graft_file = repo_get_graft_file(repo); ++ const char *work_tree = repo_get_work_tree(repo); + -+ if (!graft_file) -+ return error(_("unable to get graft file")); ++ if (!work_tree) ++ return 0; + -+ format_path(buf, graft_file, repo->prefix, PATH_FORMAT_RELATIVE); ++ format_path(buf, work_tree, repo->prefix, PATH_FORMAT_RELATIVE); + return 0; +} + - static int get_path_hooks_absolute(struct repository *repo, struct strbuf *buf) + static int get_references_format(struct repository *repo, struct strbuf *buf) { - struct strbuf hooks_path = STRBUF_INIT; + strbuf_addstr(buf, @@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, -+ { "path.grafts.absolute", get_path_grafts_absolute }, -+ { "path.grafts.relative", get_path_grafts_relative }, - { "path.hooks.absolute", get_path_hooks_absolute }, - { "path.hooks.relative", get_path_hooks_relative }, - { "path.index.absolute", get_path_index_absolute }, ++ { "path.toplevel.absolute", get_path_toplevel_absolute }, ++ { "path.toplevel.relative", get_path_toplevel_relative }, + { "references.format", get_references_format }, + }; + ## t/t1900-repo-info.sh ## @@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' -+test_repo_info_path 'grafts standard' 'grafts' '.git/info/grafts' ++test_expect_success 'path.toplevel absolute and relative' ' ++ test_when_finished "rm -rf repo" && ++ git init repo && ++ ( ++ mkdir -p repo/sub && ++ cd repo/sub && + -+test_repo_info_path 'grafts with GIT_GRAFT_FILE override' 'grafts' \ -+ 'custom-graft-file' \ -+ 'GIT_GRAFT_FILE="$ROOT/custom-graft-file" && export GIT_GRAFT_FILE' ++ ROOT="$(test-tool path-utils real_path ..)" && + - test_repo_info_path 'hooks standard' 'hooks' '.git/hooks' - - test_repo_info_path 'hooks with core.hooksPath override' 'hooks' \ ++ echo "path.toplevel.absolute=$ROOT" >expect.abs && ++ git repo info path.toplevel.absolute >actual.abs && ++ test_cmp expect.abs actual.abs && ++ ++ echo "path.toplevel.relative=../" >expect.rel && ++ git repo info path.toplevel.relative >actual.rel && ++ test_cmp expect.rel actual.rel ++ ) ++' ++ ++test_expect_success 'path.toplevel absolute and relative in a bare repository' ' ++ test_when_finished "rm -rf bare.git" && ++ git init --bare bare.git && ++ ( ++ cd bare.git && ++ ++ echo "path.toplevel.absolute=" >expect.abs && ++ git repo info path.toplevel.absolute >actual.abs && ++ test_cmp expect.abs actual.abs && ++ ++ echo "path.toplevel.relative=" >expect.rel && ++ git repo info path.toplevel.relative >actual.rel && ++ test_cmp expect.rel actual.rel ++ ) ++' ++ + test_done 1: 7c90603a1b ! 2: 2274dd8be2 submodule: use repository to find superproject @@ submodule.h: void absorb_git_dir_into_superproject(const char *path, #endif - ## t/t7400-submodule-basic.sh ## -@@ t/t7400-submodule-basic.sh: test_expect_success 'submodule add fails when name is reused' ' + ## t/t1500-rev-parse.sh ## +@@ t/t1500-rev-parse.sh: test_expect_success ':/ and HEAD^{/} favor more recent matching commits' ' ) ' -+test_expect_success 'path.superproject-root works with --git-dir' ' ++test_expect_success '--show-superproject-working-tree works with --git-dir' ' ++ rm -rf sub super && + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && @@ t/t7400-submodule-basic.sh: test_expect_success 'submodule add fails when name i + SUPER_ROOT="$(test-tool path-utils real_path .)" && + MODULE_DIR="$SUPER_ROOT/.git/modules/sub" && + -+ echo "path.superproject-root.absolute=$SUPER_ROOT" >expect && -+ git --git-dir="$MODULE_DIR" repo info path.superproject-root.absolute >actual && ++ echo "$SUPER_ROOT" >expect && ++ git --git-dir="$MODULE_DIR" rev-parse --show-superproject-working-tree >actual && + test_cmp expect actual + ) +' 2: 1bfb0c8c1d ! 3: 34c54cdafd repo: add path.superproject-root with absolute and relative suffixes @@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str +{ + struct strbuf superproject = STRBUF_INIT; + -+ if (!get_superproject_working_tree(repo, &superproject)) { -+ strbuf_release(&superproject); -+ return 0; -+ } ++ if (get_superproject_working_tree(repo, &superproject)) ++ format_path(buf, superproject.buf, "", PATH_FORMAT_CANONICAL); + -+ format_path(buf, superproject.buf, "", PATH_FORMAT_CANONICAL); + strbuf_release(&superproject); + return 0; +} @@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str +{ + struct strbuf superproject = STRBUF_INIT; + -+ if (!get_superproject_working_tree(repo, &superproject)) { -+ strbuf_release(&superproject); -+ return 0; -+ } ++ if (get_superproject_working_tree(repo, &superproject)) ++ format_path(buf, superproject.buf, repo->prefix, PATH_FORMAT_RELATIVE); + -+ format_path(buf, superproject.buf, repo->prefix, PATH_FORMAT_RELATIVE); + strbuf_release(&superproject); + return 0; +} 3: 09d2937fcd ! 4: 985403c7b3 repo: add path.hooks with absolute and relative suffixes @@ Documentation/git-repo.adoc: values that they return: + +`path.hooks.relative`:: + The path to the repository's hooks directory relative to the current -+ working directory. Respects the `core.hooksPath` configuration. ++ working directory. Respects the `core.hooksPath` configuration. If ++ `core.hooksPath` is set to `/dev/null`, that value is returned unchanged. + `path.superproject-root.absolute`:: The canonical absolute path to the working tree root of the superproject @@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str + struct strbuf hooks_path = STRBUF_INIT; + + repo_git_path_replace(repo, &hooks_path, "hooks"); -+ format_path(buf, hooks_path.buf, "", PATH_FORMAT_CANONICAL); ++ if (!strcmp(hooks_path.buf, "/dev/null")) ++ strbuf_addstr(buf, "/dev/null"); ++ else ++ format_path(buf, hooks_path.buf, "", PATH_FORMAT_CANONICAL); ++ + strbuf_release(&hooks_path); + return 0; +} @@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str + struct strbuf hooks_path = STRBUF_INIT; + + repo_git_path_replace(repo, &hooks_path, "hooks"); -+ format_path(buf, hooks_path.buf, repo->prefix, PATH_FORMAT_RELATIVE); ++ if (!strcmp(hooks_path.buf, "/dev/null")) ++ strbuf_addstr(buf, "/dev/null"); ++ else ++ format_path(buf, hooks_path.buf, repo->prefix, PATH_FORMAT_RELATIVE); ++ + strbuf_release(&hooks_path); + return 0; +} @@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = { { "path.toplevel.absolute", get_path_toplevel_absolute }, ## t/t1900-repo-info.sh ## -@@ t/t1900-repo-info.sh: test_repo_info_path () { - cd repo/sub && - ROOT="$(test-tool path-utils real_path ..)" && export ROOT && - eval "$init_command" && -- echo "path.$field_name.absolute=$ROOT/$expected_dir" >expect && -+ case "$expected_dir" in -+ /*) EXPECT_ABS="$expected_dir" ;; -+ *) EXPECT_ABS="$ROOT/$expected_dir" ;; -+ esac && -+ echo "path.$field_name.absolute=$EXPECT_ABS" >expect && - git repo info "path.$field_name.absolute" >actual && - test_cmp expect actual - ) -@@ t/t1900-repo-info.sh: test_repo_info_path () { - cd repo/sub && - ROOT="$(test-tool path-utils real_path ..)" && export ROOT && - eval "$init_command" && -- echo "path.$field_name.relative=../$expected_dir" >expect && -+ case "$expected_dir" in -+ /*) EXPECT_REL="$(test-tool path-utils relative_path "$expected_dir" "$PWD")" ;; -+ *) EXPECT_REL="../$expected_dir" ;; -+ esac && -+ echo "path.$field_name.relative=$EXPECT_REL" >expect && - git repo info "path.$field_name.relative" >actual && - test_cmp expect actual - ) @@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' @@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir + 'custom-hooks' \ + 'git config core.hooksPath "$ROOT/custom-hooks" && mkdir -p "$ROOT/custom-hooks"' + -+# /dev/null is not a real, canonicalizable filesystem path on Windows, -+# so path resolution for core.hooksPath=/dev/null cannot be expected to -+# produce a literal "/dev/null" the way it does on POSIX systems. -+if ! test_have_prereq MINGW -+then -+ test_repo_info_path 'hooks with core.hooksPath=/dev/null' 'hooks' \ -+ '/dev/null' \ -+ 'git config core.hooksPath /dev/null' -+fi ++test_expect_success 'hooks with core.hooksPath=/dev/null' ' ++ test_when_finished "rm -rf repo" && ++ git init repo && ++ ( ++ mkdir -p repo/sub && ++ cd repo/sub && ++ cat >>../.git/config <<-\EOF && ++ [core] ++ hooksPath = /dev/null ++ EOF ++ echo "path.hooks.absolute=/dev/null" >expect.abs && ++ echo "path.hooks.relative=/dev/null" >expect.rel && ++ git repo info path.hooks.absolute >actual.abs && ++ git repo info path.hooks.relative >actual.rel && ++ test_cmp expect.abs actual.abs && ++ test_cmp expect.rel actual.rel ++ ) ++' + test_expect_success 'path.superproject-root absolute and relative' ' test_when_finished "rm -rf sub super" &&4:
d0c186f150! 5:486836ae52repo: add path.index with absolute and relative suffixes
@@ Commit message##
Documentation/git-repo.adoc##
@@Documentation/git-repo.adoc: values that they return:
- The path to the repository's hooks directory relative to the current
- working directory. Respects thecore.hooksPathconfiguration.
+ working directory. Respects thecore.hooksPathconfiguration. If
+core.hooksPathis set to/dev/null, that value is returned unchanged.+
path.index.absolute::
+ The canonical absolute path to the repository's current index file.
@@builtin/repo.c: static const structrepo_info_fieldrepo_info_field[] = {
{ "path.toplevel.absolute",get_path_toplevel_absolute},##
t/t1900-repo-info.sh##
-@@t/t1900-repo-info.sh: then
- 'git config core.hooksPath/dev/null'
- fi
+@@t/t1900-repo-info.sh:test_expect_success'hooks with core.hooksPath=/dev/null' '
+ )
+ '+test_repo_info_path 'index standard' 'index' '.git/index'
+
6:ef69d4aa8c! 6:91a8dc3ab1repo: add path.git-prefix
@@builtin/repo.c: static const structrepo_info_fieldrepo_info_field[] = {
+ { "path.git-prefix",get_path_git_prefix},
{ "path.gitdir.absolute",get_path_gitdir_absolute},
{ "path.gitdir.relative",get_path_gitdir_relative},
- { "path.grafts.absolute",get_path_grafts_absolute},
+ { "path.hooks.absolute",get_path_hooks_absolute},##
t/t1900-repo-info.sh##
@@t/t1900-repo-info.sh:test_repo_info_path'commondir with onlyGIT_DIR' 'commondir' \
7:3e61728dba! 7:84a9fb4060repo: add path.cdup@@ builtin/repo.c: static int get_object_format(struct repository *repo, struct str + if (!is_inside_work_tree(repo)) { + const char *worktree = repo_get_work_tree(repo); + -+ if (worktree) { ++ if (worktree) + strbuf_addstr(buf, worktree); -+ } ++ return 0; + } + + while (pfx) { @@ t/t1900-repo-info.sh: test_repo_info_path 'commondir with only GIT_DIR' 'commond +test_expect_success 'path.cdup cwd outside the working tree' ' + test_when_finished "rm -rf repo" && + mkdir -p repo/tmp/x && -+ cd repo && -+ git init test && + ( -+ echo path.cdup=$(pwd)/tmp/x >./test/expect && ++ cd repo && ++ git init test && ++ echo "path.cdup=$(pwd)/tmp/x" >test/expect && + cd test && + GIT_WORK_TREE=../tmp/x && + export GIT_WORK_TREE &&
Re: [GSoC Patch v8 0/7] repo: add path keys to repo info
Hey Phillip,
Quoted 20 lines · Phillip Wood
On 07/11/2026 16:00, K Jayatheerth wrote:
I'm a bit late to the party, I like the idea of adding some more paths to "git repo", but I have a few comments about the design of this series.
Quoted 9 lines
This patch series continues the work to expose repository paths and metadata via the
git repo infocommand. It introduces several keys for querying repository paths in standard absolute and relative formats, as well as refactoringget_superproject_working_tree()to operate on astruct repository *.The path keys added in this series are:
-path.toplevel.absolute/path.toplevel.relative: The root directory of the working tree (or an empty string in bare repositories).In our documentation and glossary, we call this directory the "working tree" so I think "path.working-tree.*" would be a better name, rather than copying the name from the equivalent rev-parse option.
Quoted 7 lines
Quoted 2 lines
-
path.superproject-root.absolute/path.superproject-root.relative:
The root of the superproject when inside a submodule.Personally, I'd prefer "path.superproject-working-tree.*" here, though I see Justin thought that was a bit of a mouthful. As this command is for use in scripts I'd rather have a descriptive name.
I don't have an opinion on the name itself, but, that said:
I think superproject-working-tree is a more suiting name. It is becuase you may have a working tree in a different place and it might not be the root itself.
I think the same logic applies for toplevel too.
Any more thoughts from Justin, Lucas, Junio or any other reviewer would be better I reckon.
Quoted 8 lines
Quoted 2 lines
-
path.hooks.absolute/path.hooks.relative: The repository's hooks directory (respectingcore.hooksPath, including/dev/null).Given we have config based hooks now, do we really want to add this? Scripts that want to run hooks should be using "git hook run" and scripts that want to install hooks should be using the config based hooks so that they co-exist with the user's existing hooks.
I believe that is a fair point for new tooling, though wouldn't many existing scripts
and third-party tools still learn about hooks directly via git rev-parse --git-path hooks?
Since the main goal of git repo info is to provide an alternative to rev-parse's various path flags, path.hooks still seems useful for scripts migrating over, unless the consensus is to deprecate querying the hooks directory altogether.
Quoted 8 lines
Quoted 4 lines
-
path.index.absolute/path.index.relative: The repository's active index file.
-path.git-prefix: The prefix from the worktree root to the current working directory.The "git-" prefix seems a bit odd to me, maybe "path.prefix" would be a better name for an option that returns the prefix to add to paths?
Agreed, I would change this in the next patch series.
Quoted 8 lines
Quoted 2 lines
-
path.cdup: The relative path from the current directory up to the worktree root.How does this differ from path.working-tree.relative? I've never really understood "git rev-parse --cdup" - if you're in the repository root directory, 'cd "$(git rev-parse --cdup)"' dumps you in your home directory which has always seemed a bit surprising to me.
Well looking at the code itself
What I can say is I find couple of edge cases,
The cdup command relies on a slash counting loop on the prefix string to output directory-up
sequences like '../', returns an empty string at the root and falls back to the worktree path when outside.
On the contrary, relative formatting uses Git's path utility library to compute true relative
filesystem paths, outputting '.' at the root instead of leaving it blank.
Quoted 4 lines
One note on the tests - our test suite is quite slow, so it would be good to avoid initializing new repositories for each test where we are checking these paths.
Alright, I will look into them and see how I can optimize them.
Quoted 4 lines
Thanks
Phillip
[snip]
Thank you,
- K Jayatheerth
Re: [GSoC Patch v8 0/7] repo: add path keys to repo info
Quoted 9 lines · K Jayatheerth
Quoted 6 lines
Quoted 2 lines
-
path.superproject-root.absolute/path.superproject-root.relative:
The root of the superproject when inside a submodule.Personally, I'd prefer "path.superproject-working-tree.*" here, though I see Justin thought that was a bit of a mouthful. As this command is for use in scripts I'd rather have a descriptive name.
I don't have an opinion on the name itself, but, that said:
I think superproject-working-tree is a more suiting name.
Syntactically you could put anything at the second level of three-level configuration variable names, but I thought we avoid '-' in configuration variable names in general.
We can see that we made many mistakes in the 'maintenance.' hierarchy ...
$ git grep -h -E '^`?[^ ]*::$' Documentation/config/ | grep -e -
... but nowhere else.
Re: [GSoC Patch v8 0/7] repo: add path keys to repo info
Hi Junio
Quoted 11 lines · Junio C Hamano
Syntactically you could put anything at the second level of three-level configuration variable names, but I thought we avoid '-' in configuration variable names in general.
We can see that we made many mistakes in the 'maintenance.' hierarchy ...
$ git grep -h -E '^`?[^ ]*::$' Documentation/config/ | grep -e -... but nowhere else.
These aren't actually config keys, but we do seem to have added "path.gitdir.*" and "path.commondir.*" rather than "path.git-dir.*" and "path.common-dir.*" so dropping the dashes would be consistent with the existing path keys.
Thanks
Phillip
Re: [GSoC Patch v8 0/7] repo: add path keys to repo info
In reply to Junio C HamanoQuoted 17 lines · Junio C Hamano
Quoted 9 lines · K Jayatheerth
Quoted 6 lines
Quoted 2 lines
-
path.superproject-root.absolute/path.superproject-root.relative:
The root of the superproject when inside a submodule.Personally, I'd prefer "path.superproject-working-tree.*" here, though I see Justin thought that was a bit of a mouthful. As this command is for use in scripts I'd rather have a descriptive name.
I don't have an opinion on the name itself, but, that said:
I think superproject-working-tree is a more suiting name.Syntactically you could put anything at the second level of three-level configuration variable names, but I thought we avoid '-' in configuration variable names in general.
Quoted 6 lines
We can see that we made many mistakes in the 'maintenance.' hierarchy ...
$ git grep -h -E '^`?[^ ]*::$' Documentation/config/ | grep -e -... but nowhere else.
As echoed by Phillip below, I will avoid the hyphens.
Thank you!
- K Jayatheerth
Re: [GSoC Patch v8 0/7] repo: add path keys to repo info
In reply to K JayatheerthQuoted 18 lines · K Jayatheerth
Quoted 9 lines · Phillip Wood
Quoted 4 lines
The path keys added in this series are:
-path.toplevel.absolute/path.toplevel.relative: The root directory of the working tree (or an empty string in bare repositories).In our documentation and glossary, we call this directory the "working tree" so I think "path.working-tree.*" would be a better name, rather than copying the name from the equivalent rev-parse option.
Quoted 7 lines
Quoted 2 lines
-
path.superproject-root.absolute/path.superproject-root.relative:
The root of the superproject when inside a submodule.Personally, I'd prefer "path.superproject-working-tree.*" here, though I see Justin thought that was a bit of a mouthful. As this command is for use in scripts I'd rather have a descriptive name.
Quoted 8 lines
I don't have an opinion on the name itself, but, that said:
I think superproject-working-tree is a more suiting name. It is becuase you may have a working tree in a different place and it might not be the root itself.
I think the same logic applies for toplevel too.Any more thoughts from Justin, Lucas, Junio or any other reviewer would be better I reckon.
Yes, that would be helpful
Quoted 14 lines
Quoted 8 lines
Quoted 2 lines
-
path.hooks.absolute/path.hooks.relative: The repository's hooks directory (respectingcore.hooksPath, including/dev/null).Given we have config based hooks now, do we really want to add this? Scripts that want to run hooks should be using "git hook run" and scripts that want to install hooks should be using the config based hooks so that they co-exist with the user's existing hooks.
I believe that is a fair point for new tooling, though wouldn't many existing scripts
and third-party tools still learn about hooks directly viagit rev-parse --git-path hooks?
Quoted 4 lines
Since the main goal of
git repo infois to provide an alternative torev-parse's various path flags,path.hooksstill seems useful for scripts migrating over, unless the consensus is to deprecate querying the hooks directory altogether.
Isn't the goal to provide a better interface than rev-parse, rather than just porting the various path related options across unchanged? My worry is that by adding "path.hooks.*" we're encouraging people to use an outdated interface that ignores the existence of config based hooks. Anyone who wants to keep using "git rev-parse --git-path hooks" can do so, but I'd rather we didn't encourage that pattern by supporting it in new commands.
Quoted 12 lines
Quoted 8 lines
Quoted 2 lines
-
path.cdup: The relative path from the current directory up to the worktree root.How does this differ from path.working-tree.relative? I've never really understood "git rev-parse --cdup" - if you're in the repository root directory, 'cd "$(git rev-parse --cdup)"' dumps you in your home directory which has always seemed a bit surprising to me.
Well looking at the code itself
What I can say is I find couple of edge cases,
Quoted 8 lines
The cdup command relies on a slash counting loop on the prefix string to output directory-up
sequences like '../', returns an empty string at the root and falls back to the worktree path when outside.On the contrary, relative formatting uses Git's path utility library to compute true relative
filesystem paths, outputting '.' at the root instead of leaving it blank.
Right - but what practical benefit does "path.cdup" offer over "path.working-tree.relative"? "git rev-parse --cdup" was added in 5f94c730f3 (rev-parse: --show-cdup, 2005-12-22), four years before "--show-toplevel" in 7cceca5ccc (Add 'git rev-parse --show-toplevel' option., 2010-01-12) and 15 years before support for relative paths in fac60b8925 (rev-parse: add option for absolute or relative path formatting, 2020-12-13). So when it was added "--cdup" was the only way to find the root of the repository working tree, which is not the case now.
Thanks
Phillip
Re: [GSoC Patch v8 0/7] repo: add path keys to repo info
Quoted 50 lines · Phillip Wood
Quoted 18 lines · K Jayatheerth
Quoted 9 lines · Phillip Wood
Quoted 4 lines
The path keys added in this series are:
-path.toplevel.absolute/path.toplevel.relative: The root directory of the working tree (or an empty string in bare repositories).In our documentation and glossary, we call this directory the "working tree" so I think "path.working-tree.*" would be a better name, rather than copying the name from the equivalent rev-parse option.
Quoted 7 lines
Quoted 2 lines
-
path.superproject-root.absolute/path.superproject-root.relative:
The root of the superproject when inside a submodule.Personally, I'd prefer "path.superproject-working-tree.*" here, though I see Justin thought that was a bit of a mouthful. As this command is for use in scripts I'd rather have a descriptive name.
Quoted 8 lines
I don't have an opinion on the name itself, but, that said:
I think superproject-working-tree is a more suiting name. It is becuase you may have a working tree in a different place and it might not be the root itself.
I think the same logic applies for toplevel too.Any more thoughts from Justin, Lucas, Junio or any other reviewer would be better I reckon.
Yes, that would be helpful
Quoted 14 lines
Quoted 8 lines
Quoted 2 lines
-
path.hooks.absolute/path.hooks.relative: The repository's hooks directory (respectingcore.hooksPath, including/dev/null).Given we have config based hooks now, do we really want to add this? Scripts that want to run hooks should be using "git hook run" and scripts that want to install hooks should be using the config based hooks so that they co-exist with the user's existing hooks.
I believe that is a fair point for new tooling, though wouldn't many existing scripts
and third-party tools still learn about hooks directly viagit rev-parse --git-path hooks?Quoted 4 lines
Since the main goal of
git repo infois to provide an alternative torev-parse's various path flags,path.hooksstill seems useful for scripts migrating over, unless the consensus is to deprecate querying the hooks directory altogether.
Quoted 7 lines
Isn't the goal to provide a better interface than rev-parse, rather than just porting the various path related options across unchanged? My worry is that by adding "path.hooks.*" we're encouraging people to use an outdated interface that ignores the existence of config based hooks. Anyone who wants to keep using "git rev-parse --git-path hooks" can do so, but I'd rather we didn't encourage that pattern by supporting it in new commands.
Well, rev-parse is one way people can use it to access, so sure, I will drop this patch.
Quoted 21 lines
Quoted 12 lines
Quoted 8 lines
Quoted 2 lines
-
path.cdup: The relative path from the current directory up to the worktree root.How does this differ from path.working-tree.relative? I've never really understood "git rev-parse --cdup" - if you're in the repository root directory, 'cd "$(git rev-parse --cdup)"' dumps you in your home directory which has always seemed a bit surprising to me.
Well looking at the code itself
What I can say is I find couple of edge cases,Quoted 8 lines
The cdup command relies on a slash counting loop on the prefix string to output directory-up
sequences like '../', returns an empty string at the root and falls back to the worktree path when outside.On the contrary, relative formatting uses Git's path utility library to compute true relative
filesystem paths, outputting '.' at the root instead of leaving it blank.
Quoted 9 lines
Right - but what practical benefit does "path.cdup" offer over "path.working-tree.relative"? "git rev-parse --cdup" was added in
5f94c730f3(rev-parse: --show-cdup, 2005-12-22), four years before "--show-toplevel" in7cceca5ccc(Add 'git rev-parse --show-toplevel' option., 2010-01-12) and 15 years before support for relative paths infac60b8925(rev-parse: add option for absolute or relative path formatting, 2020-12-13). So when it was added "--cdup" was the only way to find the root of the repository working tree, which is not the case now.
Well, you are right, it adds nothing new per se.
I was replicating rev-parse without any benefit in both these cases.
Same logic applies, I will drop both these patches.
Quoted 4 lines
Thanks
Phillip
Thanks for the review Phillip!
Regards,
- K Jayatheerth
Re: [GSoC Patch v8 0/7] repo: add path keys to repo info
Hi
Quoted 5 lines · K Jayatheerth
Well, you are right, it adds nothing new per se.
I was replicating rev-parse without any benefit in both these cases.Same logic applies, I will drop both these patches.
That's great, I look forward to reading V9
Thanks
Phillip
v9 cover repo: add path keys to repo info
In reply to K JayatheerthThis patch series continues the work to expose repository paths and metadata via the git repo info command. It introduces several keys for querying repository paths in standard absolute and relative formats, as well as refactoring get_superproject_working_tree() to operate on a struct repository *.
The path keys added in this series are:
- path.workingtree.absolute / path.workingtree.relative: The root directory of the working tree (or an empty string in bare repositories).
- path.superprojectworkingtree.absolute / path.superprojectworkingtree.relative: The root of the superproject when inside a submodule.
- path.index.absolute / path.index.relative: The repository's active index file.
- path.prefix: The prefix from the worktree root to the current working directory.
Changes since v8:
- Dropped path.hooks and path.cdup.
- Renamed path.toplevel.* to path.workingtree.* to align with the standard "working tree" glossary term while avoiding hyphens in configuration variable names.
- Renamed path.superproject-root.* to path.superprojectworkingtree.* to provide a descriptive name for scripts while avoiding hyphens.
- Renamed path.git-prefix to path.prefix to shorten it and avoid hyphens.
K Jayatheerth (5):
repo: add path.workingtree with absolute and relative suffix
formatting
submodule: use repository to find superproject
repo: add path.superprojectworkingtree with absolute and relative
suffixes
repo: add path.index with absolute and relative suffixes
repo: add path.prefix
Documentation/git-repo.adoc | 37 +++++++++++ builtin/repo.c | 78 +++++++++++++++++++++++ builtin/rev-parse.c | 2 +- submodule.c | 43 ++++++------- submodule.h | 2 +- t/t1500-rev-parse.sh | 20 ++++++ t/t1900-repo-info.sh | 120 ++++++++++++++++++++++++++++++++++++ 7 files changed, 279 insertions(+), 23 deletions(-)
Range-diff against v8:
1: 27b9811163 ! 1: 6cb242828b repo: add path.toplevel with absolute and relative suffix formatting
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: add path.toplevel with absolute and relative suffix formatting
+ repo: add path.workingtree with absolute and relative suffix formatting
Scripts frequently need to find the root directory of a repository's
working tree. Currently, this requires using `git rev-parse --show-toplevel`
or inferring it from other repository information.
- Introduce `path.toplevel.absolute` and `path.toplevel.relative` keys
+ Introduce `path.workingtree.absolute` and `path.workingtree.relative` keys
to `git repo info`. This allows scripts to retrieve the top-level
working tree path in a predictable, strictly formatted manner without
relying on `rev-parse`.
@@ Documentation/git-repo.adoc: values that they return:
`path.gitdir.relative`::
The path to the Git repository directory relative to the current working directory.
-+`path.toplevel.absolute`::
++`path.workingtree.absolute`::
+ The canonical absolute path to the top-level directory of the
+ repository's working tree. Outputs an empty string if the repository
+ is bare.
+
-+`path.toplevel.relative`::
++`path.workingtree.relative`::
+ The path to the top-level directory of the repository's working
+ tree relative to the current working directory. Outputs an empty
+ string if the repository is bare.
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
return 0;
}
-+static int get_path_toplevel_absolute(struct repository *repo, struct strbuf *buf)
++static int get_path_workingtree_absolute(struct repository *repo, struct strbuf *buf)
+{
+ const char *work_tree = repo_get_work_tree(repo);
+
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+ return 0;
+}
+
-+static int get_path_toplevel_relative(struct repository *repo, struct strbuf *buf)
++static int get_path_workingtree_relative(struct repository *repo, struct strbuf *buf)
+{
+ const char *work_tree = repo_get_work_tree(repo);
+
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
{ "path.commondir.relative", get_path_commondir_relative },
{ "path.gitdir.absolute", get_path_gitdir_absolute },
{ "path.gitdir.relative", get_path_gitdir_relative },
-+ { "path.toplevel.absolute", get_path_toplevel_absolute },
-+ { "path.toplevel.relative", get_path_toplevel_relative },
++ { "path.workingtree.absolute", get_path_workingtree_absolute },
++ { "path.workingtree.relative", get_path_workingtree_relative },
{ "references.format", get_references_format },
};
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
'.git' \
'GIT_DIR="../.git" && export GIT_DIR'
-+test_expect_success 'path.toplevel absolute and relative' '
++test_expect_success 'path.workingtree absolute and relative' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
+
+ ROOT="$(test-tool path-utils real_path ..)" &&
+
-+ echo "path.toplevel.absolute=$ROOT" >expect.abs &&
-+ git repo info path.toplevel.absolute >actual.abs &&
++ echo "path.workingtree.absolute=$ROOT" >expect.abs &&
++ git repo info path.workingtree.absolute >actual.abs &&
+ test_cmp expect.abs actual.abs &&
+
-+ echo "path.toplevel.relative=../" >expect.rel &&
-+ git repo info path.toplevel.relative >actual.rel &&
++ echo "path.workingtree.relative=../" >expect.rel &&
++ git repo info path.workingtree.relative >actual.rel &&
+ test_cmp expect.rel actual.rel
+ )
+'
+
-+test_expect_success 'path.toplevel absolute and relative in a bare repository' '
++test_expect_success 'path.workingtree absolute and relative in a bare repository' '
+ test_when_finished "rm -rf bare.git" &&
+ git init --bare bare.git &&
+ (
+ cd bare.git &&
+
-+ echo "path.toplevel.absolute=" >expect.abs &&
-+ git repo info path.toplevel.absolute >actual.abs &&
++ echo "path.workingtree.absolute=" >expect.abs &&
++ git repo info path.workingtree.absolute >actual.abs &&
+ test_cmp expect.abs actual.abs &&
+
-+ echo "path.toplevel.relative=" >expect.rel &&
-+ git repo info path.toplevel.relative >actual.rel &&
++ echo "path.workingtree.relative=" >expect.rel &&
++ git repo info path.workingtree.relative >actual.rel &&
+ test_cmp expect.rel actual.rel
+ )
+'
2: 2274dd8be2 = 2: 9da5ce8a69 submodule: use repository to find superproject
3: 34c54cdafd ! 3: deaf3ae42e repo: add path.superproject-root with absolute and relative suffixes
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: add path.superproject-root with absolute and relative suffixes
+ repo: add path.superprojectworkingtree with absolute and relative suffixes
Scripts working in multi-repository setups often need to identify the
top-level working tree of a superproject from within a submodule.
Currently, this is only exposed via `git rev-parse
--show-superproject-working-tree`.
- Introduce `path.superproject-root.absolute` and
- `path.superproject-root.relative` keys to `git repo info`.
+ Introduce `path.superprojectworkingtree.absolute` and
+ `path.superprojectworkingtree.relative` keys to `git repo info`.
This exposes the core submodule context via a scriptable config-like key
using standard format rules.
@@ Documentation/git-repo.adoc: values that they return:
`path.gitdir.relative`::
The path to the Git repository directory relative to the current working directory.
-+`path.superproject-root.absolute`::
++`path.superprojectworkingtree.absolute`::
+ The canonical absolute path to the working tree root of the superproject
+ if the current repository is an initialized submodule. Outputs an empty
+ string if not in a submodule.
+
-+`path.superproject-root.relative`::
++`path.superprojectworkingtree.relative`::
+ The path to the working tree root of the superproject relative to the
+ current working directory if the current repository is an initialized
+ submodule. Outputs an empty string if not in a submodule.
+
- `path.toplevel.absolute`::
+ `path.workingtree.absolute`::
The canonical absolute path to the top-level directory of the
repository's working tree. Outputs an empty string if the repository
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
return 0;
}
-+static int get_path_superproject_absolute(struct repository *repo, struct strbuf *buf)
++static int get_path_superprojectworkingtree_absolute(struct repository *repo, struct strbuf *buf)
+{
+ struct strbuf superproject = STRBUF_INIT;
+
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+ return 0;
+}
+
-+static int get_path_superproject_relative(struct repository *repo, struct strbuf *buf)
++static int get_path_superprojectworkingtree_relative(struct repository *repo, struct strbuf *buf)
+{
+ struct strbuf superproject = STRBUF_INIT;
+
@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, str
+ return 0;
+}
+
- static int get_path_toplevel_absolute(struct repository *repo, struct strbuf *buf)
+ static int get_path_workingtree_absolute(struct repository *repo, struct strbuf *buf)
{
const char *work_tree = repo_get_work_tree(repo);
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
{ "path.commondir.relative", get_path_commondir_relative },
{ "path.gitdir.absolute", get_path_gitdir_absolute },
{ "path.gitdir.relative", get_path_gitdir_relative },
-+ { "path.superproject-root.absolute", get_path_superproject_absolute },
-+ { "path.superproject-root.relative", get_path_superproject_relative },
- { "path.toplevel.absolute", get_path_toplevel_absolute },
- { "path.toplevel.relative", get_path_toplevel_relative },
++ { "path.superprojectworkingtree.absolute", get_path_superprojectworkingtree_absolute },
++ { "path.superprojectworkingtree.relative", get_path_superprojectworkingtree_relative },
+ { "path.workingtree.absolute", get_path_workingtree_absolute },
+ { "path.workingtree.relative", get_path_workingtree_relative },
{ "references.format", get_references_format },
## t/t1900-repo-info.sh ##
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
'.git' \
'GIT_DIR="../.git" && export GIT_DIR'
-+test_expect_success 'path.superproject-root absolute and relative' '
++test_expect_success 'path.superprojectworkingtree absolute and relative' '
+ test_when_finished "rm -rf sub super" &&
+ git init sub &&
+ test_commit -C sub initial &&
@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir
+ cd sub &&
+ ROOT="$(test-tool path-utils real_path ..)" &&
+
-+ echo "path.superproject-root.absolute=$ROOT" >expect.abs &&
-+ git repo info path.superproject-root.absolute >actual.abs &&
++ echo "path.superprojectworkingtree.absolute=$ROOT" >expect.abs &&
++ git repo info path.superprojectworkingtree.absolute >actual.abs &&
+ test_cmp expect.abs actual.abs &&
+
-+ echo "path.superproject-root.relative=../" >expect.rel &&
-+ git repo info path.superproject-root.relative >actual.rel &&
++ echo "path.superprojectworkingtree.relative=../" >expect.rel &&
++ git repo info path.superprojectworkingtree.relative >actual.rel &&
+ test_cmp expect.rel actual.rel
+ )
+'
+
-+test_expect_success 'path.superproject-root returns empty when not in a submodule' '
++test_expect_success 'path.superprojectworkingtree returns empty when not in a submodule' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
+
-+ echo "path.superproject-root.absolute=" >expect.abs &&
-+ git repo info path.superproject-root.absolute >actual.abs &&
++ echo "path.superprojectworkingtree.absolute=" >expect.abs &&
++ git repo info path.superprojectworkingtree.absolute >actual.abs &&
+ test_cmp expect.abs actual.abs &&
+
-+ echo "path.superproject-root.relative=" >expect.rel &&
-+ git repo info path.superproject-root.relative >actual.rel &&
++ echo "path.superprojectworkingtree.relative=" >expect.rel &&
++ git repo info path.superprojectworkingtree.relative >actual.rel &&
+ test_cmp expect.rel actual.rel
+ )
+'
+
- test_expect_success 'path.toplevel absolute and relative' '
+ test_expect_success 'path.workingtree absolute and relative' '
test_when_finished "rm -rf repo" &&
git init repo &&
4: 985403c7b3 < -: ---------- repo: add path.hooks with absolute and relative suffixes
5: 486836ae52 ! 4: de9e189714 repo: add path.index with absolute and relative suffixes@@ Commit message
## Documentation/git-repo.adoc ##
@@ Documentation/git-repo.adoc: values that they return:
- working directory. Respects the core.hooksPath configuration. If
- core.hooksPath is set to /dev/null, that value is returned unchanged.
+ path.gitdir.relative::
+ The path to the Git repository directory relative to the current working directory.
+path.index.absolute::
+ The canonical absolute path to the repository's current index file.
@@ Documentation/git-repo.adoc: values that they return:
+ Returns the configured index path even if the repository is bare or the
+ file does not exist.
+
- path.superproject-root.absolute::
+ path.superprojectworkingtree.absolute::
The canonical absolute path to the working tree root of the superproject if the current repository is an initialized submodule. Outputs an empty
## builtin/repo.c ##
-@@ builtin/repo.c: static int get_path_hooks_relative(struct repository *repo, struct strbuf *buf) +@@ builtin/repo.c: static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)
return 0;
}
@@ builtin/repo.c: static int get_path_hooks_relative(struct repository *repo, stru
+ return 0;
+}
+
- static int get_path_superproject_absolute(struct repository *repo, struct strbuf *buf)
+ static int get_path_superprojectworkingtree_absolute(struct repository *repo, struct strbuf *buf) {
struct strbuf superproject = STRBUF_INIT;
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
+ { "path.commondir.relative", get_path_commondir_relative },
+ { "path.gitdir.absolute", get_path_gitdir_absolute },
{ "path.gitdir.relative", get_path_gitdir_relative },
- { "path.hooks.absolute", get_path_hooks_absolute },
- { "path.hooks.relative", get_path_hooks_relative },
+ { "path.index.absolute", get_path_index_absolute },
+ { "path.index.relative", get_path_index_relative },
- { "path.superproject-root.absolute", get_path_superproject_absolute },
- { "path.superproject-root.relative", get_path_superproject_relative },
- { "path.toplevel.absolute", get_path_toplevel_absolute },
+ { "path.superprojectworkingtree.absolute", get_path_superprojectworkingtree_absolute },
+ { "path.superprojectworkingtree.relative", get_path_superprojectworkingtree_relative },
+ { "path.workingtree.absolute", get_path_workingtree_absolute },
## t/t1900-repo-info.sh ##
-@@ t/t1900-repo-info.sh: test_expect_success 'hooks with core.hooksPath=/dev/null' '
- )
- '
+@@ t/t1900-repo-info.sh: test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \
+ '.git' \
+ 'GIT_DIR="../.git" && export GIT_DIR'
+test_repo_info_path 'index standard' 'index' '.git/index'
+
@@ t/t1900-repo-info.sh: test_expect_success 'hooks with core.hooksPath=/dev/null'
+ )
+'
+
- test_expect_success 'path.superproject-root absolute and relative' '
+ test_expect_success 'path.superprojectworkingtree absolute and relative' ' test_when_finished "rm -rf sub super" &&
git init sub &&
6: 91a8dc3ab1 < -: ---------- repo: add path.git-prefix
7: 84a9fb4060 ! 5: 97035f59f4 repo: add path.cdup
@@ Metadata
Author: K Jayatheerth <[email protected]>
## Commit message ##
- repo: add path.cdup
+ repo: add path.prefix
- Scripts sometimes need the relative path from the current working
- directory to the repository's working tree root (cdup). While this
- information can be retrieved through `git rev-parse --show-cdup`,
- `git repo info` does not currently expose it as a scriptable key.
+ Scripts sometimes need the path from the repository's working tree root
+ to the current working directory. While this information can be derived
+ through existing Git commands, `git repo info` does not currently expose
+ it as a scriptable key.
- Introduce the `path.cdup` key to `git repo info`. The key returns the
- path from the current working directory to the root of the working tree,
+ Introduce the `path.prefix` key to `git repo info`. The key returns
+ the path from the working tree root to the current working directory,
returning the empty string when invoked from the working tree root.
Mentored-by: Justin Tobler <[email protected]>
@@ Commit message
## Documentation/git-repo.adoc ##
@@ Documentation/git-repo.adoc: values that they return:
- `object.format`::
- The object format (hash algorithm) used in the repository.
+ Returns the configured index path even if the repository is bare or the
+ file does not exist.
-+`path.cdup`::
-+ When the command is invoked from a subdirectory, show the
-+ path of the top-level directory relative to the current
-+ directory (typically a sequence of "../", or an empty string).
++`path.prefix`::
++ The path from the root of the working tree to the current working
++ directory. Returns the empty string when the current working directory
++ is the root of the working tree.
+
- `path.commondir.absolute`::
- The canonical absolute path to the Git repository's common
- directory (the shared `.git` directory containing objects,
+ `path.superprojectworkingtree.absolute`::
+ The canonical absolute path to the working tree root of the superproject
+ if the current repository is an initialized submodule. Outputs an empty
## builtin/repo.c ##
-@@ builtin/repo.c: static int get_object_format(struct repository *repo, struct strbuf *buf)
+@@ builtin/repo.c: static int get_path_commondir_relative(struct repository *repo, struct strbuf *b
return 0;
}
-+static int get_path_cdup(struct repository *repo, struct strbuf *buf)
++static int get_path_prefix(struct repository *repo, struct strbuf *buf)
+{
-+ const char *pfx = repo->prefix;
-+
-+ if (!is_inside_work_tree(repo)) {
-+ const char *worktree = repo_get_work_tree(repo);
-+
-+ if (worktree)
-+ strbuf_addstr(buf, worktree);
-+ return 0;
-+ }
-+
-+ while (pfx) {
-+ pfx = strchr(pfx, '/');
-+ if (pfx) {
-+ pfx++;
-+ strbuf_addstr(buf, "../");
-+ }
-+ }
++ /*
++ * repo->prefix is NULL when the current working directory is
++ * the worktree root.
++ */
++ strbuf_addstr(buf, repo->prefix ? repo->prefix : "");
+ return 0;
+}
+
- static int get_path_commondir_absolute(struct repository *repo, struct strbuf *buf)
+ static int get_path_gitdir_absolute(struct repository *repo, struct strbuf *buf)
{
- const char *common_dir = repo_get_common_dir(repo);
+ const char *git_dir = repo_get_git_dir(repo);
@@ builtin/repo.c: static const struct repo_info_field repo_info_field[] = {
- { "layout.bare", get_layout_bare },
- { "layout.shallow", get_layout_shallow },
- { "object.format", get_object_format },
-+ { "path.cdup", get_path_cdup },
- { "path.commondir.absolute", get_path_commondir_absolute },
- { "path.commondir.relative", get_path_commondir_relative },
- { "path.git-prefix", get_path_git_prefix },
+ { "path.gitdir.relative", get_path_gitdir_relative },
+ { "path.index.absolute", get_path_index_absolute },
+ { "path.index.relative", get_path_index_relative },
++ { "path.prefix", get_path_prefix },
+ { "path.superprojectworkingtree.absolute", get_path_superprojectworkingtree_absolute },
+ { "path.superprojectworkingtree.relative", get_path_superprojectworkingtree_relative },
+ { "path.workingtree.absolute", get_path_workingtree_absolute },
## t/t1900-repo-info.sh ##
@@ t/t1900-repo-info.sh: test_repo_info_path 'commondir with only GIT_DIR' 'commondir' \
'.git' \
'GIT_DIR="../.git" && export GIT_DIR'
-+test_expect_success 'path.cdup at repository root' '
++test_expect_success 'path.prefix at repository root' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ (
+ cd repo &&
-+ echo "path.cdup=" >expect &&
-+ git repo info path.cdup >actual &&
++ echo "path.prefix=" >expect &&
++ git repo info path.prefix >actual &&
+ test_cmp expect actual
+ )
+'
+
-+test_expect_success 'path.cdup in subdirectory' '
++test_expect_success 'path.prefix in subdirectory' '
+ test_when_finished "rm -rf repo" &&
+ git init repo &&
+ mkdir -p repo/sub/dir &&
+ (
+ cd repo/sub/dir &&
-+ echo "path.cdup=../../" >expect &&
-+ git repo info path.cdup >actual &&
++ echo "path.prefix=sub/dir/" >expect &&
++ git repo info path.prefix >actual &&
+ test_cmp expect actual
+ )
+'
+
-+test_expect_success 'path.cdup cwd outside the working tree' '
-+ test_when_finished "rm -rf repo" &&
-+ mkdir -p repo/tmp/x &&
-+ (
-+ cd repo &&
-+ git init test &&
-+ echo "path.cdup=$(pwd)/tmp/x" >test/expect &&
-+ cd test &&
-+ GIT_WORK_TREE=../tmp/x &&
-+ export GIT_WORK_TREE &&
-+ GIT_DIR=$(pwd)/.git &&
-+ export GIT_DIR &&
-+ git repo info path.cdup >actual &&
-+ test_cmp expect actual
-+ )
-+'
-+
- test_expect_success 'path.git-prefix at repository root' '
- test_when_finished "rm -rf repo" &&
- git init repo &&
+ test_repo_info_path 'gitdir standard' 'gitdir' '.git'
+
+ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \Signature · 1 line
2.56.0-rc2
PATCH v9 1/5 repo: add path.workingtree with absolute and relative suffix formatting
Scripts frequently need to find the root directory of a repository's working tree. Currently, this requires using git rev-parse --show-toplevel or inferring it from other repository information.
Introduce path.workingtree.absolute and path.workingtree.relative keys to git repo info. This allows scripts to retrieve the top-level working tree path in a predictable, strictly formatted manner without relying on rev-parse.
If requested in a bare repository where no working tree exists, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 24 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 69 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.workingtree.absolute`:: + The canonical absolute path to the top-level directory of the + repository's working tree. Outputs an empty string if the repository + is bare. + +`path.workingtree.relative`:: + The path to the top-level directory of the repository's working + tree relative to the current working directory. Outputs an empty + string if the repository is bare. + `references.format`:: The reference storage format. The valid values are: +
builtin/repo.c +24 -0
@@ -121,6 +121,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_workingtree_absolute (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) +return 0 ; + +format_path (buf, work_tree,"" ,PATH_FORMAT_CANONICAL ); +return 0 ; +} + +static int get_path_workingtree_relative (struct repository *repo,struct strbuf *buf) +{ +const char *work_tree =repo_get_work_tree (repo); + +if (!work_tree) +return 0 ; + +format_path (buf, work_tree, repo->prefix,PATH_FORMAT_RELATIVE ); +return 0 ; +} +static int get_references_format (struct repository *repo,struct strbuf *buf) { strbuf_addstr(buf,
@@ -137,6 +159,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.workingtree.absolute", get_path_workingtree_absolute }, + { "path.workingtree.relative", get_path_workingtree_relative }, { "references.format", get_references_format }, };
t/t1900-repo-info.sh +35 -0
@@ -213,4 +213,39 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.workingtree absolute and relative' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + mkdir -p repo/sub && + cd repo/sub && + + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.workingtree.absolute=$ROOT" >expect.abs && + git repo info path.workingtree.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.workingtree.relative=../" >expect.rel && + git repo info path.workingtree.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.workingtree absolute and relative in a bare repository' ' + test_when_finished "rm -rf bare.git" && + git init --bare bare.git && + ( + cd bare.git && + + echo "path.workingtree.absolute=" >expect.abs && + git repo info path.workingtree.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.workingtree.relative=" >expect.rel && + git repo info path.workingtree.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_done
Signature · 1 line
2.56.0-rc2
PATCH v9 2/5 submodule: use repository to find superproject
In reply to K Jayatheerthget_superproject_working_tree() currently uses xgetcwd() to determine the repository whose superproject should be checked.
This is incorrect when --git-dir points to a repository different from the one associated with the current working directory. In that case, the current working directory may cause the function to return the wrong superproject or an empty result.
Pass the repository to get_superproject_working_tree() so that the superproject is determined from the repository being inspected rather than the current working directory.
--- builtin/rev-parse.c | 2 +- submodule.c | 43 ++++++++++++++++++++++--------------------- submodule.h | 2 +- t/t1500-rev-parse.sh | 20 ++++++++++++++++++++ 4 files changed, 44 insertions(+), 23 deletions(-)
builtin/rev-parse.c +1 -1
@@ -997,7 +997,7 @@ int cmd_rev_parse(int argc, }if (!strcmp (arg,"--show-superproject-working-tree" )) {struct strbuf superproject =STRBUF_INIT ; -if (get_superproject_working_tree (&superproject)) +if (get_superproject_working_tree (the_repository, &superproject))print_path (superproject.buf, prefix, format,DEFAULT_UNMODIFIED );strbuf_release (&superproject);continue ;
submodule.c +22 -21
99 lines not on this page · raw message
submodule.h +1 -1
@@ -170,6 +170,6 @@ void absorb_git_dir_into_superproject(const char *path,* project is a submodule of. If this repository is not a submodule of * another repository, return 0. */ -int get_superproject_working_tree (struct strbuf *buf); +int get_superproject_working_tree (struct repository *r,struct strbuf *buf);#endif
t/t1500-rev-parse.sh +20 -0
@@ -383,4 +383,24 @@ test_expect_success ':/ and HEAD^{/} favor more recent matching commits' ' ) ' +test_expect_success '--show-superproject-working-tree works with --git-dir' ' + rm -rf sub super && + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + SUPER_ROOT="$(test-tool path-utils real_path .)" && + MODULE_DIR="$SUPER_ROOT/.git/modules/sub" && + + echo "$SUPER_ROOT" >expect && + git --git-dir="$MODULE_DIR" rev-parse --show-superproject-working-tree >actual && + test_cmp expect actual + ) +' + test_done
Signature · 1 line
2.56.0-rc2
PATCH v9 3/5 repo: add path.superprojectworkingtree with absolute and relative suffixes
In reply to K JayatheerthScripts working in multi-repository setups often need to identify the top-level working tree of a superproject from within a submodule. Currently, this is only exposed via git rev-parse --show-superproject-working-tree.
Introduce path.superprojectworkingtree.absolute and path.superprojectworkingtree.relative keys to git repo info. This exposes the core submodule context via a scriptable config-like key using standard format rules.
If requested when not inside a submodule, the command returns an empty string.
--- Documentation/git-repo.adoc | 10 ++++++++++ builtin/repo.c | 25 ++++++++++++++++++++++++ t/t1900-repo-info.sh | 39 +++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+)
Documentation/git-repo.adoc +10 -0
@@ -119,6 +119,16 @@ values that they return: `path.gitdir.relative`:: The path to the Git repository directory relative to the current working directory. +`path.superprojectworkingtree.absolute`:: + The canonical absolute path to the working tree root of the superproject + if the current repository is an initialized submodule. Outputs an empty + string if not in a submodule. + +`path.superprojectworkingtree.relative`:: + The path to the working tree root of the superproject relative to the + current working directory if the current repository is an initialized + submodule. Outputs an empty string if not in a submodule. + `path.workingtree.absolute`:: The canonical absolute path to the top-level directory of the repository's working tree. Outputs an empty string if the repository
builtin/repo.c +25 -0
@@ -18,6 +18,7 @@#include "strbuf.h" #include "string-list.h" #include "shallow.h" +#include "submodule.h" #include "tree.h" #include "tree-walk.h" #include "utf8.h"
@@ -121,6 +122,28 @@ static int get_path_gitdir_relative(struct repository *repo, struct strbuf *buf)return 0 ; } +static int get_path_superprojectworkingtree_absolute (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (get_superproject_working_tree (repo, &superproject)) +format_path (buf, superproject.buf,"" ,PATH_FORMAT_CANONICAL ); + +strbuf_release (&superproject); +return 0 ; +} + +static int get_path_superprojectworkingtree_relative (struct repository *repo,struct strbuf *buf) +{ +struct strbuf superproject =STRBUF_INIT ; + +if (get_superproject_working_tree (repo, &superproject)) +format_path (buf, superproject.buf, repo->prefix,PATH_FORMAT_RELATIVE ); + +strbuf_release (&superproject); +return 0 ; +} +static int get_path_workingtree_absolute (struct repository *repo,struct strbuf *buf) {const char *work_tree =repo_get_work_tree (repo);
@@ -159,6 +182,8 @@ static const struct repo_info_field repo_info_field[] = { { "path.commondir.relative", get_path_commondir_relative }, { "path.gitdir.absolute", get_path_gitdir_absolute }, { "path.gitdir.relative", get_path_gitdir_relative }, + { "path.superprojectworkingtree.absolute", get_path_superprojectworkingtree_absolute }, + { "path.superprojectworkingtree.relative", get_path_superprojectworkingtree_relative }, { "path.workingtree.absolute", get_path_workingtree_absolute }, { "path.workingtree.relative", get_path_workingtree_relative }, { "references.format", get_references_format },
t/t1900-repo-info.sh +39 -0
@@ -213,6 +213,45 @@ test_repo_info_path 'gitdir with explicit GIT_DIR' 'gitdir' \ '.git' \ 'GIT_DIR="../.git" && export GIT_DIR' +test_expect_success 'path.superprojectworkingtree absolute and relative' ' + test_when_finished "rm -rf sub super" && + git init sub && + test_commit -C sub initial && + git init super && + ( + cd super && + git -c protocol.file.allow=always submodule add "../sub" sub && + git commit -m "add submodule" && + + cd sub && + ROOT="$(test-tool path-utils real_path ..)" && + + echo "path.superprojectworkingtree.absolute=$ROOT" >expect.abs && + git repo info path.superprojectworkingtree.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superprojectworkingtree.relative=../" >expect.rel && + git repo info path.superprojectworkingtree.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + +test_expect_success 'path.superprojectworkingtree returns empty when not in a submodule' ' + test_when_finished "rm -rf repo" && + git init repo && + ( + cd repo && + + echo "path.superprojectworkingtree.absolute=" >expect.abs && + git repo info path.superprojectworkingtree.absolute >actual.abs && + test_cmp expect.abs actual.abs && + + echo "path.superprojectworkingtree.relative=" >expect.rel && + git repo info path.superprojectworkingtree.relative >actual.rel && + test_cmp expect.rel actual.rel + ) +' + test_expect_success 'path.workingtree absolute and relative' ' test_when_finished "rm -rf repo" && git init repo &&
Signature · 1 line
2.56.0-rc2