path: root/Documentation/git-for-each-ref.txt
diff options
authorKarthik Nayak <>2017-01-10 08:49:48 (GMT)
committerJunio C Hamano <>2017-01-31 20:38:59 (GMT)
commit1a0ca5e358c1af14160e610e346c706e5dccf535 (patch)
tree1728a6743b9b837307398d392873547b3fa84d12 /Documentation/git-for-each-ref.txt
parent3a42980f9e5ecc2b74c538109d4007c630881f1c (diff)
ref-filter: modify the 'lstrip=<N>' option to work with negative '<N>'
Currently the 'lstrip=<N>' option only takes a positive value '<N>' and strips '<N>' slash-separated path components from the left. Modify the 'lstrip' option to also take a negative number '<N>' 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 <>
Diffstat (limited to 'Documentation/git-for-each-ref.txt')
1 files changed, 8 insertions, 2 deletions
diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
index 04ffc35..8e4d16d 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=<N>` is appended, strips `<N>`
slash-separated path components from the front of the refname
- (e.g., `%(refname:lstrip=2)` turns `refs/tags/foo` into `foo`.
- `<N>` must be a positive integer.
+ (e.g. `%(refname:lstrip=2)` turns `refs/tags/foo` into `foo`.
+ If `<N>` is a negative number, strip as many path components as
+ necessary from the left to leave `-<N>` 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 <N>, or it becomes the full refname if
+ stripping with negative <N>. Neither is an error.
The type of the object (`blob`, `tree`, `commit`, `tag`).