3 # check-dco.py: validate all commits are signed off
5 # Copyright (C) 2020 Red Hat, Inc.
7 # SPDX-License-Identifier: GPL-2.0-or-later
14 namespace
= "qemu-project"
15 if len(sys
.argv
) >= 2:
16 namespace
= sys
.argv
[1]
19 reponame
= os
.path
.basename(cwd
)
20 repourl
= "https://gitlab.com/%s/%s.git" % (namespace
, reponame
)
22 subprocess
.check_call(["git", "remote", "add", "check-dco", repourl
])
23 subprocess
.check_call(["git", "fetch", "check-dco", "master"],
24 stdout
=subprocess
.DEVNULL
,
25 stderr
=subprocess
.DEVNULL
)
27 ancestor
= subprocess
.check_output(["git", "merge-base",
28 "check-dco/master", "HEAD"],
29 universal_newlines
=True)
31 ancestor
= ancestor
.strip()
33 subprocess
.check_call(["git", "remote", "rm", "check-dco"])
37 print("\nChecking for 'Signed-off-by: NAME <EMAIL>' " +
38 "on all commits since %s...\n" % ancestor
)
40 log
= subprocess
.check_output(["git", "log", "--format=%H %s",
42 universal_newlines
=True)
47 commits
= [[c
[0:40], c
[41:]] for c
in log
.strip().split("\n")]
49 for sha
, subject
in commits
:
51 msg
= subprocess
.check_output(["git", "show", "-s", sha
],
52 universal_newlines
=True)
53 lines
= msg
.strip().split("\n")
55 print("🔍 %s %s" % (sha
, subject
))
58 if "Signed-off-by:" in line
:
60 if "localhost" in line
:
61 print(" ❌ FAIL: bad email in %s" % line
)
65 print(" ❌ FAIL missing Signed-off-by tag")
71 ❌ ERROR: One or more commits are missing a valid Signed-off-By tag.
74 This project requires all contributors to assert that their contributions
75 are provided in compliance with the terms of the Developer's Certificate
78 https://developercertificate.org/
80 To indicate acceptance of the DCO every commit must have a tag
82 Signed-off-by: REAL NAME <EMAIL>
84 This can be achieved by passing the "-s" flag to the "git commit" command.
86 To bulk update all commits on current branch "git rebase" can be used:
88 git rebase -i master -x 'git commit --amend --no-edit -s'