From 21011c548e0b80c5fcfb7a4c0be906da9a661385 Mon Sep 17 00:00:00 2001 From: Susis Strolch Date: Thu, 12 Apr 2018 12:48:12 +0200 Subject: [PATCH] GIT hooks: post-merge, post-commit, post-checkout scripts intended as local git hooks. post-merge: - create symlink ESPEasy - if necessary - add "#define BUILD_GIT " to Custom.h - add "#define USE_CUSTOM_H" to src/ESPEasy-Globals.h post-commit: - add "#define BUILD_GIT " to Custom.h post-checkout: - on branch checkout also add "#define BUILD_GIT " --- .gitignore | 1 + hooks/post-checkout | 11 +++++++++++ hooks/post-commit | 10 ++++++++++ hooks/post-merge | 21 +++++++++++++++++++++ 4 files changed, 43 insertions(+) create mode 100755 hooks/post-checkout create mode 100755 hooks/post-commit create mode 100755 hooks/post-merge diff --git a/.gitignore b/.gitignore index 718428ff73..e94d41b924 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ ## Project ##################### lib/readme.txt src/Custom.h +/ESPEasy diff --git a/hooks/post-checkout b/hooks/post-checkout new file mode 100755 index 0000000000..00a2a7e0a3 --- /dev/null +++ b/hooks/post-checkout @@ -0,0 +1,11 @@ +#!/bin/bash +# purpose: GIT post-commit +# change value of BUILD_GIT macro +# +WORKDIR=src +CUSTOM_H=${WORKDIR}/Custom.h +GLOBAL_H=${WORKDIR}/ESPEasy-Globals.h + +# update BUILD_GIT on branch checkout +[[ $3 == 1 && -f ${CUSTOM_H} ]] && \ + sed -i.bak -e "s/\(#define BUILD_GIT\).*/\1 $(git log -1 --pretty=format:%h HEAD)/" ${CUSTOM_H} diff --git a/hooks/post-commit b/hooks/post-commit new file mode 100755 index 0000000000..e324884c3a --- /dev/null +++ b/hooks/post-commit @@ -0,0 +1,10 @@ +#!/bin/bash +# purpose: GIT post-commit +# change value of BUILD_GIT macro +# +WORKDIR=src +CUSTOM_H=${WORKDIR}/Custom.h +GLOBAL_H=${WORKDIR}/ESPEasy-Globals.h + +[[ -f ${CUSTOM_H} ]] && \ +sed -i.bak -e "s/\(#define BUILD_GIT\).*/\1 $(git log -1 --pretty=format:%h HEAD)/" ${CUSTOM_H} diff --git a/hooks/post-merge b/hooks/post-merge new file mode 100755 index 0000000000..e86deb6376 --- /dev/null +++ b/hooks/post-merge @@ -0,0 +1,21 @@ +#!/bin/bash +# build an include file to select plugins +# +WORKDIR=ESPEasy +CUSTOM_H=${WORKDIR}/Custom.h +GLOBAL_H=${WORKDIR}/ESPEasy-Globals.h + +[[ -L ${WORKDIR} ]] || ( + ln -s src ${WORKDIR} +) + +# we expect that ${CUSTOM_H} always contains a "#define BUILD_GIT" macro +[[ -f ${CUSTOM_H} ]] && ( +echo "post_merge: change BUILD_GIT" +sed -i.bak -e "s/\(#define BUILD_GIT\).*/\1 $(git log -1 --pretty=format:%h HEAD)/" ${CUSTOM_H} +) + +# uncomment if you don't want to use the Custom.h include +grep -q "^#define USE_CUSTOM_H" ${GLOBAL_H} || ( +sed -i -e "/[ \t]*#define ESPEASY_GLOBALS_H_/a #define USE_CUSTOM_H" ${GLOBAL_H} +)