From c8d59d7e2debf9c49a055ebd29571ba0c557d780 Mon Sep 17 00:00:00 2001 From: cornfeedhobo Date: Sat, 4 Jan 2020 09:41:55 -0800 Subject: [PATCH] cleanup --- lib/utilities.bash | 87 +++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 47 deletions(-) diff --git a/lib/utilities.bash b/lib/utilities.bash index eea0decc..0f6e7d65 100644 --- a/lib/utilities.bash +++ b/lib/utilities.bash @@ -159,55 +159,48 @@ _bash-it-update-repo() { local remote="${3:-origin}" local old_pwd="${PWD}" - if [[ ! -d "${dir}" ]] ; then + cd "${dir}" || return 1 - return 1 + git fetch &> /dev/null + + declare status + status="$(git rev-list master.."${remote}/master" 2> /dev/null)" + + if [[ -n "${status}" ]]; then + + for i in $(git rev-list --merges --first-parent "master..${remote}"); do + num_of_lines=$(git log -1 --format=%B "$i" | awk 'NF' | wc -l) + if [ "$num_of_lines" -eq 1 ]; then + description="%s" + else + description="%b" + fi + git --no-pager log --format="%h: $description (%an)" -1 "$i" + done + echo "" + read -e -n 1 -p "Would you like to update to $(git log -1 --format=%h "${remote}/master")? [Y/n] " RESP + + case $RESP in + [yY]|"") + if ! git pull --rebase &> /dev/null + then + echo "${name} successfully updated." + else + echo "Error updating ${name}, please, check if your ${name} installation folder (${dir}) is clean." + fi + ;; + [nN]) + echo "Not upgrading…" + ;; + *) + echo -e "\033[91mPlease choose y or n.\033[m" + ;; + esac else - - cd "${dir}" - - git fetch &> /dev/null - - declare status - status="$(git rev-list master.."${remote}"/master 2> /dev/null)" - - if [[ -n "${status}" ]]; then - - for i in $(git rev-list --merges --first-parent master.."${remote}"); do - num_of_lines=$(git log -1 --format=%B "$i" | awk 'NF' | wc -l) - if [ "$num_of_lines" -eq 1 ]; then - description="%s" - else - description="%b" - fi - git --no-pager log --format="%h: $description (%an)" -1 "$i" - done - echo "" - read -e -n 1 -p "Would you like to update to $(git log -1 --format=%h origin/master)? [Y/n] " RESP - - case $RESP in - [yY]|"") - if ! git pull --rebase &> /dev/null - then - echo "${name} successfully updated." - else - echo "Error updating ${name}, please, check if your ${name} installation folder (${dir}) is clean." - fi - ;; - [nN]) - echo "Not upgrading…" - ;; - *) - echo -e "\033[91mPlease choose y or n.\033[m" - ;; - esac - - else - echo "${name} is up to date, nothing to do!" - fi - - cd "${old_pwd}" &> /dev/null || return 1 - + echo "${name} is up to date, nothing to do!" fi + + cd "${old_pwd}" &> /dev/null || return 1 + }