-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test Signed-off-by: Nikolay Martyanov <[email protected]>
- Loading branch information
1 parent
cf0ea39
commit 80c81db
Showing
4 changed files
with
78 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
venv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
""" | ||
This script checks the commit messages in the current branch to ensure they follow the | ||
recommended format. The recommended format is as follows: | ||
* Commit message should have a subject and body | ||
* An empty line should separate the subject and body | ||
* The body should not be empty (it should contain more than just "Signed-off-by") | ||
""" | ||
|
||
import git | ||
import sys | ||
|
||
def check_commit_message(commit): | ||
message_lines = commit.message.strip().splitlines() | ||
|
||
if len(message_lines) < 2: | ||
return False, f"Commit {commit.hexsha} has no body." | ||
|
||
subject = message_lines[0].strip() | ||
second_line = message_lines[1].strip() | ||
|
||
if not subject: | ||
return False, f"Commit {commit.hexsha} has no subject." | ||
|
||
# Check if the second line is empty (indicating a blank line between subject and body) | ||
if second_line: | ||
return False, f"Commit {commit.hexsha} does not have an empty line between the subject and body." | ||
|
||
# Remove the subject and empty line to get the body | ||
body_lines = [line.strip() for line in message_lines[2:] if line.strip()] | ||
|
||
# Remove lines that are just "Signed-off-by" | ||
body_lines = [line for line in body_lines if not line.lower().startswith("signed-off-by")] | ||
|
||
if not body_lines: | ||
return False, f"Commit {commit.hexsha} has a body but only contains Signed-off-by." | ||
|
||
return True, None | ||
|
||
|
||
def main(): | ||
repo = git.Repo(search_parent_directories=True) | ||
|
||
# Fetch the latest from origin/master to ensure we are comparing correctly | ||
repo.remotes.origin.fetch('master') | ||
|
||
commits = list(repo.iter_commits('origin/master..HEAD')) | ||
|
||
if not commits: | ||
print("No commits between origin/master and HEAD.") | ||
sys.exit(1) | ||
|
||
print(f"Checking {len(commits)} commits between origin/master and HEAD...") | ||
|
||
for commit in commits: | ||
valid, error_message = check_commit_message(commit) | ||
if not valid: | ||
print(error_message) | ||
sys.exit(1) | ||
|
||
print("All commits are valid.") | ||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
gitdb==4.0.11 | ||
GitPython==3.1.43 | ||
smmap==5.0.1 |