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>
This commit is contained in:
12
rev-parse.c
12
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];
|
||||
|
||||
Reference in New Issue
Block a user