From 12b9d32790b40bf3ea49134095619700191abf1f Mon Sep 17 00:00:00 2001 From: John Keeping Date: Sun, 16 Jun 2013 15:18:17 +0100 Subject: rev-parse: add --prefix option This makes 'git rev-parse' behave as if it were invoked from the specified subdirectory of a repository, with the difference that any file paths which it prints are prefixed with the full path from the top of the working tree. This is useful for shell scripts where we may want to cd to the top of the working tree but need to handle relative paths given by the user on the command line. Signed-off-by: John Keeping Signed-off-by: Junio C Hamano --- Documentation/git-rev-parse.txt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'Documentation') diff --git a/Documentation/git-rev-parse.txt b/Documentation/git-rev-parse.txt index 947d62fd25..993903c9f1 100644 --- a/Documentation/git-rev-parse.txt +++ b/Documentation/git-rev-parse.txt @@ -59,6 +59,22 @@ OPTIONS If there is no parameter given by the user, use `` instead. +--prefix :: + Behave as if 'git rev-parse' was invoked from the `` + subdirectory of the working tree. Any relative filenames are + resolved as if they are prefixed by `` and will be printed + in that form. ++ +This can be used to convert arguments to a command run in a subdirectory +so that they can still be used after moving to the top-level of the +repository. For example: ++ +---- +prefix=$(git rev-parse --show-prefix) +cd "$(git rev-parse --show-toplevel)" +eval "set -- $(git rev-parse --sq --prefix "$prefix" "$@")" +---- + --verify:: Verify that exactly one parameter is provided, and that it can be turned into a raw 20-byte SHA-1 that can be used to -- cgit v1.2.3