From 5f94c730f31862c7f500173ee3a9d141c4730f0b Mon Sep 17 00:00:00 2001 From: Junio C Hamano Date: Thu, 22 Dec 2005 22:35:38 -0800 Subject: 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 --- rev-parse.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'rev-parse.c') diff --git a/rev-parse.c b/rev-parse.c index bb4949ad7..0c951af0d 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]; -- cgit v1.2.1