Merge pull request #1626 from NoahGorny/update-to-stable-or-unstable
bash-it update to stable or devpull/1685/head v1.0.0
commit
c387517122
17
README.md
17
README.md
|
|
@ -87,13 +87,24 @@ Have a look at our [bash-it-docker repository](https://github.com/Bash-it/bash-i
|
||||||
|
|
||||||
### Updating
|
### Updating
|
||||||
|
|
||||||
To update Bash-it to the latest version, simply run:
|
To update Bash-it to the latest stable version, simply run:
|
||||||
|
|
||||||
```bash
|
```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 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.
|
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:
|
For these cases, we provide a `migrate` command:
|
||||||
|
|
|
||||||
|
|
@ -87,7 +87,16 @@ _bash-it-comp()
|
||||||
COMPREPLY=( $(compgen -W "${doctor_args}" -- ${cur}) )
|
COMPREPLY=( $(compgen -W "${doctor_args}" -- ${cur}) )
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
migrate | reload | search | update | version)
|
update)
|
||||||
|
if [[ ${cur} == -* ]];then
|
||||||
|
local update_args="-s --silent"
|
||||||
|
else
|
||||||
|
local update_args="stable dev"
|
||||||
|
fi
|
||||||
|
COMPREPLY=( $(compgen -W "${update_args}" -- ${cur}) )
|
||||||
|
return 0
|
||||||
|
;;
|
||||||
|
migrate | reload | search | version)
|
||||||
return 0
|
return 0
|
||||||
;;
|
;;
|
||||||
enable | disable)
|
enable | disable)
|
||||||
|
|
|
||||||
129
lib/helpers.bash
129
lib/helpers.bash
|
|
@ -80,7 +80,7 @@ bash-it ()
|
||||||
_bash-it-search $component "$@"
|
_bash-it-search $component "$@"
|
||||||
return;;
|
return;;
|
||||||
update)
|
update)
|
||||||
func=_bash-it_update;;
|
func=_bash-it_update-$component;;
|
||||||
migrate)
|
migrate)
|
||||||
func=_bash-it-migrate;;
|
func=_bash-it-migrate;;
|
||||||
version)
|
version)
|
||||||
|
|
@ -158,43 +158,26 @@ _bash-it-plugins ()
|
||||||
_bash-it-describe "plugins" "a" "plugin" "Plugin"
|
_bash-it-describe "plugins" "a" "plugin" "Plugin"
|
||||||
}
|
}
|
||||||
|
|
||||||
_bash-it_update() {
|
_bash-it_update-dev() {
|
||||||
_about 'updates Bash-it'
|
_about 'updates Bash-it to the latest master'
|
||||||
_group 'lib'
|
_group 'lib'
|
||||||
|
|
||||||
local old_pwd="${PWD}"
|
_bash-it_update- dev "$@"
|
||||||
|
}
|
||||||
|
|
||||||
cd "${BASH_IT}" || return
|
_bash-it_update-stable() {
|
||||||
|
_about 'updates Bash-it to the latest tag'
|
||||||
|
_group 'lib'
|
||||||
|
|
||||||
if [ -z $BASH_IT_REMOTE ]; then
|
_bash-it_update- stable "$@"
|
||||||
BASH_IT_REMOTE="origin"
|
}
|
||||||
fi
|
|
||||||
|
|
||||||
git fetch &> /dev/null
|
_bash-it_pull_and_update_inner() {
|
||||||
|
git checkout "$1" &> /dev/null
|
||||||
declare status
|
|
||||||
status="$(git rev-list master..${BASH_IT_REMOTE}/master 2> /dev/null)"
|
|
||||||
|
|
||||||
if [[ -n "${status}" ]]; then
|
|
||||||
|
|
||||||
for i in $(git rev-list --merges --first-parent master..${BASH_IT_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 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]|"")
|
|
||||||
git pull --rebase &> /dev/null
|
|
||||||
if [[ $? -eq 0 ]]; then
|
if [[ $? -eq 0 ]]; then
|
||||||
echo "Bash-it successfully updated."
|
echo "Bash-it successfully updated."
|
||||||
echo ""
|
echo ""
|
||||||
echo "Migrating your installation to the latest version now..."
|
echo "Migrating your installation to the latest $2 version now..."
|
||||||
_bash-it-migrate
|
_bash-it-migrate
|
||||||
echo ""
|
echo ""
|
||||||
echo "All done, enjoy!"
|
echo "All done, enjoy!"
|
||||||
|
|
@ -202,17 +185,101 @@ _bash-it_update() {
|
||||||
else
|
else
|
||||||
echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean."
|
echo "Error updating Bash-it, please, check if your Bash-it installation folder (${BASH_IT}) is clean."
|
||||||
fi
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
_bash-it_update-() {
|
||||||
|
_about 'updates Bash-it'
|
||||||
|
_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
|
||||||
|
|
||||||
|
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
|
||||||
|
# Defaults to stable update
|
||||||
|
if [ -z "$1" ] || [ "$1" == "stable" ]; then
|
||||||
|
version="stable"
|
||||||
|
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}/${BASH_IT_DEVELOPMENT_BRANCH}
|
||||||
|
fi
|
||||||
|
|
||||||
|
declare revision
|
||||||
|
revision="HEAD..${TARGET}"
|
||||||
|
declare status
|
||||||
|
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 ${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="${log_color}%h: $description (%an)" -1 $i
|
||||||
|
done
|
||||||
|
echo ""
|
||||||
|
|
||||||
|
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])
|
[nN])
|
||||||
echo "Not upgrading…"
|
echo "Not updating…"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
echo -e "\033[91mPlease choose y or n.\033[m"
|
echo -e "\033[91mPlease choose y or n.\033[m"
|
||||||
;;
|
;;
|
||||||
esac
|
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\""
|
||||||
else
|
else
|
||||||
echo "Bash-it is up to date, nothing to do!"
|
echo "Bash-it is up to date, nothing to do!"
|
||||||
fi
|
fi
|
||||||
|
fi
|
||||||
cd "${old_pwd}" &> /dev/null || return
|
cd "${old_pwd}" &> /dev/null || return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,10 @@ export BASH_IT_THEME='bobby'
|
||||||
# cloned bash-it with a remote other than origin such as `bash-it`.
|
# cloned bash-it with a remote other than origin such as `bash-it`.
|
||||||
# export BASH_IT_REMOTE='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.
|
# Your place for hosting Git repos. I use this for private repos.
|
||||||
export GIT_HOSTING='git@git.domain.com'
|
export GIT_HOSTING='git@git.domain.com'
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -58,9 +58,14 @@ function __check_completion () {
|
||||||
assert_line -n 0 "vagrant vault vim"
|
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 '
|
run __check_completion 'bash-it update '
|
||||||
assert_line -n 0 ""
|
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" {
|
@test "completion bash-it: search - show no options" {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue