1#!/usr/bin/env python3 2# 3# check-dco.py: validate all commits are signed off 4# 5# Copyright (C) 2020 Red Hat, Inc. 6# 7# SPDX-License-Identifier: GPL-2.0-or-later 8 9import os 10import os.path 11import sys 12import subprocess 13 14namespace = "qemu-project" 15if len(sys.argv) >= 2: 16 namespace = sys.argv[1] 17 18cwd = os.getcwd() 19reponame = os.path.basename(cwd) 20repourl = "https://gitlab.com/%s/%s.git" % (namespace, reponame) 21 22print(f"adding upstream git repo @ {repourl}") 23subprocess.check_call(["git", "remote", "add", "check-dco", repourl]) 24subprocess.check_call(["git", "fetch", "check-dco", "master"]) 25 26ancestor = subprocess.check_output(["git", "merge-base", 27 "check-dco/master", "HEAD"], 28 universal_newlines=True) 29 30ancestor = ancestor.strip() 31 32subprocess.check_call(["git", "remote", "rm", "check-dco"]) 33 34errors = False 35 36print("\nChecking for 'Signed-off-by: NAME <EMAIL>' " + 37 "on all commits since %s...\n" % ancestor) 38 39log = subprocess.check_output(["git", "log", "--format=%H %s", 40 ancestor + "..."], 41 universal_newlines=True) 42 43if log == "": 44 commits = [] 45else: 46 commits = [[c[0:40], c[41:]] for c in log.strip().split("\n")] 47 48for sha, subject in commits: 49 50 msg = subprocess.check_output(["git", "show", "-s", sha], 51 universal_newlines=True) 52 lines = msg.strip().split("\n") 53 54 print(" %s %s" % (sha, subject)) 55 sob = False 56 for line in lines: 57 if "Signed-off-by:" in line: 58 sob = True 59 if "localhost" in line: 60 print(" ❌ FAIL: bad email in %s" % line) 61 errors = True 62 63 if not sob: 64 print(" ❌ FAIL missing Signed-off-by tag") 65 errors = True 66 67if errors: 68 print(""" 69 70❌ ERROR: One or more commits are missing a valid Signed-off-By tag. 71 72 73This project requires all contributors to assert that their contributions 74are provided in compliance with the terms of the Developer's Certificate 75of Origin 1.1 (DCO): 76 77 https://developercertificate.org/ 78 79To indicate acceptance of the DCO every commit must have a tag 80 81 Signed-off-by: REAL NAME <EMAIL> 82 83This can be achieved by passing the "-s" flag to the "git commit" command. 84 85To bulk update all commits on current branch "git rebase" can be used: 86 87 git rebase -i master -x 'git commit --amend --no-edit -s' 88 89""") 90 91 sys.exit(1) 92 93sys.exit(0) 94