From 96295e92a5668b0db607b3e7c875085eb982daed Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Mon, 22 Jun 2020 16:19:37 +0300 Subject: [PATCH 01/13] lib: Improve bash-it update so it can update to latest tag --- lib/helpers.bash | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index d4e85fc9..51d6517b 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -79,7 +79,7 @@ bash-it () _bash-it-search $component "$@" return;; update) - func=_bash-it_update;; + func=_bash-it_update-$component;; migrate) func=_bash-it-migrate;; version) @@ -155,26 +155,49 @@ _bash-it-plugins () _bash-it-describe "plugins" "a" "plugin" "Plugin" } -_bash-it_update() { +_bash-it_update-dev() { + _about 'updates Bash-it to the latest master' + _group 'lib' + + _bash-it_update- dev +} + +_bash-it_update-stable() { + _about 'updates Bash-it to the latest tag' + _group 'lib' + + _bash-it_update- stable +} + +_bash-it_update-() { _about 'updates Bash-it' + _param '1: What kind of update to do (stable|dev)' _group 'lib' local old_pwd="${PWD}" cd "${BASH_IT}" || return - if [ -z $BASH_IT_REMOTE ]; then + if [ -z "$BASH_IT_REMOTE" ]; then BASH_IT_REMOTE="origin" fi + # Defaults to stable update + if [ -z "$1" ] || [ "$1" == "stable" ]; then + version="stable" + TARGET=$(git describe --tags "$(git rev-list --tags --max-count=1)") + else + version="dev" + TARGET=${BASH_IT_REMOTE}/master + fi - git fetch &> /dev/null + git fetch $BASH_IT_REMOTE --tags &> /dev/null declare status - status="$(git rev-list master..${BASH_IT_REMOTE}/master 2> /dev/null)" + status="$(git rev-list HEAD.."${TARGET}" 2> /dev/null)" if [[ -n "${status}" ]]; then - for i in $(git rev-list --merges --first-parent master..${BASH_IT_REMOTE}); do + for i in $(git rev-list --merges --first-parent HEAD.."${TARGET}"); do num_of_lines=$(git log -1 --format=%B $i | awk 'NF' | wc -l) if [ $num_of_lines -eq 1 ]; then description="%s" @@ -184,14 +207,14 @@ _bash-it_update() { git 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 + read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP case $RESP in [yY]|"") - git pull --rebase &> /dev/null + git checkout "${TARGET}" &> /dev/null if [[ $? -eq 0 ]]; then echo "Bash-it successfully updated." echo "" - echo "Migrating your installation to the latest version now..." + echo "Migrating your installation to the latest $version version now..." _bash-it-migrate echo "" echo "All done, enjoy!" From 1bdcacf2422f70d2cd1fe0a1b4fb09958022dcdc Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Mon, 22 Jun 2020 16:19:52 +0300 Subject: [PATCH 02/13] completion: Update completion for new bash-it update Also fix the update completion test --- completion/available/bash-it.completion.bash | 7 ++++++- test/completion/bash-it.completion.bats | 4 ++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index c13e8623..87c84a22 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -87,7 +87,12 @@ _bash-it-comp() COMPREPLY=( $(compgen -W "${doctor_args}" -- ${cur}) ) return 0 ;; - migrate | reload | search | update | version) + update) + local update_args="stable dev" + COMPREPLY=( $(compgen -W "${update_args}" -- ${cur}) ) + return 0 + ;; + migrate | reload | search | version) return 0 ;; enable | disable) diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index e453ae43..44eefc75 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -58,9 +58,9 @@ function __check_completion () { assert_line -n 0 "vagrant vault vim" } -@test "completion bash-it: update - show no options" { +@test "completion bash-it: update - show options" { run __check_completion 'bash-it update ' - assert_line -n 0 "" + assert_line -n 0 "stable dev" } @test "completion bash-it: search - show no options" { From d8c2256c3912475ee3f8855b875bd3bad92a853f Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 14 Jul 2020 13:47:21 +0300 Subject: [PATCH 03/13] doc: Add stable/dev option to update section --- README.md | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 26ac5cb7..6a0449b2 100644 --- a/README.md +++ b/README.md @@ -87,13 +87,17 @@ Have a look at our [bash-it-docker repository](https://github.com/Bash-it/bash-i ### Updating -To update Bash-it to the latest version, simply run: +To update Bash-it to the latest stable version, simply run: ```bash -bash-it update +bash-it update stable ``` -that's all. +If you want to update to the latest dev version (directly from master), run: + +```bash +bash-it update dev +``` If you are using an older version of Bash-it, it's possible that some functionality has changed, or that the internal structure of how Bash-it organizes its functionality has been updated. For these cases, we provide a `migrate` command: From ecf65569cefff5201432b064c705664c80babaa0 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 17 Jul 2020 15:50:40 +0300 Subject: [PATCH 04/13] lib: Update to stable now correctly fails if no tags are present --- lib/helpers.bash | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 51d6517b..35cabc42 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -184,7 +184,12 @@ _bash-it_update-() { # Defaults to stable update if [ -z "$1" ] || [ "$1" == "stable" ]; then version="stable" - TARGET=$(git describe --tags "$(git rev-list --tags --max-count=1)") + TARGET=$(git describe --tags "$(git rev-list --tags --max-count=1)" 2> /dev/null) + + if [[ -z "$TARGET" ]]; then + echo "Can not find tags, so can not update to latest stable version..." + return + fi else version="dev" TARGET=${BASH_IT_REMOTE}/master From 8e6876719b82b380af161e154b7e6a147c954b58 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 17 Jul 2020 16:36:57 +0300 Subject: [PATCH 05/13] lib: Add BASH_IT_DEVELOPMENT_BRANCH variable --- lib/helpers.bash | 5 ++++- template/bash_profile.template.bash | 4 ++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 35cabc42..b163cfc8 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -181,6 +181,9 @@ _bash-it_update-() { if [ -z "$BASH_IT_REMOTE" ]; then BASH_IT_REMOTE="origin" fi + if [ -z "$BASH_IT_DEVELOPMENT_BRANCH" ]; then + BASH_IT_DEVELOPMENT_BRANCH="master" + fi # Defaults to stable update if [ -z "$1" ] || [ "$1" == "stable" ]; then version="stable" @@ -192,7 +195,7 @@ _bash-it_update-() { fi else version="dev" - TARGET=${BASH_IT_REMOTE}/master + TARGET=${BASH_IT_REMOTE}/${BASH_IT_DEVELOPMENT_BRANCH} fi git fetch $BASH_IT_REMOTE --tags &> /dev/null diff --git a/template/bash_profile.template.bash b/template/bash_profile.template.bash index f8f4705f..4a840df3 100755 --- a/template/bash_profile.template.bash +++ b/template/bash_profile.template.bash @@ -18,6 +18,10 @@ export BASH_IT_THEME='bobby' # cloned bash-it with a remote other than origin such as `bash-it`. # export BASH_IT_REMOTE='bash-it' +# (Advanced): Change this to the name of the main development branch if +# you renamed it or if it was changed for some reason +# export BASH_IT_DEVELOPMENT_BRANCH='master' + # Your place for hosting Git repos. I use this for private repos. export GIT_HOSTING='git@git.domain.com' From 9b208e7d5c1eab0378a408ab9e03b55a89ee06ed Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 17 Jul 2020 18:00:31 +0300 Subject: [PATCH 06/13] lib: Update no-op message in case of stable update --- lib/helpers.bash | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index b163cfc8..e7265489 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -239,7 +239,11 @@ _bash-it_update-() { ;; esac else - echo "Bash-it is up to date, nothing to do!" + if [[ ${version} == "stable" ]]; then + echo "You're on the latest stable version. If you want to check out the latest 'dev' version, please run \"bash-it update dev\"" + else + echo "Bash-it is up to date, nothing to do!" + fi fi cd "${old_pwd}" &> /dev/null || return } From 4ca6dd9a366f1256e522fc067ad42bb57fb788de Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 19 Jun 2020 17:56:09 +0300 Subject: [PATCH 07/13] helpers: Add --slient option to bash-it update --- lib/helpers.bash | 66 ++++++++++++++++++++++++++++++------------------ 1 file changed, 41 insertions(+), 25 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index e7265489..2cb0b18c 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -159,14 +159,29 @@ _bash-it_update-dev() { _about 'updates Bash-it to the latest master' _group 'lib' - _bash-it_update- dev + _bash-it_update- dev "$@" } _bash-it_update-stable() { _about 'updates Bash-it to the latest tag' _group 'lib' - _bash-it_update- stable + _bash-it_update- stable "$@" +} + +_bash-it_pull_and_update_inner() { + git checkout "$1" &> /dev/null + if [[ $? -eq 0 ]]; then + echo "Bash-it successfully updated." + echo "" + echo "Migrating your installation to the latest $2 version now..." + _bash-it-migrate + echo "" + echo "All done, enjoy!" + bash-it reload + else + echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean." + fi } _bash-it_update-() { @@ -174,6 +189,12 @@ _bash-it_update-() { _param '1: What kind of update to do (stable|dev)' _group 'lib' + declare silent + for word in $@; do + if [[ ${word} == "--silent" || ${word} == "-s" ]]; then + silent=true + fi + done local old_pwd="${PWD}" cd "${BASH_IT}" || return @@ -215,29 +236,24 @@ _bash-it_update-() { git log --format="%h: $description (%an)" -1 $i done echo "" - read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP - case $RESP in - [yY]|"") - git checkout "${TARGET}" &> /dev/null - if [[ $? -eq 0 ]]; then - echo "Bash-it successfully updated." - echo "" - echo "Migrating your installation to the latest $version version now..." - _bash-it-migrate - echo "" - echo "All done, enjoy!" - bash-it reload - else - echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean." - fi - ;; - [nN]) - echo "Not upgrading…" - ;; - *) - echo -e "\033[91mPlease choose y or n.\033[m" - ;; - esac + + if [[ $silent ]]; then + echo "Updating to ${TARGET}($(git log -1 --format=%h "${TARGET}"))..." + _bash-it_pull_and_update_inner $TARGET $version + else + read -e -n 1 -p "Would you like to update to ${TARGET}($(git log -1 --format=%h "${TARGET}"))? [Y/n] " RESP + case $RESP in + [yY]|"") + _bash-it_pull_and_update_inner $TARGET $version + ;; + [nN]) + echo "Not upgrading…" + ;; + *) + echo -e "\033[91mPlease choose y or n.\033[m" + ;; + esac + fi else if [[ ${version} == "stable" ]]; then echo "You're on the latest stable version. If you want to check out the latest 'dev' version, please run \"bash-it update dev\"" From 3f2c6e79ee9c22c2e9648d218842c0d08f3ec564 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 14 Jul 2020 13:50:20 +0300 Subject: [PATCH 08/13] doc: Add --silent flag documentation --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 6a0449b2..1da1f7eb 100644 --- a/README.md +++ b/README.md @@ -99,6 +99,13 @@ If you want to update to the latest dev version (directly from master), run: bash-it update dev ``` +If you want to update automatically and unattended, you can add the optional +`-s/--silent` flag, for example: + +```bash +bash-it update dev --silent +``` + If you are using an older version of Bash-it, it's possible that some functionality has changed, or that the internal structure of how Bash-it organizes its functionality has been updated. For these cases, we provide a `migrate` command: From 2fd1cd66e4db2c9979d2d0d6f1953b3289ff4ba8 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 14 Jul 2020 18:05:51 +0300 Subject: [PATCH 09/13] completion: Add --silent and -s completion --- completion/available/bash-it.completion.bash | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/completion/available/bash-it.completion.bash b/completion/available/bash-it.completion.bash index 87c84a22..c9b4b683 100644 --- a/completion/available/bash-it.completion.bash +++ b/completion/available/bash-it.completion.bash @@ -88,7 +88,11 @@ _bash-it-comp() return 0 ;; update) - local update_args="stable dev" + if [[ ${cur} == -* ]];then + local update_args="-s --silent" + else + local update_args="stable dev" + fi COMPREPLY=( $(compgen -W "${update_args}" -- ${cur}) ) return 0 ;; From fc17169b1cf423e5e6dac729e919004ab254daf6 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Fri, 17 Jul 2020 16:40:11 +0300 Subject: [PATCH 10/13] test: Add completion test for -s --silent flag --- test/completion/bash-it.completion.bats | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/completion/bash-it.completion.bats b/test/completion/bash-it.completion.bats index 44eefc75..902c4b42 100644 --- a/test/completion/bash-it.completion.bats +++ b/test/completion/bash-it.completion.bats @@ -63,6 +63,11 @@ function __check_completion () { assert_line -n 0 "stable dev" } +@test "completion bash-it: update - show optional flags" { + run __check_completion 'bash-it update -' + assert_line -n 0 "-s --silent" +} + @test "completion bash-it: search - show no options" { run __check_completion 'bash-it search ' assert_line -n 0 "" From 0a9b43e86d432f3b915c9381a0065a87cdcb0146 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Sat, 18 Jul 2020 11:41:52 +0300 Subject: [PATCH 11/13] lib: Fetch from remote before calculating latest tag in bash-it update --- lib/helpers.bash | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 2cb0b18c..ff8fddda 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -202,6 +202,9 @@ _bash-it_update-() { if [ -z "$BASH_IT_REMOTE" ]; then BASH_IT_REMOTE="origin" fi + + git fetch $BASH_IT_REMOTE --tags &> /dev/null + if [ -z "$BASH_IT_DEVELOPMENT_BRANCH" ]; then BASH_IT_DEVELOPMENT_BRANCH="master" fi @@ -219,8 +222,6 @@ _bash-it_update-() { TARGET=${BASH_IT_REMOTE}/${BASH_IT_DEVELOPMENT_BRANCH} fi - git fetch $BASH_IT_REMOTE --tags &> /dev/null - declare status status="$(git rev-list HEAD.."${TARGET}" 2> /dev/null)" From 6bed26eccb19259eb3da3d73b635e59522b194e5 Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 13 Oct 2020 14:55:03 +0300 Subject: [PATCH 12/13] lib: helpers: Rename Upgrading -> Updating --- lib/helpers.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index ff8fddda..31628d27 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -248,7 +248,7 @@ _bash-it_update-() { _bash-it_pull_and_update_inner $TARGET $version ;; [nN]) - echo "Not upgrading…" + echo "Not updating…" ;; *) echo -e "\033[91mPlease choose y or n.\033[m" From a1adfaaa3e84927b7a0b86ee4bc9b4eacd30e6bf Mon Sep 17 00:00:00 2001 From: Noah Gorny Date: Tue, 13 Oct 2020 15:02:37 +0300 Subject: [PATCH 13/13] lib: helpers: Handle stable revert update --- lib/helpers.bash | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/lib/helpers.bash b/lib/helpers.bash index 31628d27..1bb2ad28 100644 --- a/lib/helpers.bash +++ b/lib/helpers.bash @@ -222,19 +222,34 @@ _bash-it_update-() { TARGET=${BASH_IT_REMOTE}/${BASH_IT_DEVELOPMENT_BRANCH} fi + declare revision + revision="HEAD..${TARGET}" declare status - status="$(git rev-list HEAD.."${TARGET}" 2> /dev/null)" + status="$(git rev-list ${revision} 2> /dev/null)" + declare revert + + if [[ -z "${status}" && ${version} == "stable" ]]; then + revision="${TARGET}..HEAD" + status="$(git rev-list ${revision} 2> /dev/null)" + revert=true + fi if [[ -n "${status}" ]]; then + if [[ $revert ]]; then + echo "Your version is a more recent development version ($(git log -1 --format=%h HEAD))" + echo "You can continue in order to revert and update to the latest stable version" + echo "" + log_color="%Cred" + fi - for i in $(git rev-list --merges --first-parent HEAD.."${TARGET}"); do + for i in $(git rev-list --merges --first-parent ${revision}); 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 log --format="%h: $description (%an)" -1 $i + git log --format="${log_color}%h: $description (%an)" -1 $i done echo ""