From 9a4201efc17ccf010fc4817a068c8c59173d3f21 Mon Sep 17 00:00:00 2001 From: Will Woods Date: Tue, 17 Nov 2020 13:29:51 -0500 Subject: [PATCH] suppress 'nothing added to commit..' messages from countme-update.sh Right now countme-update.sh tries to `git commit -a` whether or not anything has changed, which results in this output whenever there's no new changes to commit: On branch master Untracked files: (use "git add ..." to include in what will be committed) raw.db totals.db nothing added to commit but untracked files present (use "git add" to track) This commit tweaks `countme-update.sh` so that it only attempts `git commit` if there are changes to be committed - i.e. when `git diff` returns 1. Signed-off-by: Will Woods --- roles/web-data-analysis/files/countme-update.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/roles/web-data-analysis/files/countme-update.sh b/roles/web-data-analysis/files/countme-update.sh index ad94105693..a9d2c083e5 100644 --- a/roles/web-data-analysis/files/countme-update.sh +++ b/roles/web-data-analysis/files/countme-update.sh @@ -15,6 +15,9 @@ PUBLIC_TOTALS_CSV=$PUBLIC_DATA_DIR/totals.csv UPDATE_RAWDB=countme-update-rawdb.sh UPDATE_TOTALS=countme-update-totals.sh +# How we're gonna call git - our local repo dir is LOCAL_DATA_DIR +_GIT="git -C $LOCAL_DATA_DIR" + # Copy with atomic overwrite atomic_copy() { local src="$1" dst="$2" @@ -94,12 +97,13 @@ set -e _run $UPDATE_RAWDB --rawdb $RAW_DB _run $UPDATE_TOTALS --rawdb $RAW_DB --totals-db $TOTALS_DB --totals-csv $TOTALS_CSV -# Update local git repo +# If needed: init local git repo and mark file(s) to be tracked therein if [ ! -d $LOCAL_DATA_DIR/.git ]; then - _run git init $LOCAL_DATA_DIR - _run git -C $LOCAL_DATA_DIR add -N $(realpath $TOTALS_CSV --relative-to $LOCAL_DATA_DIR) + _run $_GIT init + _run $_GIT add -N $(realpath $TOTALS_CSV --relative-to $LOCAL_DATA_DIR) fi -_run git -C $LOCAL_DATA_DIR commit -a -m "$(date -u +%F) update" +# If any tracked files were updated, commit changes +_run $_GIT diff --quiet || _run $_GIT commit -a -m "$(date -u +%F) update" # Copy new data into place _run atomic_copy $TOTALS_DB $PUBLIC_TOTALS_DB