[FS#361] git: add pre-receive hook to reject commits without SoB line
LEDE Bugs
lede-bugs at lists.infradead.org
Wed Dec 28 06:37:37 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()
diff = subprocess.Popen(['git', 'log', '-n 1', commit],stdout=subprocess.PIPE)
for line in iter(diff.stdout.readline, ''):
if line.startswith('Author: '):
author = re.sub('^Author: ', '', line)
print('Found author: {}').format(author)
continue
if line.find('Signed-off-by: '):
sob = re.sub('.*Signed-off-by: ', '', line)
if sob == author:
print('Found SoB line for author')
sys.exit(0)
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