buildhistory: improve git commit robustness

* 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"

(From OE-Core rev: 8eff4fea13317a741114f2a2e8e228d0155ba64c)

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Paul Eggleton 2011-12-30 13:08:01 +00:00 committed by Richard Purdie
parent f724b7bc2e
commit a57cda0f80
1 changed files with 17 additions and 4 deletions

View 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
}