extract more functions
This commit is contained in:
parent
d26aea7ab2
commit
e528a27048
|
@ -62,6 +62,31 @@ get_end_date() {
|
||||||
get_now() {
|
get_now() {
|
||||||
date +"%Y-%m-%dT%H:%M:%S%z"
|
date +"%Y-%m-%dT%H:%M:%S%z"
|
||||||
}
|
}
|
||||||
|
get_complete_hostname() {
|
||||||
|
REAL_HOSTNAME=$(get_fqdn)
|
||||||
|
if [ "${HOSTNAME}" = "${REAL_HOSTNAME}" ]; then
|
||||||
|
echo "${HOSTNAME}"
|
||||||
|
else
|
||||||
|
echo "${HOSTNAME} (${REAL_HOSTNAME})"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
get_repository_status() {
|
||||||
|
dir=$1
|
||||||
|
# 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 | tr -d ' ')
|
||||||
|
if [ "${CHANGED_LINES}" != "0" ]; then
|
||||||
|
STATUS=$(${GIT_BIN} status --short | tail -n 10)
|
||||||
|
# append diff data, without empty lines
|
||||||
|
RESULT=$(printf "%s\n%s\n" "${GIT_DIR} (last 10 lines)" "${STATUS}" | sed -e '/^$/d')
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
# unset environment variables to prevent accidental influence on other git commands
|
||||||
|
unset GIT_DIR GIT_WORK_TREE
|
||||||
|
echo "${RESULT}"
|
||||||
|
}
|
||||||
|
|
||||||
commit_repositories() {
|
commit_repositories() {
|
||||||
GIT_COMMITS=""
|
GIT_COMMITS=""
|
||||||
|
@ -164,13 +189,7 @@ done
|
||||||
set -u
|
set -u
|
||||||
|
|
||||||
# Gather information
|
# Gather information
|
||||||
REAL_HOSTNAME=$(get_fqdn)
|
HOSTNAME_TEXT=$(get_complete_hostname)
|
||||||
if [ "${HOSTNAME}" = "${REAL_HOSTNAME}" ]; then
|
|
||||||
HOSTNAME_TEXT="${HOSTNAME}"
|
|
||||||
else
|
|
||||||
HOSTNAME_TEXT="${HOSTNAME} (${REAL_HOSTNAME})"
|
|
||||||
fi
|
|
||||||
|
|
||||||
# TTY=$(get_tty)
|
# TTY=$(get_tty)
|
||||||
# WHO=$(get_who)
|
# WHO=$(get_who)
|
||||||
IP=$(get_ip)
|
IP=$(get_ip)
|
||||||
|
@ -191,21 +210,12 @@ GIT_STATUSES=""
|
||||||
if test -x "${GIT_BIN}"; then
|
if test -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)
|
RESULT=$(get_repository_status "${dir}")
|
||||||
export GIT_DIR="${dir}/.git" GIT_WORK_TREE="${dir}"
|
if test -n "${RESULT}"; then
|
||||||
# If the repository and the work tree exist, try to commit changes
|
GIT_STATUSES=$(printf "%s\n%s\n" "${GIT_STATUSES}" "${RESULT}" | sed -e '/^$/d')
|
||||||
if test -d "${GIT_DIR}" && test -d "${GIT_WORK_TREE}"; then
|
|
||||||
CHANGED_LINES=$(${GIT_BIN} status --porcelain | wc -l | tr -d ' ')
|
|
||||||
if [ "${CHANGED_LINES}" != "0" ]; then
|
|
||||||
STATUS=$(${GIT_BIN} status --short | tail -n 10)
|
|
||||||
# append diff data, without empty lines
|
|
||||||
GIT_STATUSES=$(printf "%s\n%s\n%s\n" "${GIT_STATUSES}" "${GIT_DIR} (last 10 lines)" "${STATUS}" | sed -e '/^$/d')
|
|
||||||
fi
|
|
||||||
fi
|
fi
|
||||||
# unset environment variables to prevent accidental influence on other git commands
|
|
||||||
unset GIT_DIR GIT_WORK_TREE
|
|
||||||
done
|
done
|
||||||
if [ -n "${GIT_STATUSES}" ]; then
|
if test -n "${GIT_STATUSES}"; then
|
||||||
echo "/!\ There are some uncommited changes. If you proceed, everything will be commited."
|
echo "/!\ There are some uncommited changes. If you proceed, everything will be commited."
|
||||||
echo "${GIT_STATUSES}"
|
echo "${GIT_STATUSES}"
|
||||||
echo ""
|
echo ""
|
||||||
|
|
Loading…
Reference in a new issue