mirror of
https://github.com/pyenv/pyenv.git
synced 2024-11-21 20:47:00 -05:00
Improve rbenv --version
git checkout discovery
When `rbenv --version` is called, this now happens: 1. It changes into the directory where `libexec/rbenv--version` resides and checks if it's a checkout of the rbenv repo (as opposed to Homebrew checkout or something else). Then it reads the git revision. 2. If that failed, change to `$RBENV_ROOT` directory and repeat step 1.
This commit is contained in:
parent
0f44c57d08
commit
dcca61c0bc
2 changed files with 36 additions and 4 deletions
|
@ -13,10 +13,14 @@ set -e
|
||||||
[ -n "$RBENV_DEBUG" ] && set -x
|
[ -n "$RBENV_DEBUG" ] && set -x
|
||||||
|
|
||||||
version="0.4.0"
|
version="0.4.0"
|
||||||
|
git_revision=""
|
||||||
|
|
||||||
if cd "$RBENV_ROOT" 2>/dev/null; then
|
for source_dir in "${BASH_SOURCE%/*}" "$RBENV_ROOT"; do
|
||||||
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
|
if cd "$source_dir" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then
|
||||||
git_revision="${git_revision#v}"
|
git_revision="$(git describe --tags HEAD 2>/dev/null || true)"
|
||||||
fi
|
git_revision="${git_revision#v}"
|
||||||
|
[ -z "$git_revision" ] || break
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
echo "rbenv ${git_revision:-$version}"
|
echo "rbenv ${git_revision:-$version}"
|
||||||
|
|
|
@ -6,6 +6,18 @@ setup() {
|
||||||
mkdir -p "$HOME"
|
mkdir -p "$HOME"
|
||||||
git config --global user.name "Tester"
|
git config --global user.name "Tester"
|
||||||
git config --global user.email "tester@test.local"
|
git config --global user.email "tester@test.local"
|
||||||
|
|
||||||
|
mkdir -p "${RBENV_TEST_DIR}/bin"
|
||||||
|
cat > "${RBENV_TEST_DIR}/bin/git" <<CMD
|
||||||
|
#!$BASH
|
||||||
|
if [[ \$1 == remote && \$PWD != "\$RBENV_TEST_DIR"/* ]]; then
|
||||||
|
echo "not allowed" >&2
|
||||||
|
exit 1
|
||||||
|
else
|
||||||
|
exec $(which git) "\$@"
|
||||||
|
fi
|
||||||
|
CMD
|
||||||
|
chmod +x "${RBENV_TEST_DIR}/bin/git"
|
||||||
}
|
}
|
||||||
|
|
||||||
git_commit() {
|
git_commit() {
|
||||||
|
@ -19,10 +31,25 @@ git_commit() {
|
||||||
[[ $output == "rbenv 0."* ]]
|
[[ $output == "rbenv 0."* ]]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@test "doesn't read version from non-rbenv repo" {
|
||||||
|
mkdir -p "$RBENV_ROOT"
|
||||||
|
cd "$RBENV_ROOT"
|
||||||
|
git init
|
||||||
|
git remote add origin https://github.com/homebrew/homebrew.git
|
||||||
|
git_commit
|
||||||
|
git tag v1.0
|
||||||
|
|
||||||
|
cd "$RBENV_TEST_DIR"
|
||||||
|
run rbenv---version
|
||||||
|
assert_success
|
||||||
|
[[ $output == "rbenv 0."* ]]
|
||||||
|
}
|
||||||
|
|
||||||
@test "reads version from git repo" {
|
@test "reads version from git repo" {
|
||||||
mkdir -p "$RBENV_ROOT"
|
mkdir -p "$RBENV_ROOT"
|
||||||
cd "$RBENV_ROOT"
|
cd "$RBENV_ROOT"
|
||||||
git init
|
git init
|
||||||
|
git remote add origin https://github.com/sstephenson/rbenv.git
|
||||||
git_commit
|
git_commit
|
||||||
git tag v0.4.1
|
git tag v0.4.1
|
||||||
git_commit
|
git_commit
|
||||||
|
@ -38,6 +65,7 @@ git_commit() {
|
||||||
mkdir -p "$RBENV_ROOT"
|
mkdir -p "$RBENV_ROOT"
|
||||||
cd "$RBENV_ROOT"
|
cd "$RBENV_ROOT"
|
||||||
git init
|
git init
|
||||||
|
git remote add origin https://github.com/sstephenson/rbenv.git
|
||||||
git_commit
|
git_commit
|
||||||
|
|
||||||
cd "$RBENV_TEST_DIR"
|
cd "$RBENV_TEST_DIR"
|
||||||
|
|
Loading…
Reference in a new issue