TT#44969 Extract git status check to common function (for further refactoring)

'git status' output has been changed in 2.9 which causes some troubles for us
(we didn't change all the places, we missed ngcpcfg-ha.git repo,
better to use common code in all the places).

Change-Id: Ie664af89ee6d6b31fb3011e763107c41bf4cf00f
changes/50/24550/3
Alexander Lutay 8 years ago
parent ffa7452139
commit 9b7ce2abf2

@ -349,6 +349,15 @@ record_commit_id() {
echo "$latest_commit" > "${STATE_FILES_DIR}/build"
fi
}
is_git_clean() {
log_debug "git status | grep -qE 'working (directory|tree) clean'"
if git status | grep -qE 'working (directory|tree) clean'; then
return 0
else
return 1
fi
}
## }}}
## END OF FILE #################################################################

@ -23,8 +23,7 @@ check_for_outstanding_commits() {
log_debug "cd $NGCPCTL_MAIN"
cd "$NGCPCTL_MAIN"
log_debug "git status | grep -qE 'working (directory|tree) clean'"
if git status | grep -qE 'working (directory|tree) clean' ; then
if is_git_clean ; then
return 1 # nothing to commit
else
return 0 # outstanding commits

@ -81,7 +81,7 @@ if ! $MODIFIED_ONLY ; then
else
log_info "Considering modified files only due to --modified-only option."
if git status | grep -qE 'working (directory|tree) clean' ; then
if is_git_clean ; then
log_info "No changes found, nothing to do."
exit 0
fi

@ -75,8 +75,7 @@ clean_ensure_branch_master () {
clean_tracked() {
log_info "Removing all local changes (if any):"
log_debug "git status | grep -qE 'working (directory|tree) clean'"
if git status | grep -qE 'working (directory|tree) clean' ; then
if is_git_clean ; then
log_info "OK: no local changes found, nothing to clean here."
return 0
fi

@ -67,8 +67,7 @@ else
msg="$*"
fi
log_debug "git status | grep -qE 'working (directory|tree) clean'"
if git status | grep -qE 'working (directory|tree) clean' ; then
if is_git_clean ; then
log_info "OK: nothing to commit."
else
log_debug "git add . ; git commit -a -m \"\$msg [\$(date --rfc-3339=ns)]\""

@ -35,8 +35,7 @@ if ! [ -d .git ] ; then
fi
log_info "Checking state of /etc files"
log_debug 'git status | grep -q "working directory clean"'
if git status | grep -qE 'working (directory|tree) clean' ; then
if is_git_clean ; then
log_info "OK: nothing to commit."
else
log_debug "etckeeper commit \"ngcpcfg apply on \$(date)\""

@ -53,7 +53,7 @@ fi
log_debug "git add ."
git add .
if ! git status | grep -qE 'working (directory|tree) clean' ; then
if ! is_git_clean ; then
log_debug "git commit -a -m \"initial version of ngcpcfg on $HNAME\""
git commit -a -m "initial version of ngcpcfg on $HNAME" >/dev/null
fi

@ -60,8 +60,7 @@ check_local_state() {
log_info "OK: has been initialised already"
log_info "Checking state of configuration files:"
log_debug "git status | grep -qE 'working (directory|tree) clean"
if git status | grep -qE 'working (directory|tree) clean' ; then
if is_git_clean ; then
log_info "OK: nothing to commit"
else
if git diff-index --name-only HEAD | grep -q . ; then
@ -87,8 +86,7 @@ check_etc_state() {
cd /etc
log_info "Checking state of /etc files:"
log_debug "git status | grep -qE 'working (directory|tree) clean'"
if git status | grep -qE 'working (directory|tree) clean' ; then
if is_git_clean ; then
log_info "OK: nothing to commit"
else
log_info "ACTION_NEEDED: configuration files changed (execute 'etckeeper commit [message]')"

Loading…
Cancel
Save