From 3a42980f9e5ecc2b74c538109d4007c630881f1c Mon Sep 17 00:00:00 2001 From: Karthik Nayak Date: Tue, 10 Jan 2017 14:19:47 +0530 Subject: [PATCH] ref-filter: Do not abruptly die when using the 'lstrip=' option Currently when we use the 'lstrip=' option, if 'N' is greater than the number of components available in the refname, we abruptly end program execution by calling die(). This behavior is undesired since a single refname with few components could end program execution. To avoid this, return an empty string whenever the value 'N' is greater than the number of components available, instead of calling die(). Signed-off-by: Karthik Nayak Signed-off-by: Junio C Hamano --- Documentation/git-for-each-ref.txt | 3 +-- ref-filter.c | 3 +-- t/t6300-for-each-ref.sh | 4 ---- 3 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index b0d94deea6..04ffc35524 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -98,8 +98,7 @@ refname:: 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. If a displayed ref has fewer - components than ``, the command aborts with an error. + `` must be a positive integer. objecttype:: The type of the object (`blob`, `tree`, `commit`, `tag`). diff --git a/ref-filter.c b/ref-filter.c index cccd86f574..4fd6ef186c 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1099,8 +1099,7 @@ static const char *lstrip_ref_components(const char *refname, unsigned int len) while (remaining) { switch (*start++) { case '\0': - die(_("ref '%s' does not have %ud components to :lstrip"), - refname, len); + return ""; case '/': remaining--; break; diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index 5eb013ca21..d3d1a97db9 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -147,10 +147,6 @@ test_expect_success 'arguments to :lstrip must be positive integers' ' test_must_fail git for-each-ref --format="%(refname:lstrip=foo)" ' -test_expect_success 'stripping refnames too far gives an error' ' - test_must_fail git for-each-ref --format="%(refname:lstrip=3)" -' - test_expect_success 'Check format specifiers are ignored in naming date atoms' ' git for-each-ref --format="%(authordate)" refs/heads && git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads && -- 2.11.4.GIT