From 1a0ca5e358c1af14160e610e346c706e5dccf535 Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Tue, 10 Jan 2017 14:19:48 +0530 Subject: ref-filter: modify the 'lstrip=' option to work with negative '' Currently the 'lstrip=' option only takes a positive value '' and strips '' slash-separated path components from the left. Modify the 'lstrip' option to also take a negative number '' which would strip from the left as necessary and _leave_ behind only 'N' slash-separated path components from the right-most end. For e.g. %(refname:lstrip=-1) would make 'foo/goo/abc' into 'abc'. Add documentation and tests for the same. Signed-off-by: Karthik Nayak Signed-off-by: Junio C Hamano --- Documentation/git-for-each-ref.txt | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'Documentation') diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index 04ffc35524..8e4d16d7a3 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -97,8 +97,14 @@ refname:: The option core.warnAmbiguousRefs is used to select the strict abbreviation mode. If `lstrip=` is appended, strips `` slash-separated path components from the front of the refname - (e.g., `%(refname:lstrip=2)` turns `refs/tags/foo` into `foo`. - `` must be a positive integer. + (e.g. `%(refname:lstrip=2)` turns `refs/tags/foo` into `foo`. + If `` is a negative number, strip as many path components as + necessary from the left to leave `-` path components + (e.g. `%(refname:lstrip=-2)` turns + `refs/tags/foo` into `tags/foo`). When the ref does not have + enough components, the result becomes an empty string if + stripping with positive , or it becomes the full refname if + stripping with negative . Neither is an error. objecttype:: The type of the object (`blob`, `tree`, `commit`, `tag`). -- cgit v1.2.3