Skip to content

Commit

Permalink
GIT hooks: post-merge, post-commit, post-checkout
Browse files Browse the repository at this point in the history
scripts intended as local git hooks.
post-merge:
- create symlink ESPEasy - if necessary
- add "#define BUILD_GIT <git revision>" to Custom.h
- add "#define USE_CUSTOM_H" to src/ESPEasy-Globals.h

post-commit:
- add "#define BUILD_GIT <git revision>" to Custom.h

post-checkout:
- on branch checkout also add "#define BUILD_GIT <git revision>"
  • Loading branch information
Susis Strolch committed Apr 14, 2018
1 parent a151e60 commit 21011c5
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@
## Project #####################
lib/readme.txt
src/Custom.h
/ESPEasy
11 changes: 11 additions & 0 deletions hooks/post-checkout
Original file line number Diff line number Diff line change
@@ -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}
10 changes: 10 additions & 0 deletions hooks/post-commit
Original file line number Diff line number Diff line change
@@ -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}
21 changes: 21 additions & 0 deletions hooks/post-merge
Original file line number Diff line number Diff line change
@@ -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}
)

0 comments on commit 21011c5

Please sign in to comment.