Skip to content

Commit

Permalink
Test for generated patchname with trailing period
Browse files Browse the repository at this point in the history
There is a corner case where generated patchnames can end up with a
trailing period, which is invalid for patch (and git ref) names.

When constructing the shortened name, we now remove trailing periods
from each "word" component. A message such as "This is. My patch." will
now become "this-is-my-patch" instead of "this-is.-my-patch".

Signed-off-by: Peter Grayson <pete@jpgrayson.net>
  • Loading branch information
jpgrayson committed Dec 13, 2021
1 parent 247c93c commit 48d73dc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
5 changes: 1 addition & 4 deletions stgit/lib/stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,17 +205,14 @@ def make_name(self, raw, unique=True, lower=True, allow=(), disallow=()):

name_len = config.getint('stgit.namelength')

words = long_name.split('-')
words = [word.rstrip('.') for word in long_name.split('-')]
short_name = words[0]
for word in words[1:]:
new_name = '%s-%s' % (short_name, word)
if name_len <= 0 or len(new_name) <= name_len:
short_name = new_name
else:
break
# Strip trailing dots again because the truncation may have
# left a trailing dot, which is not allowed
short_name = re.sub(r'\.+$', '', short_name)
assert self.is_name_valid(short_name)

if not unique:
Expand Down
8 changes: 8 additions & 0 deletions t/t1003-new.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@ test_expect_success \
grep -e "Invalid patch name: \"\""
'

test_expect_success \
'Invalid patch name: trailing periods in shortened name' '
test_config stgit.namelength 10 &&
stg new -m "aaa. bbb. ccc." &&
test "$(echo $(stg top))" = "aaa-bbb" &&
stg delete --top
'

test_expect_success \
'Create a patch without giving a name' '
stg new -m yo &&
Expand Down

0 comments on commit 48d73dc

Please sign in to comment.