From: Junio C Hamano Date: Fri, 23 Dec 2005 06:35:38 +0000 (-0800) Subject: rev-parse: --show-cdup X-Git-Tag: v1.1.0~31 X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=5f94c730f31862c7f500173ee3a9d141c4730f0b;p=git.git rev-parse: --show-cdup When --show-prefix is useful, sometimes it is easier to cd up to the toplevel of the tree. This is equivalent to: git rev-parse --show-prefix | sed -e 's|[^/][^/]*|..|g' but we do not have to invoke sed for that. Signed-off-by: Junio C Hamano --- diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt index 431b8f6e..d638bfc2 100644 --- a/Documentation/git-rev-parse.txt +++ b/Documentation/git-rev-parse.txt @@ -68,10 +68,15 @@ OPTIONS Show all refs found in `$GIT_DIR/refs`. --show-prefix:: - When the command is invoked from a directory show the + When the command is invoked from a subdirectory, show the path of the current directory relative to the top-level directory. +--show-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). + --since=datestring, --after=datestring:: Parses the date string, and outputs corresponding --max-age= parameter for git-rev-list command. diff --git a/rev-parse.c b/rev-parse.c index bb4949ad..0c951af0 100644 --- a/rev-parse.c +++ b/rev-parse.c @@ -216,6 +216,18 @@ int main(int argc, char **argv) puts(prefix); continue; } + if (!strcmp(arg, "--show-cdup")) { + const char *pfx = prefix; + while (pfx) { + pfx = strchr(pfx, '/'); + if (pfx) { + pfx++; + printf("../"); + } + } + putchar('\n'); + continue; + } if (!strcmp(arg, "--git-dir")) { const char *gitdir = getenv(GIT_DIR_ENVIRONMENT); static char cwd[PATH_MAX];