Re: [AD] switching to git, 2012 edition |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Mon, 2 Jul 2012 18:48:51 +0200
Elias Pschernig <info@xxxxxxxxxx> wrote:
>
> Also, I'm thinking about a hook which makes sure that both user.name
> and user.email of the committer are in authors.txt and otherwise
> reject the push. I see myself using random names whenever I commit
> from some place besides my standard git folder otherwise. (Not sure
> that is a problem...)
This one for example.
#!/usr/bin/env python
import sys, re, subprocess, os
# get the SourceForge user who is pushing
user = os.environ["USER"]
email = user + "@users.sourceforge.net"
# go through all pushed references
for row in sys.stdin:
m = re.compile(r"^([0-9a-f]+)\s+([0-9a-f]+)\s+(\S+)$").match(row)
if not m: continue
oldver, curver, ref = m.groups()
# get info about the change
p = subprocess.Popen(["git", "rev-list",
"--pretty=format:%an:%ae:%cn:%ce",
oldver + ".." + curver], stdout = subprocess.PIPE)
stdout, stderr = p.communicate()
if p.returncode: continue
# go through all contained commits
for info in stdout.splitlines():
if info.startswith("commit "): continue
# do our check
aname, aemail, cname, cemail = info.split(":")
if cemail != email:
print("Please set user.email in .git/config to " + email +
" (and make sure your user.name is correct)!")
print("You tried to commit as " + cname + " (" + cemail + ")")
print("After that fix the commit with the following command and push again.")
print("git commit --amend --reset-author")
sys.exit(1)