mirror of
https://github.com/pyenv/pyenv-update.git
synced 2025-11-12 05:23:47 -05:00
73 lines
1.3 KiB
Bash
Executable File
73 lines
1.3 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
|
|
set -e
|
|
[ -n "$PYENV_DEBUG" ] && set -x
|
|
|
|
if [ -z "$PYENV_ROOT" ]; then
|
|
PYENV_ROOT="${HOME}/.pyenv"
|
|
fi
|
|
|
|
REMOTE="${PYENV_REMOTE:-origin}"
|
|
BRANCH="${PYENV_BRANCH:-master}"
|
|
|
|
verify_repo_remote() {
|
|
( cd "$1" && git remote show -n "${REMOTE}" 1>/dev/null 2>&1 )
|
|
}
|
|
|
|
verify_repo_branch() {
|
|
local name="$(cd "$1" && git name-rev --refs='refs/heads/*' --name-only HEAD 2>/dev/null)"
|
|
[[ "${name}" == "${BRANCH}" ]]
|
|
}
|
|
|
|
verify_repo_clean() {
|
|
! ( cd "$1" && git status --porcelain ) | grep -q -v '^[!?][!?]'
|
|
}
|
|
|
|
verify_repo() {
|
|
local stat=0
|
|
verify_repo_remote "$1" || {
|
|
stat="$?"
|
|
error "pyenv-update: $1 does not have ${REMOTE}."
|
|
}
|
|
verify_repo_branch "$1" || {
|
|
stat="$?"
|
|
error "pyenv-update: $1 is not on ${BRANCH} branch."
|
|
}
|
|
verify_repo_clean "$1" || {
|
|
stat="$?"
|
|
error "pyenv-update: $1 is not clean"
|
|
}
|
|
return "$stat"
|
|
}
|
|
|
|
update_repo() {
|
|
info "Updating $1..."
|
|
verify_repo "$1" &&
|
|
( cd "${repo}" && git pull --no-rebase --ff "${REMOTE}" "${BRANCH}" )
|
|
}
|
|
|
|
info() {
|
|
{ printf "\x1B[2;32m"
|
|
echo "$@"
|
|
printf "\x1B[0m"
|
|
}
|
|
}
|
|
|
|
error() {
|
|
{ printf "\x1B[1;31m"
|
|
echo "$@"
|
|
printf "\x1B[0m"
|
|
} 1>&2
|
|
}
|
|
|
|
STATUS=0
|
|
shopt -s nullglob
|
|
for repo in "${PYENV_ROOT}" "${PYENV_ROOT}/plugins/"*; do
|
|
if [ -d "${repo}/.git" ]; then
|
|
update_repo "${repo}" || STATUS="$?"
|
|
fi
|
|
done
|
|
shopt -u nullglob
|
|
|
|
exit "$STATUS"
|