Let's consider that [] is the default test idiom when combined with if

This commit is contained in:
Jérémy Lecour 2019-03-10 22:31:34 +01:00
parent 90e3bc188f
commit 42bb96d005

View file

@ -116,7 +116,7 @@ get_repository_status() {
# tell Git where to find the repository and the work tree (no need to `cd …` there) # 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}" export GIT_DIR="${dir}/.git" GIT_WORK_TREE="${dir}"
# If the repository and the work tree exist, try to commit changes # If the repository and the work tree exist, try to commit changes
if test -d "${GIT_DIR}" && test -d "${GIT_WORK_TREE}"; then if [ -d "${GIT_DIR}" ] && [ -d "${GIT_WORK_TREE}" ]; then
CHANGED_LINES=$(${GIT_BIN} status --porcelain | wc -l | tr -d ' ') CHANGED_LINES=$(${GIT_BIN} status --porcelain | wc -l | tr -d ' ')
if [ "${CHANGED_LINES}" != "0" ]; then if [ "${CHANGED_LINES}" != "0" ]; then
STATUS=$(${GIT_BIN} status --short | tail -n 10) STATUS=$(${GIT_BIN} status --short | tail -n 10)
@ -154,13 +154,13 @@ END
} }
hook_commit() { hook_commit() {
if test -x "${GIT_BIN}"; then if [ -x "${GIT_BIN}" ]; then
# loop on possible directories managed by GIT # loop on possible directories managed by GIT
for dir in ${GIT_REPOSITORIES}; do for dir in ${GIT_REPOSITORIES}; do
# tell Git where to find the repository and the work tree (no need to `cd …` there) # 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}" export GIT_DIR="${dir}/.git" GIT_WORK_TREE="${dir}"
# If the repository and the work tree exist, try to commit changes # If the repository and the work tree exist, try to commit changes
if test -d "${GIT_DIR}" && test -d "${GIT_WORK_TREE}"; then if [ -d "${GIT_DIR}" ] && [ -d "${GIT_WORK_TREE}" ]; then
CHANGED_LINES=$(${GIT_BIN} status --porcelain | wc -l | tr -d ' ') CHANGED_LINES=$(${GIT_BIN} status --porcelain | wc -l | tr -d ' ')
if [ "${CHANGED_LINES}" != "0" ]; then if [ "${CHANGED_LINES}" != "0" ]; then
if [ "${DRY_RUN}" = "1" ]; then if [ "${DRY_RUN}" = "1" ]; then
@ -180,6 +180,7 @@ hook_commit() {
# unset environment variables to prevent accidental influence on other git commands # unset environment variables to prevent accidental influence on other git commands
unset GIT_DIR GIT_WORK_TREE unset GIT_DIR GIT_WORK_TREE
done done
if [ -n "${GIT_COMMITS}" ]; then if [ -n "${GIT_COMMITS}" ]; then
if [ "${VERBOSE}" = "1" ]; then if [ "${VERBOSE}" = "1" ]; then
printf "\n\n********** Commits ****************\n%s\n***********************************\n" "${GIT_COMMITS}" printf "\n\n********** Commits ****************\n%s\n***********************************\n" "${GIT_COMMITS}"
@ -359,11 +360,11 @@ GIT_REPOSITORIES="/etc /etc/bind"
# initialize variable # initialize variable
GIT_STATUSES="" GIT_STATUSES=""
# git statuses # git statuses
if test -x "${GIT_BIN}"; then if [ -x "${GIT_BIN}" ]; then
# loop on possible directories managed by GIT # loop on possible directories managed by GIT
for dir in ${GIT_REPOSITORIES}; do for dir in ${GIT_REPOSITORIES}; do
RESULT=$(get_repository_status "${dir}") RESULT=$(get_repository_status "${dir}")
if test -n "${RESULT}"; then if [ -n "${RESULT}" ]; then
# append diff data, without empty lines # append diff data, without empty lines
GIT_STATUSES=$(printf "%s\n%s\n" "${GIT_STATUSES}" "${RESULT}" | sed -e '/^$/d') GIT_STATUSES=$(printf "%s\n%s\n" "${GIT_STATUSES}" "${RESULT}" | sed -e '/^$/d')
fi fi
@ -385,7 +386,7 @@ if [ -z "${MESSAGE}" ] && [ "${INTERACTIVE}" = "1" ]; then
read -r MESSAGE read -r MESSAGE
fi fi
if test -z "${MESSAGE}"; then if [ -z "${MESSAGE}" ]; then
echo "no value..." echo "no value..."
exit 1 exit 1
fi fi