Skip to content
This repository was archived by the owner on Sep 5, 2023. It is now read-only.

Commit 092483b

Browse files
committed
fix(formatting): Correct string capitalisation
The description and body fields were being modifed to drop their capitals throughout the text when capitalising the first letter. This was behaviour of the built in str.capitalize() method. A new utility function has been created which performs the desired behaviour of purely upper casing the first character in a string. Fix #25 Fix #28
1 parent 84f33fa commit 092483b

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

gitcommit/gitcommit.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
)
3939
from .completers import TypeCompleter, FooterCompleter
4040
from .updater import check_for_update
41+
from .utils import capitaliseFirst
4142

4243
IS_BREAKING_CHANGE = None # default for global variable
4344
try:
@@ -218,7 +219,7 @@ def add_description(commit_msg):
218219

219220
# Sanitise
220221
c_descr = c_descr.strip() # remove whitespace
221-
c_descr = c_descr.capitalize() # capital first letter
222+
c_descr = capitaliseFirst(c_descr) # capital first letter
222223
if c_descr[-1] == ".":
223224
c_descr = c_descr[:-1] # remove period if last character
224225
c_descr = c_descr.strip() # remove further whitespace
@@ -255,7 +256,7 @@ def add_body(commit_msg):
255256

256257
c_body = session.prompt(ANSI(text), validator=body_validator)
257258
c_body = c_body.strip() # remove leading/trailing whitespace
258-
c_body = c_body.capitalize() # capital first letter
259+
c_body = capitaliseFirst(c_body) # capital first letter
259260

260261
if IS_BREAKING_CHANGE:
261262
full_body = "BREAKING CHANGE: " + c_body

gitcommit/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
def capitaliseFirst(string_in: str) -> str:
2+
"""A utility function that will capitalise only the first character in a string. Unlike str.capitalize() which will lower all other characters in the string."""
3+
if len(string_in) == 0:
4+
return ""
5+
elif len(string_in) == 1:
6+
return string_in[0].upper()
7+
elif len(string_in) > 1:
8+
return string_in[0].upper() + string_in[1:]

0 commit comments

Comments
 (0)