X-Git-Url: https://git.octo.it/?a=blobdiff_plain;f=rev-parse.c;h=7abad35de90b190c5d5e5456661853cf8167954a;hb=fc5be4fdaa063a667d17ae40e4ad130e2177b0f8;hp=bb4949ad70364abdf7c3bbca357e5ebc42880614;hpb=3eeb419968c1f8f0a762a7127db770e9d9c8037d;p=git.git diff --git a/rev-parse.c b/rev-parse.c index bb4949ad..7abad35d 100644 --- a/rev-parse.c +++ b/rev-parse.c @@ -154,6 +154,7 @@ int main(int argc, char **argv) const char *prefix = setup_git_directory(); for (i = 1; i < argc; i++) { + struct stat st; char *arg = argv[i]; char *dotdot; @@ -216,6 +217,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]; @@ -281,6 +294,8 @@ int main(int argc, char **argv) } if (verify) die("Needed a single revision"); + if (lstat(arg, &st) < 0) + die("'%s': %s", arg, strerror(errno)); as_is = 1; show_file(arg); }