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>
Junio C Hamano committed
Dec 22, 2005 at 22:35 UTC
5f94c730f31862c7f500173ee3a9d141c4730f0b
2 files changed
+18
-1
Documentation/git-rev-parse.txt
+6
-1
@@ -68,10 +68,15 @@ OPTIONS
68
Show all refs found in `$GIT_DIR/refs`.
69
70
--show-prefix::
71
- When the command is invoked from a directory show the
71
+ When the command is invoked from a subdirectory, show the
72
path of the current directory relative to the top-level
73
directory.
74
75
+--show-cdup::
76
+ When the command is invoked from a subdirectory, show the
77
+ path of the top-level directory relative to the current
78
+ directory (typically a sequence of "../", or an empty string).
79
+
80
--since=datestring, --after=datestring::
81
Parses the date string, and outputs corresponding
82
--max-age= parameter for git-rev-list command.
rev-parse.c
+12
@@ -216,6 +216,18 @@ int main(int argc, char **argv)
216
puts(prefix);
217
continue;
218
}
219
+ if (!strcmp(arg, "--show-cdup")) {
220
+ const char *pfx = prefix;
221
+ while (pfx) {
222
+ pfx = strchr(pfx, '/');
223
+ if (pfx) {
224
+ pfx++;
225
+ printf("../");
226
+ }
227
+ }
228
+ putchar('\n');
229
+ continue;
230
+ }
231
if (!strcmp(arg, "--git-dir")) {
232
const char *gitdir = getenv(GIT_DIR_ENVIRONMENT);
233
static char cwd[PATH_MAX];