Skip to content

Commit 3a42980

Browse files
KarthikNayakgitster
authored andcommitted
ref-filter: Do not abruptly die when using the 'lstrip=<N>' option
Currently when we use the 'lstrip=<N>' 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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 17938f1 commit 3a42980

File tree

3 files changed

+2
-8
lines changed

3 files changed

+2
-8
lines changed

Documentation/git-for-each-ref.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,7 @@ refname::
9898
abbreviation mode. If `lstrip=<N>` is appended, strips `<N>`
9999
slash-separated path components from the front of the refname
100100
(e.g., `%(refname:lstrip=2)` turns `refs/tags/foo` into `foo`.
101-
`<N>` must be a positive integer. If a displayed ref has fewer
102-
components than `<N>`, the command aborts with an error.
101+
`<N>` must be a positive integer.
103102

104103
objecttype::
105104
The type of the object (`blob`, `tree`, `commit`, `tag`).

ref-filter.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,8 +1099,7 @@ static const char *lstrip_ref_components(const char *refname, unsigned int len)
10991099
while (remaining) {
11001100
switch (*start++) {
11011101
case '\0':
1102-
die(_("ref '%s' does not have %ud components to :lstrip"),
1103-
refname, len);
1102+
return "";
11041103
case '/':
11051104
remaining--;
11061105
break;

t/t6300-for-each-ref.sh

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@ test_expect_success 'arguments to :lstrip must be positive integers' '
147147
test_must_fail git for-each-ref --format="%(refname:lstrip=foo)"
148148
'
149149

150-
test_expect_success 'stripping refnames too far gives an error' '
151-
test_must_fail git for-each-ref --format="%(refname:lstrip=3)"
152-
'
153-
154150
test_expect_success 'Check format specifiers are ignored in naming date atoms' '
155151
git for-each-ref --format="%(authordate)" refs/heads &&
156152
git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&

0 commit comments

Comments
 (0)