From e020160d43983b8b268796dd4a87f8bd60b10c99 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Wed, 8 Jan 2014 18:41:04 +0100 Subject: [PATCH 1/3] Detect unstaged changes Abort when there are unstaged changes in the repository being processed. --- update-trackers.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/update-trackers.sh b/update-trackers.sh index ed554f3..37474dd 100755 --- a/update-trackers.sh +++ b/update-trackers.sh @@ -47,7 +47,7 @@ function usage() { function process_error() { - echo "ERROR: $1" + echo -e "\nERROR: $1" if [ -n "$REPO" ] then echo "Fix issues in repository '$REPO' and try again" @@ -113,6 +113,10 @@ do cd $DIR_NAME/$REPO 2>/dev/null || process_error "repository '$REPO' does not exist in '$DIR_NAME' or is not accessible" + # Detect if there are unstaged changes in the repository's current branch + git diff-index --name-status --exit-code HEAD || + process_error "There are unstaged changes" + # First update the reference branch, pull changes from upstream echo "- Pulling upstream changes into reference branch '$UPDATE_BRANCH'" git checkout $UPDATE_BRANCH || From ad083bb1ea01593290f6989fba1a6bd4cf7355b3 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Wed, 8 Jan 2014 19:19:38 +0100 Subject: [PATCH 2/3] Improve handling of unstaged changes Script now asks user if changes should be discarded (git co -- .) instead of simply aborting in error. --- update-trackers.sh | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/update-trackers.sh b/update-trackers.sh index 37474dd..42b586c 100755 --- a/update-trackers.sh +++ b/update-trackers.sh @@ -47,7 +47,12 @@ function usage() { function process_error() { - echo -e "\nERROR: $1" + echo -ne "\nERROR: " + if [ -n "$1" ] + then + echo $1 + fi + if [ -n "$REPO" ] then echo "Fix issues in repository '$REPO' and try again" @@ -114,8 +119,20 @@ do process_error "repository '$REPO' does not exist in '$DIR_NAME' or is not accessible" # Detect if there are unstaged changes in the repository's current branch - git diff-index --name-status --exit-code HEAD || - process_error "There are unstaged changes" + git diff-index --name-status --exit-code HEAD + if [ $? -ne 0 ] + then + echo -e "\nThere are unstaged changes" + read -n 1 -p "Would you like to discard them ? " + echo + if [ "$(echo ${REPLY} | tr "[:upper:]" "[:lower:]")" = "y" ] + then + echo "Discarding changes" + git checkout -- . || process_error + else + process_error "can't proceed with unstaged changes" + fi + fi # First update the reference branch, pull changes from upstream echo "- Pulling upstream changes into reference branch '$UPDATE_BRANCH'" @@ -149,12 +166,13 @@ do grep "^\s*\$g_version_suffix" $CONFIG_FILE >/dev/null if [ $? -eq 0 ] then - echo "Updating existing config" + echo "Updating existing config file" sed -r -i.bak "s/^(\s*\\\$g_version_suffix\s*=\s*[\"']).*([\"'])/\1$VERSION_SUFFIX\2/" $CONFIG_FILE else echo "Config option does not exist, appending it to end of file" echo "\$g_version_suffix = '$VERSION_SUFFIX';" >>$CONFIG_FILE fi + # Syntax check the modified config file, just in case php -l $CONFIG_FILE || process_error "Invalid $CONFIG_FILE" From a4c6e9ad787c076d2a27c176be3f6d9756efbc10 Mon Sep 17 00:00:00 2001 From: Damien Regad Date: Wed, 8 Jan 2014 19:30:42 +0100 Subject: [PATCH 3/3] Delete 'admin' dir at end of process Asks the user if they want to delete the 'admin' directory, and if not displays a warning to remind them to do it manually afterwards. --- update-trackers.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/update-trackers.sh b/update-trackers.sh index 42b586c..46245db 100755 --- a/update-trackers.sh +++ b/update-trackers.sh @@ -177,6 +177,17 @@ do php -l $CONFIG_FILE || process_error "Invalid $CONFIG_FILE" + echo + read -n 1 -p "The 'admin' directory should be deleted. Would you like to do it now ? " + echo + ADMIN_DIR=$PWD/admin + if [ "$(echo ${REPLY} | tr "[:upper:]" "[:lower:]")" = "y" ] + then + rm -rvf $ADMIN_DIR + else + echo "WARNING: Remember to delete it after completing the upgrade (rm -rf $ADMIN_DIR)" + fi + echo -e "\nRepository '$REPO' updated successfully\n" cd - >/dev/null done