[FS#361] git: add pre-receive hook to reject commits without SoB line
LEDE Bugs
lede-bugs at lists.infradead.org
Wed Dec 28 07:26:40 PST 2016
For full information about what has changed in this task, visit the URL below and click the History tab.
FS#361 - git: add pre-receive hook to reject commits without SoB line
User who did this: Stijn Tintel (stintel)
Task details edited:
-------
I recently pushed a commit without Signed-off-by. Looking at the git history, this happened before.
To avoid this in the future, add a pre-receive that checks for signed-off-by line, and rejects the push when it's not found.
Here is some (ugly) example python code that does this, and even goes 1 step further: it rejects the push if there is any commit that does not contain a SoB for the commit author. I think it makes sense to enforce this, it came up in https://github.com/lede-project/source/pull/592#issuecomment-265760007 .
#!/usr/bin/env python
import os, re, subprocess, sys
author = ""
for line in sys.stdin:
(base, commit, ref) = line.strip().split()
crange = '{}..{}'.format(base, commit)
commits = subprocess.Popen(['git', 'log', '--format=%H', crange],stdout=subprocess.PIPE)
for commit in iter(commits.stdout.readline, ''):
msg = subprocess.Popen(['git', 'log', '-n 1', commit.strip()],stdout=subprocess.PIPE)
found_sob = False
for line in iter(msg.stdout.readline, ''):
if line.startswith('Author: '):
author = re.sub('^Author: ', '', line)
continue
if line.find('Signed-off-by: '):
sob = re.sub('.*Signed-off-by: ', '', line)
if sob == author:
found_sob = True
if found_sob:
continue
else:
print('No SoB line for author in commit {}'.format(commit))
sys.exit(1)
-------
More information can be found at the following URL:
https://bugs.lede-project.org/index.php?do=details&task_id=361
More information about the lede-bugs
mailing list