summaryrefslogtreecommitdiff
path: root/rev-parse.c
diff options
context:
space:
mode:
authorJunio C Hamano <junkio@cox.net>2005-12-22 22:35:38 -0800
committerJunio C Hamano <junkio@cox.net>2005-12-22 22:35:38 -0800
commit5f94c730f31862c7f500173ee3a9d141c4730f0b (patch)
treee2123685937d061759aa00d483ee46e3aa2dc3ad /rev-parse.c
parentc10d63451883f67c37622d2a21b2fc93be2f90c9 (diff)
downloadgit-5f94c730f31862c7f500173ee3a9d141c4730f0b.tar.gz
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 <junkio@cox.net>
Diffstat (limited to 'rev-parse.c')
-rw-r--r--rev-parse.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/rev-parse.c b/rev-parse.c
index bb4949ad70..0c951af0d4 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];