Bug 13703

Summary: Create git update and pre-commit hook to prevent Groups.io e-mail in commit messages
Product: [Infrastructure] Infrastructure General Reporter: Michael Halstead <mhalstead>
Component: infrastructure-generalAssignee: Richard Purdie <richard.purdie>
Status: RESOLVED FIXED QA Contact:
Severity: normal    
Priority: High CC: akuster808, randy.macleod
Version: 3.1   
Target Milestone: 3.1 M3   
Hardware: x86   
OS: Multiple   
Whiteboard:
OS type for building Yocto: --- Type of Regression: ---
Verified: Documentation change: Don't know

Description Michael Halstead 2019-12-12 17:26:57 UTC
In order to comply with DMARC Groups.io will rewrite the from lines of certain e-mails. We don't want these mangled e-mail addresses in our git repositories.

Write an update hook to prevent these from getting into the official repos.

Write a pre-commit hook maintainers can add to local repos to prevent bad addresses from being committed in the first place.
Comment 1 Michael Halstead 2020-01-30 17:17:30 UTC
I'm going to try to create these starting with the hooks below.

https://raw.githubusercontent.com/asadana/Git-Check-Author/master/pre-commit

https://raw.githubusercontent.com/asadana/Git-Check-Author/master/pre-receive
Comment 2 Richard Purdie 2020-02-18 22:40:46 UTC
I don't know how to get git to reject local commits with incorrect addresses in as the git committer name isn't passed to any of the suitable hooks. I did have more success with the server side blocking. The poky repo now has a pre-receive hook that successfully prevents 'bad' user names from being pushed.
Comment 3 Richard Purdie 2020-02-18 23:18:10 UTC
Locally the best I've been able to come up with is a post-applypatch which does:

#!/bin/bash
authorName=$(git log -1 --pretty=format:%an HEAD)
if [[ "$authorName" == *"Openembedded-core"* ]]; then
    echo "####################################################################"
    echo "####################################################################"
    echo "Invalid Author $authorName"
    echo "####################################################################"
    echo "####################################################################"
    git reset HEAD~1 --hard
fi
Comment 4 Michael Halstead 2020-02-19 23:13:12 UTC
Richard's pre-receive hook is deployed on the OpenEmbeddeded and Yocto Project servers now.
Comment 5 Richard Purdie 2020-02-19 23:22:41 UTC
When applying patches I'm finding the easiest fix when hitting the warning is to swap the From and Reply-To: headers and git-am will then process the emails correctly. Ultimately I'll script that.
Comment 6 Armin Kuster 2020-02-23 23:06:07 UTC
I just tried pushing to stable/zeus-nut and got this error. The offending commit is already in mainline zeus.

akuster@akuster-ThinkPad-T460s:~/oss/stable/poky$ git push -f ssh://git@git.yoctoproject.org/poky-contrib.git  stable/zeus-nut:stable/zeus-nut
Counting objects: 399, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (187/187), done.
Writing objects: 100% (399/399), 77.11 KiB | 12.85 MiB/s, done.
Total 399 (delta 296), reused 284 (delta 206)
remote: Resolving deltas: 100% (296/296), completed with 100 local objects.
remote: ##############################################
remote: Invalid author Taras Kondratiuk via Openembedded-core
remote: ##############################################
To ssh://git.yoctoproject.org/poky-contrib.git
 ! [remote rejected]         stable/zeus-nut -> stable/zeus-nut (pre-receive hook declined)
Comment 7 Michael Halstead 2020-02-24 17:08:05 UTC
Armin, are you confirming this is working as expected or reporting a problem?

Separately you need to update your remote to ssh://git@push.yoctoproject.org/poky-contrib.git to ensure reliable pushes in the future.
Comment 8 akuster 2020-02-24 17:17:39 UTC
(In reply to comment #7)
> Armin, are you confirming this is working as expected or reporting a problem?
> 
> Separately you need to update your remote to
> ssh://git@push.yoctoproject.org/poky-contrib.git to ensure reliable pushes
> in the future.

I reported a problem. Richard fixed it and things are good now.

thanks.
Comment 9 Richard Purdie 2020-03-02 16:28:17 UTC
I think given the hooks installed and updated workflow tweaks people can use we've resolved this as best we can now.