]> code.ossystems Code Review - openembedded-core.git/commitdiff
buildhistory: improve git commit robustness
authorPaul Eggleton <paul.eggleton@linux.intel.com>
Fri, 30 Dec 2011 13:08:01 +0000 (13:08 +0000)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Tue, 3 Jan 2012 12:10:49 +0000 (12:10 +0000)
* Check if BUILDHISTORY_DIR exists before doing anything with it, in
  case no tasks that would have created it have executed
* Ensure the git repo in BUILDHISTORY_DIR is initialised with "git init"
  before attempting to do anything with it
* Check if any files have been added or changed before adding and
  committing, to avoid an error from "git commit"

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
meta/classes/buildhistory.bbclass

index 6a08db467eabd925b5612cccc1f5bd4cdb9c5b94..06d3510ddc4300905f58e268e2b97523919a0b6b 100644 (file)
@@ -342,11 +342,24 @@ def buildhistory_get_layers(d):
 
 
 buildhistory_commit() {
+       if [ ! -d ${BUILDHISTORY_DIR} ] ; then
+               # Code above that creates this dir never executed, so there can't be anything to commit
+               exit
+       fi
+
        ( cd ${BUILDHISTORY_DIR}/
-               git add ${BUILDHISTORY_DIR}/*
-               git commit ${BUILDHISTORY_DIR}/ -m "Build ${BUILDNAME} for machine ${MACHINE} configured for ${DISTRO} ${DISTRO_VERSION}" --author "${BUILDHISTORY_COMMIT_AUTHOR}" > /dev/null
-               if [ "${BUILDHISTORY_PUSH_REPO}" != "" ] ; then
-                       git push -q ${BUILDHISTORY_PUSH_REPO}
+               # Initialise the repo if necessary
+               if [ ! -d .git ] ; then
+                       git init -q
+               fi
+               # Ensure there are new/changed files to commit
+               repostatus=`git status --porcelain`
+               if [ "$repostatus" != "" ] ; then
+                       git add ${BUILDHISTORY_DIR}/*
+                       git commit ${BUILDHISTORY_DIR}/ -m "Build ${BUILDNAME} for machine ${MACHINE} configured for ${DISTRO} ${DISTRO_VERSION}" --author "${BUILDHISTORY_COMMIT_AUTHOR}" > /dev/null
+                       if [ "${BUILDHISTORY_PUSH_REPO}" != "" ] ; then
+                               git push -q ${BUILDHISTORY_PUSH_REPO}
+                       fi
                fi) || true
 }