diff --git a/etc-git/files/evocommit b/etc-git/files/evocommit index 0fd21076..36050d02 100644 --- a/etc-git/files/evocommit +++ b/etc-git/files/evocommit @@ -82,8 +82,14 @@ remount_repository_readonly() { is_dry_run() { test "${DRY_RUN}" = "1" } +is_verbose() { + test "${VERBOSE}" = "1" +} +is_ansible() { + test "${ANSIBLE}" = "1" +} main() { - + rc=0 lock="${GIT_DIR}/index.lock" if [ -f "${lock}" ]; then limit=$(date +"%s" -d "now - 1 hour") @@ -108,18 +114,45 @@ main() { author=$(logname) email=$(git config --get user.email) email=${email:-"${author}@evolix.net"} + # commit changes - ${GIT_BIN} add --all - ${GIT_BIN} commit --message "${MESSAGE}" --author "${author} <${email}>" --quiet + git_add_result=$(${GIT_BIN} add --all) + git_add_rc=$? + + if is_ansible; then + if [ ${git_add_rc} -ne 0 ]; then + printf "FAILED: %s\n%s" "can't add changes in ${REPOSITORY}" "${git_add_result}" + rc=1 + fi + fi + + git_commit_result=$(${GIT_BIN} commit --message "${MESSAGE}" --author "${author} <${email}>") + git_commit_rc=$? + + if is_ansible; then + if [ ${git_commit_rc} -eq 0 ]; then + printf "CHANGED: %s\n" "commit done in ${REPOSITORY} with \`${MESSAGE}'" + else + printf "FAILED: %s\n%s" "can't commit in ${REPOSITORY} \`${MESSAGE}'" "${git_commit_result}" + rc=1 + fi + fi + # remount mount point read-only if it was before if [ ${readonly_orig} -eq 1 ]; then remount_repository_readonly "${REPOSITORY}" fi fi + else + if is_ansible; then + printf "INFO: %s\n" "no commit in ${REPOSITORY}'" + fi fi unset GIT_DIR unset GIT_WORK_TREE + + exit ${rc} } # Parse options # based on https://gist.github.com/deshion/10d3cb5f88a21671e17a @@ -179,6 +212,10 @@ while :; do # print verbose information VERBOSE=1 ;; + --ansible) + # print information for Ansible + ANSIBLE=1 + ;; --) # End of all options. shift @@ -209,6 +246,7 @@ if [ -z "${REPOSITORY}" ]; then fi DRY_RUN=${DRY_RUN:-0} VERBOSE=${VERBOSE:-0} +ANSIBLE=${ANSIBLE:-0} GIT_BIN=$(command -v git) readonly GIT_BIN diff --git a/etc-git/tasks/commit.yml b/etc-git/tasks/commit.yml index f84c9b67..01530b71 100644 --- a/etc-git/tasks/commit.yml +++ b/etc-git/tasks/commit.yml @@ -7,8 +7,10 @@ register: _etc_git - name: "evocommit /etc" - command: "/usr/local/bin/evocommit --repository /etc --message \"{{ commit_message | mandatory }}\"" + command: "/usr/local/bin/evocommit --ansible --repository /etc --message \"{{ commit_message | mandatory }}\"" + changed_when: "'CHANGED:' in _etc_git_commit.stdout" ignore_errors: yes + register: _etc_git_commit when: - _etc_git.stat.exists - _etc_git.stat.isdir @@ -20,8 +22,10 @@ register: _etc_bind_git - name: "evocommit /etc/bind" - command: "/usr/local/bin/evocommit --repository /etc/bind --message \"{{ commit_message | mandatory }}\"" + command: "/usr/local/bin/evocommit --ansible --repository /etc/bind --message \"{{ commit_message | mandatory }}\"" + changed_when: "'CHANGED:' in _etc_bind_git_commit.stdout" ignore_errors: yes + register: _etc_bind_git_commit when: - _etc_bind_git.stat.exists - _etc_bind_git.stat.isdir @@ -33,8 +37,10 @@ register: _usr_share_scripts_git - name: "evocommit /usr/share/scripts" - command: "/usr/local/bin/evocommit --repository /usr/share/scripts --message \"{{ commit_message | mandatory }}\"" + command: "/usr/local/bin/evocommit --ansible --repository /usr/share/scripts --message \"{{ commit_message | mandatory }}\"" + changed_when: "'CHANGED:' in _usr_share_scripts_git_commit.stdout" ignore_errors: yes + register: _usr_share_scripts_git_commit when: - _usr_share_scripts_git.stat.exists - _usr_share_scripts_git.stat.isdir