Thread (85 messages) flat view 85 messages, 5 authors, 1d ago

Re: [GSoC Patch v6 7/7] repo: add path.cdup

From: Junio C Hamano <hidden>
Date: 2026-09-11 17:37:50

K Jayatheerth [off-list ref] writes:
quoted hunk ↗ jump to hunk
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.

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.

Mentored-by: Justin Tobler [off-list ref]
Mentored-by: Lucas Seiki Oshiro [off-list ref]
Signed-off-by: K Jayatheerth <redacted>
---
 Documentation/git-repo.adoc |  5 +++++
 builtin/repo.c              | 15 +++++++++++++++
 t/t1900-repo-info.sh        | 23 +++++++++++++++++++++++
 3 files changed, 43 insertions(+)
diff --git a/Documentation/git-repo.adoc b/Documentation/git-repo.adoc
index fb5aceae8f..0a30c0d6ab 100644
--- a/Documentation/git-repo.adoc
+++ b/Documentation/git-repo.adoc
@@ -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_DIR

The 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/x

Whether 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.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help