Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 004c86e

Browse files
albertocerroneLee-W
authored andcommitted
fix: filter git diff from commit message
When running `git commit --verbose` when using commitizen as a pre-commit we have a bug because of the diff that is incorrectly included. I have filtered out everything that is auto generated by git and that is normally excluded. See issue: #598
1 parent 45f358e commit 004c86e

File tree

1 file changed

+29
-2
lines changed

1 file changed

+29
-2
lines changed

‎commitizen/commands/check.py‎

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,8 +98,35 @@ def _get_commits(self):
9898
# Get commit messages from git log (--rev-range)
9999
return git.get_commits(end=self.rev_range)
100100

101-
def _filter_comments(self, msg: str) -> str:
102-
lines = [line for line in msg.split("\n") if not line.startswith("#")]
101+
@staticmethod
102+
def _filter_comments(msg: str) -> str:
103+
"""Filter the commit message by removing comments.
104+
105+
When using `git commit --verbose`, we exclude the diff that is going to
106+
generated, like the following example:
107+
108+
```bash
109+
...
110+
# ------------------------ >8 ------------------------
111+
# Do not modify or remove the line above.
112+
# Everything below it will be ignored.
113+
diff --git a/... b/...
114+
...
115+
```
116+
117+
Args:
118+
msg: The commit message to filter.
119+
120+
Returns:
121+
The filtered commit message without comments.
122+
"""
123+
124+
lines = []
125+
for line in msg.split("\n"):
126+
if "# ------------------------ >8 ------------------------" in line:
127+
break
128+
if not line.startswith("#"):
129+
lines.append(line)
103130
return "\n".join(lines)
104131

105132
def validate_commit_message(self, commit_msg: str, pattern: str) -> bool:

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /