Skip to content

Commit

Permalink
rev-parse: --show-cdup
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Junio C Hamano committed Dec 23, 2005
1 parent c10d634 commit 5f94c73
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
7 changes: 6 additions & 1 deletion Documentation/git-rev-parse.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions rev-parse.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down

0 comments on commit 5f94c73

Please sign in to comment.