Ajout des infos de diff avant la saisie du message

This commit is contained in:
Jérémy Lecour 2018-09-20 15:24:46 +02:00 committed by Jérémy Lecour
parent 67a0cd5f48
commit 94a143b874

View file

@ -28,6 +28,8 @@ PATH=${PATH}:/usr/sbin
SENDMAIL_BIN=$(command -v sendmail)
GIT_BIN=$(command -v git)
GIT_REPOSITORIES="/etc /etc/bind"
WHO=$(LC_ALL=C who -m)
USER=$(echo ${WHO} | cut -d" " -f1)
IP=$(echo ${WHO} | cut -d" " -f6 | sed -e "s/^(// ; s/)$//")
@ -36,6 +38,33 @@ END_DATE=$(date +"%Y %b %d %H:%M")
# we can't use "date --iso8601" because this options is not available everywhere
NOW_ISO=$(date +"%Y-%m-%dT%H:%M:%S%z")
# git diffs
GIT_DIFFS=""
if test -x "${GIT_BIN}"; then
# loop on possible directories managed by GIT
for dir in ${GIT_REPOSITORIES}; do
# tell Git where to find the repository and the work tree (no need to `cd …` there)
export GIT_DIR="${dir}/.git" GIT_WORK_TREE="${dir}"
# If the repository and the work tree exist, try to commit changes
if test -d "${GIT_DIR}" && test -d "${GIT_WORK_TREE}"; then
CHANGED_LINES=$(${GIT_BIN} status --porcelain | wc -l)
if [ "${CHANGED_LINES}" != "0" ]; then
DIFF=$(${GIT_BIN} diff --stat | tail -n 10)
# append diff data, without empty lines
GIT_DIFFS=$(echo "${GIT_DIFFS}\n${GIT_DIR} (last 10 lines)\n${DIFF}\n" | sed -e '/^$/d')
fi
fi
# unset environment variables to prevent accidental influence on other git commands
unset GIT_DIR GIT_WORK_TREE
done
if [ -n "${GIT_DIFFS}" ]; then
echo "/!\ There are some uncommited changes. If you proceed, everything will be commited."
echo "${GIT_DIFFS}"
echo ""
fi
fi
# get input from stdin
echo "Please, enter details about your maintenance"
read TEXTE
@ -69,12 +98,12 @@ GIT_COMMITS=""
if test -x "${GIT_BIN}"; then
# loop on possible directories managed by GIT
for dir in /etc /etc/bind; do
for dir in ${GIT_REPOSITORIES}; do
# tell Git where to find the repository and the work tree (no need to `cd …` there)
export GIT_DIR="${dir}/.git" GIT_WORK_TREE="${dir}"
# If the repository and the work tree exist, try to commit changes
if test -d "${GIT_DIR}" && test -d "${GIT_WORK_TREE}"; then
CHANGED_LINES=$(git status --porcelain | wc -l)
CHANGED_LINES=$(${GIT_BIN} status --porcelain | wc -l)
if [ "${CHANGED_LINES}" != "0" ]; then
${GIT_BIN} add --all
${GIT_BIN} commit --message "${TEXTE}" --author="${USER} <${USER}@evolix.net>" --quiet