From 9b7ce2abf2dbe46f282b6616eb27dddfa1459023 Mon Sep 17 00:00:00 2001 From: Alexander Lutay Date: Fri, 2 Nov 2018 12:31:01 +0100 Subject: [PATCH] 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 --- functions/main | 9 +++++++++ scripts/apply | 3 +-- scripts/build | 2 +- scripts/clean | 3 +-- scripts/commit | 3 +-- scripts/etckeeper | 3 +-- scripts/initialise | 2 +- scripts/status | 6 ++---- 8 files changed, 17 insertions(+), 14 deletions(-) diff --git a/functions/main b/functions/main index 8a83e5ea..ddd4eb16 100644 --- a/functions/main +++ b/functions/main @@ -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 ################################################################# diff --git a/scripts/apply b/scripts/apply index be3fb2b8..4fde2b8c 100755 --- a/scripts/apply +++ b/scripts/apply @@ -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 diff --git a/scripts/build b/scripts/build index b759fcfb..8e294d87 100755 --- a/scripts/build +++ b/scripts/build @@ -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 diff --git a/scripts/clean b/scripts/clean index 9e23899e..c0dc020a 100755 --- a/scripts/clean +++ b/scripts/clean @@ -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 diff --git a/scripts/commit b/scripts/commit index 418e208e..057a9b1a 100755 --- a/scripts/commit +++ b/scripts/commit @@ -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)]\"" diff --git a/scripts/etckeeper b/scripts/etckeeper index 8addb8c3..39253f73 100755 --- a/scripts/etckeeper +++ b/scripts/etckeeper @@ -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)\"" diff --git a/scripts/initialise b/scripts/initialise index 47a5aee6..0ad65af0 100755 --- a/scripts/initialise +++ b/scripts/initialise @@ -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 diff --git a/scripts/status b/scripts/status index cababd9a..b5b2f0f1 100755 --- a/scripts/status +++ b/scripts/status @@ -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]')"