Skip to contentSkip to conversation

sanity: add function to check for git config user

PATCH Superseded Stephano Cetola 2 participants 2 messages Oct 2, 2016

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 sanity: add function to check for git config user

If attempting to patch a git repo without a proper git config setup, an error will occur saying user.name/user.email are needed by git am/apply. After 0f698dfd1c8bbc0d53ae7977e26685a7a3df52a3, it was simple enough to reproduce this error by creating a kernel patch and using a container to build.

This patch abstracts out functionality that existed in buildhistory for use in other classes. It also adds a call to this functionality to the kernel-yocto class.

---
 meta/classes/buildhistory.bbclass | 13 ++++---------
 meta/classes/kernel-yocto.bbclass |  2 ++
 meta/classes/sanity.bbclass       | 15 +++++++++++++++
 3 files changed, 21 insertions(+), 9 deletions(-)
meta/classes/buildhistory.bbclass +4 -9
index 6e5de0e..ed79029 100644
@@ -688,6 +688,7 @@ END
 	rm $commitmsgfile
 }
 
+inherit sanity
 buildhistory_commit() {
 	if [ ! -d ${BUILDHISTORY_DIR} ] ; then
 		# Code above that creates this dir never executed, so there can't be anything to commit
@@ -708,15 +709,9 @@ END
 			git tag -f build-minus-2 build-minus-1 > /dev/null 2>&1 || true
 			git tag -f build-minus-1 > /dev/null 2>&1 || true
 		fi
-		# If the user hasn't set up their name/email, set some defaults
-		# just for this repo (otherwise the commit will fail with older
-		# versions of git)
-		if ! git config user.email > /dev/null ; then
-			git config --local user.email "buildhistory@${DISTRO}"
-		fi
-		if ! git config user.name > /dev/null ; then
-			git config --local user.name "buildhistory"
-		fi
+
+		check_git_config "buildhistory"
+
 		# Check if there are new/changed files to commit (other than metadata-revs)
 		repostatus=`git status --porcelain | grep -v " metadata-revs$"`
 		HOSTNAME=`hostname 2>/dev/null || echo unknown`
meta/classes/kernel-yocto.bbclass +2 -0
index 53659f2..035edeb 100644
@@ -156,9 +156,11 @@ do_kernel_metadata() {
 	fi
 }
 
+inherit sanity
 do_patch() {
 	cd ${S}
 
+	check_git_config "kernel-yocto"
 	meta_dir=$(kgit --meta)
 	(cd ${meta_dir}; ln -sf patch.queue series)
 	if [ -f "${meta_dir}/series" ]; then
meta/classes/sanity.bbclass +15 -0
index 7682ffb..40033ab 100644
@@ -1023,3 +1023,18 @@ python check_sanity_eventhandler() {
 
     return
 }
+
+# If the user hasn't set up their name/email, set some defaults
+check_git_config() {
+	if [ -z "$1" ]; then
+		name="OE"
+	else
+		name="$1"
+	fi
+	if ! git config user.email > /dev/null ; then
+        	git config --local user.email "${name}@${DISTRO}"
+	fi
+	if ! git config user.name > /dev/null ; then
+        	git config --local user.name "${name}"
+	fi
+}
Signature · 1 line
2.10.0
#1 lore raw

Hi Stephano,

Quoted 9 lines · On Sun, 02 Oct 2016 15:17:31 Stephano Cetola wrote:

If attempting to patch a git repo without a proper git config setup, an error will occur saying user.name/user.email are needed by git am/apply. After 0f698dfd1c8bbc0d53ae7977e26685a7a3df52a3, it was simple enough to reproduce this error by creating a kernel patch and using a container to build.

This patch abstracts out functionality that existed in buildhistory for use in other classes. It also adds a call to this functionality to the kernel-yocto class.

For the logic implemented by patch.bbclass, we already fixed this by forcing a dummy value for the commit name and email (since it's not actually the user doing the commit, it's the build system). If we're adding this to cover similar automated scenarios where the user isn't the one making the commit, then I think we should be fixing those to do the same instead.

Cheers,
Paul

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre