From ca252599007375ffbb3522a736a2a7a7d1eeccde Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 23 Dec 2015 15:19:54 +0100 Subject: [PATCH 01/34] Allow explicit target directory argument to `rbenv-version-file` Can be used for `.ruby-version` file lookup in the ancestry of a specific directory. In this mode of operation, global version files aren't taken into consideration, and the command fails unless a local version file was found. --- libexec/rbenv-version-file | 38 ++++++++++++++++++++++++-------------- test/version-file.bats | 11 +++++++++++ 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index 5e38c695..1e70539f 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -1,35 +1,45 @@ #!/usr/bin/env bash +# Usage: rbenv version-file [] # Summary: Detect the file that sets the current rbenv version set -e [ -n "$RBENV_DEBUG" ] && set -x +target_dir="$1" + find_local_version_file() { local root="$1" - while true; do - [[ "$root" =~ ^//[^/]*$ ]] && break + while ! [[ "$root" =~ ^//[^/]*$ ]]; do if [ -e "${root}/.ruby-version" ]; then echo "${root}/.ruby-version" - exit + return 0 elif [ -e "${root}/.rbenv-version" ]; then echo "${root}/.rbenv-version" - exit + return 0 fi [ -n "$root" ] || break root="${root%/*}" done + return 1 } -find_local_version_file "$RBENV_DIR" -[ "$RBENV_DIR" = "$PWD" ] || find_local_version_file "$PWD" +find_global_version_file() { + local global_version_file="${RBENV_ROOT}/version" -global_version_file="${RBENV_ROOT}/version" + if [ -e "$global_version_file" ]; then + echo "$global_version_file" + elif [ -e "${RBENV_ROOT}/global" ]; then + echo "${RBENV_ROOT}/global" + elif [ -e "${RBENV_ROOT}/default" ]; then + echo "${RBENV_ROOT}/default" + else + echo "$global_version_file" + fi +} -if [ -e "$global_version_file" ]; then - echo "$global_version_file" -elif [ -e "${RBENV_ROOT}/global" ]; then - echo "${RBENV_ROOT}/global" -elif [ -e "${RBENV_ROOT}/default" ]; then - echo "${RBENV_ROOT}/default" +if [ -n "$target_dir" ]; then + find_local_version_file "$target_dir" else - echo "$global_version_file" + find_local_version_file "$RBENV_DIR" || { + [ "$RBENV_DIR" != "$PWD" ] && find_local_version_file "$PWD" + } || find_global_version_file fi diff --git a/test/version-file.bats b/test/version-file.bats index ed84c484..ef7901f4 100644 --- a/test/version-file.bats +++ b/test/version-file.bats @@ -97,3 +97,14 @@ create_file() { RBENV_DIR="${RBENV_TEST_DIR}/widget/blank" run rbenv-version-file assert_success "${RBENV_TEST_DIR}/project/.ruby-version" } + +@test "finds version file in target directory" { + create_file "project/.ruby-version" + run rbenv-version-file "${PWD}/project" + assert_success "${RBENV_TEST_DIR}/project/.ruby-version" +} + +@test "fails when no version file in target directory" { + run rbenv-version-file "$PWD" + assert_failure "" +} From ba072adcb99a5c77df2a93afccdca59a23703696 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 23 Dec 2015 15:21:24 +0100 Subject: [PATCH 02/34] Have `rbenv local` read version from parent directories as well Fixes #807 --- libexec/rbenv-local | 9 +++++---- test/local.bats | 4 ++-- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libexec/rbenv-local b/libexec/rbenv-local index 9169943e..d5c5f11c 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -47,9 +47,10 @@ elif [ -n "$RBENV_VERSION" ]; then } >&2 fi else - rbenv-version-file-read .ruby-version || - rbenv-version-file-read .rbenv-version || - { echo "rbenv: no local version configured for this directory" + if version_file="$(rbenv-version-file "$PWD")"; then + rbenv-version-file-read "$version_file" + else + echo "rbenv: no local version configured for this directory" >&2 exit 1 - } >&2 + fi fi diff --git a/test/local.bats b/test/local.bats index 3e93ca7f..a84833eb 100644 --- a/test/local.bats +++ b/test/local.bats @@ -32,11 +32,11 @@ setup() { assert_success "2.0" } -@test "ignores version in parent directory" { +@test "discovers version file in parent directory" { echo "1.2.3" > .ruby-version mkdir -p "subdir" && cd "subdir" run rbenv-local - assert_failure + assert_success "1.2.3" } @test "ignores RBENV_DIR" { From 258e4413b165b87e4c0c3190b45c1a167678b4d5 Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Wed, 27 May 2015 23:10:39 -0400 Subject: [PATCH 03/34] create hook: version-name Expose a `version-name` hook. It is invoked *after* the traditional `RBENV_VERSION` lookup. Which means hook scripts can interrogate `$RBENV_VERSION_FILE` and/or `$RBENV_VERSION` (or use the executables). The hooks are then run, giving plugins a chance to alter `RBENV_VERSION`. Once the hooks have run, we now have (in `$RBENV_VERSION`) the actual version we want to use (or it's empty which defaults to `system` per normal). Lastly, the same logic remains for checking if the version exists, or trimming the `ruby-` prefix. Prime example: the ruby-bundler-ruby-version plugin can select a ruby by using the `ruby` directive from the `Gemfile` if a local `.ruby-version` doesn't exist. --- libexec/rbenv-version-name | 7 +++++++ test/version-name.bats | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+) diff --git a/libexec/rbenv-version-name b/libexec/rbenv-version-name index 3769a7cd..1af277bf 100755 --- a/libexec/rbenv-version-name +++ b/libexec/rbenv-version-name @@ -8,6 +8,13 @@ if [ -z "$RBENV_VERSION" ]; then RBENV_VERSION="$(rbenv-version-file-read "$RBENV_VERSION_FILE" || true)" fi +OLDIFS="$IFS" +IFS=$'\n' scripts=(`rbenv-hooks version-name`) +IFS="$OLDIFS" +for script in "${scripts[@]}"; do + source "$script" +done + if [ -z "$RBENV_VERSION" ] || [ "$RBENV_VERSION" = "system" ]; then echo "system" exit diff --git a/test/version-name.bats b/test/version-name.bats index d6438b5b..bc633121 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -2,6 +2,13 @@ load test_helper +export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d" + +create_hook() { + mkdir -p "${RBENV_ROOT}/rbenv.d/version-name" + cat > "${RBENV_ROOT}/rbenv.d/version-name/$1" <<<"$2" +} + create_version() { mkdir -p "${RBENV_ROOT}/versions/$1" } @@ -22,6 +29,18 @@ setup() { assert_success "system" } +@test "RBENV_VERSION can be overridden by hook" { + create_version "1.8.7" + create_version "1.9.3" + + RBENV_VERSION=1.8.7 run rbenv-version-name + assert_success "1.8.7" + + create_hook test.bash "RBENV_VERSION=1.9.3" + RBENV_VERSION=1.8.7 run rbenv-version-name + assert_success "1.9.3" +} + @test "RBENV_VERSION has precedence over local" { create_version "1.8.7" create_version "1.9.3" From c3a5f91ed0d9f7a0382ae1821297051bc827e4b8 Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Wed, 27 May 2015 23:29:11 -0400 Subject: [PATCH 04/34] create hook: version-origin Expose a `version-origin` hook. It is invoked *before* the traditional `rbenv-version-file` lookup. Because `version-origin` is traditionally run immediately after `version-name`, then any plugin hooks that alter `version-name` would have done so. Thus, running `version-origin` prior to printing the origin gives those plugins a chance to alter the `version-origin` to match. If any of the hooks set `$RBENV_VERSION_ORIGIN`, then it is used as the return value. Otherwise, the existing logic continues to return "environment variable" or "filename" as appropriate. This change, in conjunction with the `version-name` hook, makes a clean seam by which plugins can inject their own ruby version setting logic. Using this seam, as opposed to altering `$RBENV_COMMAND_PATH` from the `which` hook, means that the version name and origin are set more reliably and so `version`, `version-name`, `version-origin` and `which` all work as expected. Indeed, even PS1 works now. --- libexec/rbenv-version-origin | 11 ++++++++++- test/version-origin.bats | 16 ++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv-version-origin b/libexec/rbenv-version-origin index ae7abf9c..a9d21c4c 100755 --- a/libexec/rbenv-version-origin +++ b/libexec/rbenv-version-origin @@ -3,7 +3,16 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -if [ -n "$RBENV_VERSION" ]; then +OLDIFS="$IFS" +IFS=$'\n' scripts=(`rbenv-hooks version-origin`) +IFS="$OLDIFS" +for script in "${scripts[@]}"; do + source "$script" +done + +if [ -n "$RBENV_VERSION_ORIGIN" ]; then + echo "$RBENV_VERSION_ORIGIN" +elif [ -n "$RBENV_VERSION" ]; then echo "RBENV_VERSION environment variable" else rbenv-version-file diff --git a/test/version-origin.bats b/test/version-origin.bats index 8ad4db04..fed0aaa5 100644 --- a/test/version-origin.bats +++ b/test/version-origin.bats @@ -2,6 +2,13 @@ load test_helper +export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d" + +create_hook() { + mkdir -p "${RBENV_ROOT}/rbenv.d/version-origin" + cat > "${RBENV_ROOT}/rbenv.d/version-origin/$1" <<<"$2" +} + setup() { mkdir -p "$RBENV_TEST_DIR" cd "$RBENV_TEST_DIR" @@ -36,3 +43,12 @@ setup() { run rbenv-version-origin assert_success "${PWD}/.rbenv-version" } + +@test "reports from hook" { + touch .ruby-version + create_hook test.bash "RBENV_VERSION_ORIGIN=plugin" + + RBENV_VERSION=1 run rbenv-version-origin + + assert_success "plugin" +} From 97f0499f43a1a885beea2c738a179175ecc48580 Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Fri, 6 Nov 2015 21:17:40 -0500 Subject: [PATCH 05/34] add version-name/version-origin to hooks completion --- libexec/rbenv-hooks | 2 ++ 1 file changed, 2 insertions(+) diff --git a/libexec/rbenv-hooks b/libexec/rbenv-hooks index 201c91da..df0a6f60 100755 --- a/libexec/rbenv-hooks +++ b/libexec/rbenv-hooks @@ -9,6 +9,8 @@ set -e if [ "$1" = "--complete" ]; then echo exec echo rehash + echo version-name + echo version-origin echo which exit fi From 4fde4ecbaf1e1f3082c9275a6f244c70527ad497 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 23 Dec 2015 17:26:53 +0100 Subject: [PATCH 06/34] Ensure RBENV_VERSION_ORIGIN is not inherited from environment It's only supposed to be set from `version-origin` hooks, but not inherited from environment in case it was set. --- libexec/rbenv-version-origin | 2 ++ test/version-origin.bats | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/libexec/rbenv-version-origin b/libexec/rbenv-version-origin index a9d21c4c..3f1d4f03 100755 --- a/libexec/rbenv-version-origin +++ b/libexec/rbenv-version-origin @@ -3,6 +3,8 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x +unset RBENV_VERSION_ORIGIN + OLDIFS="$IFS" IFS=$'\n' scripts=(`rbenv-hooks version-origin`) IFS="$OLDIFS" diff --git a/test/version-origin.bats b/test/version-origin.bats index fed0aaa5..e0576648 100644 --- a/test/version-origin.bats +++ b/test/version-origin.bats @@ -52,3 +52,8 @@ setup() { assert_success "plugin" } + +@test "doesn't inherit RBENV_VERSION_ORIGIN from environment" { + RBENV_VERSION_ORIGIN=ignored run rbenv-version-origin + assert_success "${RBENV_ROOT}/version" +} From 6e300322789b7809cb70a97948dd19c163b02a1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Wed, 23 Dec 2015 17:32:21 +0100 Subject: [PATCH 07/34] Simplify version-name, version-origin hook tests No need for helper function that's gonna be used just once. --- test/version-name.bats | 16 +++++----------- test/version-origin.bats | 16 +++++----------- 2 files changed, 10 insertions(+), 22 deletions(-) diff --git a/test/version-name.bats b/test/version-name.bats index ef283283..82e1b2d0 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -2,13 +2,6 @@ load test_helper -export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d" - -create_hook() { - mkdir -p "${RBENV_ROOT}/rbenv.d/version-name" - cat > "${RBENV_ROOT}/rbenv.d/version-name/$1" <<<"$2" -} - create_version() { mkdir -p "${RBENV_ROOT}/versions/$1" } @@ -33,11 +26,12 @@ setup() { create_version "1.8.7" create_version "1.9.3" - RBENV_VERSION=1.8.7 run rbenv-version-name - assert_success "1.8.7" + mkdir -p "${RBENV_ROOT}/rbenv.d/version-name" + cat > "${RBENV_ROOT}/rbenv.d/version-name/test.bash" < "${RBENV_ROOT}/rbenv.d/version-origin/$1" <<<"$2" -} - setup() { mkdir -p "$RBENV_TEST_DIR" cd "$RBENV_TEST_DIR" @@ -45,11 +38,12 @@ setup() { } @test "reports from hook" { - touch .ruby-version - create_hook test.bash "RBENV_VERSION_ORIGIN=plugin" - - RBENV_VERSION=1 run rbenv-version-origin + mkdir -p "${RBENV_ROOT}/rbenv.d/version-origin" + cat > "${RBENV_ROOT}/rbenv.d/version-origin/test.bash" < Date: Thu, 24 Dec 2015 03:52:33 +0100 Subject: [PATCH 08/34] Improve `git --version` git revision lookup It doesn't try to chdir into RBENV_ROOT anymore because that might be a location of an unrelated rbenv install that might have a different version than the current one that is installed e.g. via a package manager such as Homebrew. Now just tries the repo where the source files (`libexec/*`) are located, and if that isn't a valid rbenv repo, bail out early. --- libexec/rbenv---version | 11 ++++------- test/--version.bats | 33 +++++++-------------------------- 2 files changed, 11 insertions(+), 33 deletions(-) diff --git a/libexec/rbenv---version b/libexec/rbenv---version index 1254a2fd..f3fba63d 100755 --- a/libexec/rbenv---version +++ b/libexec/rbenv---version @@ -15,12 +15,9 @@ set -e version="0.4.0" git_revision="" -for source_dir in "${BASH_SOURCE%/*}" "$RBENV_ROOT"; do - if cd "$source_dir" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then - git_revision="$(git describe --tags HEAD 2>/dev/null || true)" - git_revision="${git_revision#v}" - [ -z "$git_revision" ] || break - fi -done +if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then + git_revision="$(git describe --tags HEAD 2>/dev/null || true)" + git_revision="${git_revision#v}" +fi echo "rbenv ${git_revision:-$version}" diff --git a/test/--version.bats b/test/--version.bats index 3d7ad5c7..556c7d64 100644 --- a/test/--version.bats +++ b/test/--version.bats @@ -2,22 +2,13 @@ load test_helper +export GIT_DIR="${RBENV_TEST_DIR}/.git" + setup() { mkdir -p "$HOME" git config --global user.name "Tester" git config --global user.email "tester@test.local" - - mkdir -p "${RBENV_TEST_DIR}/bin" - cat > "${RBENV_TEST_DIR}/bin/git" <&2 - exit 1 -else - exec $(which git) "\$@" -fi -CMD - chmod +x "${RBENV_TEST_DIR}/bin/git" + cd "$RBENV_TEST_DIR" } git_commit() { @@ -28,26 +19,21 @@ git_commit() { assert [ ! -e "$RBENV_ROOT" ] run rbenv---version assert_success - [[ $output == "rbenv 0."* ]] + [[ $output == "rbenv "?.?.? ]] } @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."* ]] + [[ $output == "rbenv "?.?.? ]] } @test "reads version from git repo" { - mkdir -p "$RBENV_ROOT" - cd "$RBENV_ROOT" git init git remote add origin https://github.com/rbenv/rbenv.git git_commit @@ -55,20 +41,15 @@ git_commit() { git_commit git_commit - cd "$RBENV_TEST_DIR" run rbenv---version - assert_success - [[ $output == "rbenv 0.4.1-2-g"* ]] + assert_success "rbenv 0.4.1-2-g$(git rev-parse --short HEAD)" } @test "prints default version if no tags in git repo" { - mkdir -p "$RBENV_ROOT" - cd "$RBENV_ROOT" git init git remote add origin https://github.com/rbenv/rbenv.git git_commit - cd "$RBENV_TEST_DIR" run rbenv---version - [[ $output == "rbenv 0."* ]] + [[ $output == "rbenv "?.?.? ]] } From 2c7960102c6b085684e24e458dadaba24ffd9b7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 24 Dec 2015 03:54:32 +0100 Subject: [PATCH 09/34] Simplify reference to realpath.dylib within `rbenv-versions` The `../libexec` dance isn't necessary here. It was only necessary in main `rbenv` command because that one might have been pointed to directly via a symlink. --- libexec/rbenv-versions | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-versions b/libexec/rbenv-versions index b646cb54..dc8eabc2 100755 --- a/libexec/rbenv-versions +++ b/libexec/rbenv-versions @@ -27,7 +27,7 @@ done versions_dir="${RBENV_ROOT}/versions" -if ! enable -f "${BASH_SOURCE%/*}"/../libexec/rbenv-realpath.dylib realpath 2>/dev/null; then +if ! enable -f "${BASH_SOURCE%/*}"/rbenv-realpath.dylib realpath 2>/dev/null; then if [ -n "$RBENV_NATIVE_EXT" ]; then echo "rbenv: failed to load \`realpath' builtin" >&2 exit 1 From f9d8b551dc2afa82e98d0779d1c6e4eebace74f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 24 Dec 2015 12:29:35 +0100 Subject: [PATCH 10/34] Add test for detecting shell when `rbenv init` is called from script References #730 --- test/init.bats | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/test/init.bats b/test/init.bats index 0a46dd0d..d7005489 100644 --- a/test/init.bats +++ b/test/init.bats @@ -25,12 +25,24 @@ load test_helper } @test "detect parent shell" { - root="$(cd $BATS_TEST_DIRNAME/.. && pwd)" SHELL=/bin/false run rbenv-init - assert_success assert_line "export RBENV_SHELL=bash" } +@test "detect parent shell from script" { + mkdir -p "$RBENV_TEST_DIR" + cd "$RBENV_TEST_DIR" + cat > myscript.sh < Date: Sun, 10 May 2015 16:03:06 +0200 Subject: [PATCH 11/34] Fix shell version when invoked from a script When invoked from a shell script, `$(rbenv init -)` did not get the shell name correct. It needs to look at the `args` value from `ps`. Ref: https://github.com/yyuu/pyenv/issues/373 --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 8e6ee3d8..9fcfc2f4 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -33,7 +33,7 @@ done shell="$1" if [ -z "$shell" ]; then - shell="$(ps c -p "$PPID" -o 'ucomm=' 2>/dev/null || true)" + shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)" shell="${shell##-}" shell="${shell%% *}" shell="${shell:-$SHELL}" From a9a9636d1e739e047c8089e0319eed5c0cfebc21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 24 Dec 2015 13:23:01 +0100 Subject: [PATCH 12/34] Tweak sanitizing shell name Handles situation when the output is `/bin/shell- args...`. First strip away the arguments, then the trailing dash. --- libexec/rbenv-init | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv-init b/libexec/rbenv-init index 9fcfc2f4..7ddae5e5 100755 --- a/libexec/rbenv-init +++ b/libexec/rbenv-init @@ -34,8 +34,8 @@ done shell="$1" if [ -z "$shell" ]; then shell="$(ps -p "$PPID" -o 'args=' 2>/dev/null || true)" - shell="${shell##-}" shell="${shell%% *}" + shell="${shell##-}" shell="${shell:-$SHELL}" shell="${shell##*/}" fi From 7e5680a0d8c492c5af19358c543061a82dd7fcc4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 24 Dec 2015 18:04:17 +0100 Subject: [PATCH 13/34] Add configure + make step to installation instructions This compiles the `realpath` dynamic extension for bash which speeds up symlink resolution. If the extension doesn't compile due to cross-platform issues, rbenv will still work normally, although not as fast. --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 7b023676..7a517ed1 100644 --- a/README.md +++ b/README.md @@ -161,6 +161,13 @@ easy to fork and contribute any changes back upstream. $ git clone https://github.com/rbenv/rbenv.git ~/.rbenv ~~~ + Optionally, try to compile dynamic bash extension to speed up rbenv. Don't + worry if it fails; rbenv will still work normally: + + ~~~ + $ cd ~/.rbenv && src/configure && make -C src + ~~~ + 2. Add `~/.rbenv/bin` to your `$PATH` for access to the `rbenv` command-line utility. From 38692f97fec569b1a7fbc4209e800056ec547826 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 24 Dec 2015 18:18:44 +0100 Subject: [PATCH 14/34] vim ignores, the-silver-searcher ignores --- .agignore | 2 ++ .vimrc | 1 + 2 files changed, 3 insertions(+) create mode 100644 .agignore create mode 100644 .vimrc diff --git a/.agignore b/.agignore new file mode 100644 index 00000000..3a0f7841 --- /dev/null +++ b/.agignore @@ -0,0 +1,2 @@ +./versions +./cache diff --git a/.vimrc b/.vimrc new file mode 100644 index 00000000..e12e62f0 --- /dev/null +++ b/.vimrc @@ -0,0 +1 @@ +set wildignore+=versions/*,cache/* From e554cd86c3d0bf2599cca93b5ccbd5ba019bc03d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 24 Dec 2015 18:33:39 +0100 Subject: [PATCH 15/34] Strip leading `:` from RBENV_HOOK_PATH --- libexec/rbenv | 1 + test/rbenv.bats | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/libexec/rbenv b/libexec/rbenv index 795a2e9a..1ad36c95 100755 --- a/libexec/rbenv +++ b/libexec/rbenv @@ -84,6 +84,7 @@ RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib for plugin_hook in "${RBENV_ROOT}/plugins/"*/etc/rbenv.d; do RBENV_HOOK_PATH="${RBENV_HOOK_PATH}:${plugin_hook}" done +RBENV_HOOK_PATH="${RBENV_HOOK_PATH#:}" export RBENV_HOOK_PATH shopt -u nullglob diff --git a/test/rbenv.bats b/test/rbenv.bats index 4e6b32b0..6ded889c 100644 --- a/test/rbenv.bats +++ b/test/rbenv.bats @@ -71,5 +71,5 @@ load test_helper @test "RBENV_HOOK_PATH includes rbenv built-in plugins" { run rbenv echo "RBENV_HOOK_PATH" - assert_success ":${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" + assert_success "${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" } From e0b85397c8d1780908b2ffba10e35c1e676f0f71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 24 Dec 2015 19:11:39 +0100 Subject: [PATCH 16/34] Point out that it's not necessary to `sudo gem install` Closes #532 --- README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/README.md b/README.md index 7a517ed1..9dee46c1 100644 --- a/README.md +++ b/README.md @@ -293,6 +293,29 @@ that directory can also be a symlink to a Ruby version installed elsewhere on the filesystem. rbenv doesn't care; it will simply treat any entry in the `versions/` directory as a separate Ruby version. +#### Installing Ruby Gems + +Once you've installed some Ruby versions, you'll want to install gems. +First, ensure that the target version for your project is the one you want by +checking `rbenv version` (see [Command Reference](#command-reference)). Select +another version using `rbenv local 2.0.0-p247`, for example. Then, proceed to +install gems as you normally would: + +```sh +$ gem install bundler +``` + +**You don't need sudo** to install gems. Typically, the Ruby versions will be +installed and writeable by your user. No extra privileges are required to +install gems. + +Check the location where gems are being installed with `gem env`: + +```sh +$ gem env home +# => ~/.rbenv/versions//lib/ruby/gems/... +``` + ### Uninstalling Ruby Versions As time goes on, Ruby versions you install will accumulate in your From 3997a394d975136f468be196941492d3d0ef5143 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 24 Dec 2015 18:34:52 +0100 Subject: [PATCH 17/34] rbenv 1.0.0 --- libexec/rbenv---version | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libexec/rbenv---version b/libexec/rbenv---version index f3fba63d..b10e9a30 100755 --- a/libexec/rbenv---version +++ b/libexec/rbenv---version @@ -12,7 +12,7 @@ set -e [ -n "$RBENV_DEBUG" ] && set -x -version="0.4.0" +version="1.0.0" git_revision="" if cd "${BASH_SOURCE%/*}" 2>/dev/null && git remote -v 2>/dev/null | grep -q rbenv; then From c9c9415154fa60d316afedf3c470c37b4a0a9df7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 24 Dec 2015 20:01:36 +0100 Subject: [PATCH 18/34] Update ToC --- README.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 9dee46c1..a4394301 100644 --- a/README.md +++ b/README.md @@ -43,8 +43,9 @@ RVM?**](https://github.com/rbenv/rbenv/wiki/Why-rbenv%3F) * [Upgrading](#upgrading) * [Homebrew on Mac OS X](#homebrew-on-mac-os-x) * [How rbenv hooks into your shell](#how-rbenv-hooks-into-your-shell) - * [Installing Ruby Versions](#installing-ruby-versions) - * [Uninstalling Ruby Versions](#uninstalling-ruby-versions) + * [Installing Ruby versions](#installing-ruby-versions) + * [Installing Ruby gems](#installing-ruby-gems) + * [Uninstalling Ruby versions](#uninstalling-ruby-versions) * [Uninstalling rbenv](#uninstalling-rbenv) * [Command Reference](#command-reference) * [rbenv local](#rbenv-local) @@ -272,7 +273,7 @@ opposed to this idea. Here's what `rbenv init` actually does: Run `rbenv init -` for yourself to see exactly what happens under the hood. -### Installing Ruby Versions +### Installing Ruby versions The `rbenv install` command doesn't ship with rbenv out of the box, but is provided by the [ruby-build][] project. If you installed it either @@ -293,7 +294,7 @@ that directory can also be a symlink to a Ruby version installed elsewhere on the filesystem. rbenv doesn't care; it will simply treat any entry in the `versions/` directory as a separate Ruby version. -#### Installing Ruby Gems +#### Installing Ruby gems Once you've installed some Ruby versions, you'll want to install gems. First, ensure that the target version for your project is the one you want by @@ -316,7 +317,7 @@ $ gem env home # => ~/.rbenv/versions//lib/ruby/gems/... ``` -### Uninstalling Ruby Versions +### Uninstalling Ruby versions As time goes on, Ruby versions you install will accumulate in your `~/.rbenv/versions` directory. From abbcde665cd4cd7fed2138016f049b7385ea9116 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Thu, 24 Dec 2015 20:02:13 +0100 Subject: [PATCH 19/34] Fix ToC level [ci skip] --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index a4394301..b007759a 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,7 @@ RVM?**](https://github.com/rbenv/rbenv/wiki/Why-rbenv%3F) * [Homebrew on Mac OS X](#homebrew-on-mac-os-x) * [How rbenv hooks into your shell](#how-rbenv-hooks-into-your-shell) * [Installing Ruby versions](#installing-ruby-versions) - * [Installing Ruby gems](#installing-ruby-gems) + * [Installing Ruby gems](#installing-ruby-gems) * [Uninstalling Ruby versions](#uninstalling-ruby-versions) * [Uninstalling rbenv](#uninstalling-rbenv) * [Command Reference](#command-reference) From 22f4980a21cea538096ead610451bf32bd386c66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Fri, 25 Dec 2015 00:26:46 +0100 Subject: [PATCH 20/34] :fire: deprecated ruby-local-exec It was useless for a while now. I should have nuked it prior to the 1.0.0 release but I forgot :( --- bin/ruby-local-exec | 23 ----------------------- 1 file changed, 23 deletions(-) delete mode 100755 bin/ruby-local-exec diff --git a/bin/ruby-local-exec b/bin/ruby-local-exec deleted file mode 100755 index de57897c..00000000 --- a/bin/ruby-local-exec +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env bash -# -# `ruby-local-exec` is a drop-in replacement for the standard Ruby -# shebang line: -# -# #!/usr/bin/env ruby-local-exec -# -# Use it for scripts inside a project with an `.rbenv-version` -# file. When you run the scripts, they'll use the project-specified -# Ruby version, regardless of what directory they're run from. Useful -# for e.g. running project tasks in cron scripts without needing to -# `cd` into the project first. - -set -e -export RBENV_DIR="${1%/*}" - -[ -n "$RBENV_SILENCE_WARNINGS" ] || { - echo "rbenv: \`ruby-local-exec' is deprecated and will be removed in the next release." - echo " To upgrade: https://github.com/rbenv/rbenv/wiki/ruby-local-exec" - echo -} >&2 - -exec ruby "$@" From 3c9674453fe51b40acef22141ad477d8da86dc7e Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Mon, 28 Dec 2015 21:33:50 -0500 Subject: [PATCH 21/34] fix local --unset test --- test/local.bats | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/local.bats b/test/local.bats index a84833eb..368a8c0d 100644 --- a/test/local.bats +++ b/test/local.bats @@ -92,7 +92,7 @@ OUT touch .ruby-version run rbenv-local --unset assert_success "" - assert [ ! -e .rbenv-version ] + assert [ ! -e .ruby-version ] } @test "unsets alternate version file" { From f880dc6d6f65f2793f5f70fcb26e76f00033ec8b Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Mon, 28 Dec 2015 21:34:05 -0500 Subject: [PATCH 22/34] Remove support for legacy version file --- README.md | 5 ----- libexec/rbenv-local | 13 +---------- libexec/rbenv-version-file | 3 --- test/local.bats | 44 -------------------------------------- test/version-file.bats | 21 ------------------ test/version-origin.bats | 6 ------ 6 files changed, 1 insertion(+), 91 deletions(-) diff --git a/README.md b/README.md index b007759a..64e8a3c1 100644 --- a/README.md +++ b/README.md @@ -374,11 +374,6 @@ configured local version. You can also unset the local version: $ rbenv local --unset -Previous versions of rbenv stored local version specifications in a -file named `.rbenv-version`. For backwards compatibility, rbenv will -read a local version specified in an `.rbenv-version` file, but a -`.ruby-version` file in the same directory will take precedence. - ### rbenv global Sets the global version of Ruby to be used in all shells by writing diff --git a/libexec/rbenv-local b/libexec/rbenv-local index d5c5f11c..70c3751d 100755 --- a/libexec/rbenv-local +++ b/libexec/rbenv-local @@ -15,10 +15,6 @@ # `RBENV_VERSION' environment variable takes precedence over local # and global versions. # -# For backwards compatibility, rbenv will also read version -# specifications from `.rbenv-version' files, but a `.ruby-version' -# file in the same directory takes precedence. -# # should be a string matching a Ruby version known to rbenv. # The special version string `system' will use your default system Ruby. # Run `rbenv versions' for a list of available Ruby versions. @@ -36,16 +32,9 @@ fi RBENV_VERSION="$1" if [ "$RBENV_VERSION" = "--unset" ]; then - rm -f .ruby-version .rbenv-version + rm -f .ruby-version elif [ -n "$RBENV_VERSION" ]; then - previous_file="$(RBENV_VERSION= rbenv-version-origin || true)" rbenv-version-file-write .ruby-version "$RBENV_VERSION" - if [ "$previous_file" -ef .rbenv-version ]; then - rm -f .rbenv-version - { echo "rbenv: removed existing \`.rbenv-version' file and migrated" - echo " local version specification to \`.ruby-version' file" - } >&2 - fi else if version_file="$(rbenv-version-file "$PWD")"; then rbenv-version-file-read "$version_file" diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index 1e70539f..0e0c1484 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -12,9 +12,6 @@ find_local_version_file() { if [ -e "${root}/.ruby-version" ]; then echo "${root}/.ruby-version" return 0 - elif [ -e "${root}/.rbenv-version" ]; then - echo "${root}/.rbenv-version" - return 0 fi [ -n "$root" ] || break root="${root%/*}" diff --git a/test/local.bats b/test/local.bats index 368a8c0d..2d378c70 100644 --- a/test/local.bats +++ b/test/local.bats @@ -19,19 +19,6 @@ setup() { assert_success "1.2.3" } -@test "supports legacy .rbenv-version file" { - echo "1.2.3" > .rbenv-version - run rbenv-local - assert_success "1.2.3" -} - -@test "local .ruby-version has precedence over .rbenv-version" { - echo "1.8" > .rbenv-version - echo "2.0" > .ruby-version - run rbenv-local - assert_success "2.0" -} - @test "discovers version file in parent directory" { echo "1.2.3" > .ruby-version mkdir -p "subdir" && cd "subdir" @@ -64,40 +51,9 @@ setup() { assert [ "$(cat .ruby-version)" = "1.2.3" ] } -@test "renames .rbenv-version to .ruby-version" { - echo "1.8.7" > .rbenv-version - mkdir -p "${RBENV_ROOT}/versions/1.9.3" - run rbenv-local - assert_success "1.8.7" - run rbenv-local "1.9.3" - assert_success - assert_output < .rbenv-version - assert [ ! -e "${RBENV_ROOT}/versions/1.9.3" ] - run rbenv-local "1.9.3" - assert_failure "rbenv: version \`1.9.3' not installed" - assert [ ! -e .ruby-version ] - assert [ "$(cat .rbenv-version)" = "1.8.7" ] -} - @test "unsets local version" { touch .ruby-version run rbenv-local --unset assert_success "" assert [ ! -e .ruby-version ] } - -@test "unsets alternate version file" { - touch .rbenv-version - run rbenv-local --unset - assert_success "" - assert [ ! -e .rbenv-version ] -} diff --git a/test/version-file.bats b/test/version-file.bats index ef7901f4..f5c544cc 100644 --- a/test/version-file.bats +++ b/test/version-file.bats @@ -45,19 +45,6 @@ create_file() { assert_success "${RBENV_TEST_DIR}/.ruby-version" } -@test "legacy file in current directory" { - create_file ".rbenv-version" - run rbenv-version-file - assert_success "${RBENV_TEST_DIR}/.rbenv-version" -} - -@test ".ruby-version has precedence over legacy file" { - create_file ".ruby-version" - create_file ".rbenv-version" - run rbenv-version-file - assert_success "${RBENV_TEST_DIR}/.ruby-version" -} - @test "in parent directory" { create_file ".ruby-version" mkdir -p project @@ -74,14 +61,6 @@ create_file() { assert_success "${RBENV_TEST_DIR}/project/.ruby-version" } -@test "legacy file has precedence if higher" { - create_file ".ruby-version" - create_file "project/.rbenv-version" - cd project - run rbenv-version-file - assert_success "${RBENV_TEST_DIR}/project/.rbenv-version" -} - @test "RBENV_DIR has precedence over PWD" { create_file "widget/.ruby-version" create_file "project/.ruby-version" diff --git a/test/version-origin.bats b/test/version-origin.bats index 61e1dfe8..12da6be9 100644 --- a/test/version-origin.bats +++ b/test/version-origin.bats @@ -31,12 +31,6 @@ setup() { assert_success "${PWD}/.ruby-version" } -@test "detects alternate version file" { - touch .rbenv-version - run rbenv-version-origin - assert_success "${PWD}/.rbenv-version" -} - @test "reports from hook" { mkdir -p "${RBENV_ROOT}/rbenv.d/version-origin" cat > "${RBENV_ROOT}/rbenv.d/version-origin/test.bash" < Date: Mon, 28 Dec 2015 22:04:53 -0500 Subject: [PATCH 23/34] Remove support for legacy global version files `default` was made legacy back in 2011 with 5be66da9f4053137a320058495031d0af6db29b4 (the command was renamed from `rbenv-default` to `rbenv-global`, and so the global file was renamed from `$RBENV_ROOT/default` to `$RBENV_ROOT/global` (the latter taking precedence) `global` was then made legacy about a month later in Sep 2011 when the preferred filename was changed to `$RBENV_ROOT/version`. --- libexec/rbenv-global | 5 +---- libexec/rbenv-version-file | 10 +--------- test/global.bats | 4 ++-- test/version-file.bats | 24 +++++------------------- 4 files changed, 9 insertions(+), 34 deletions(-) diff --git a/libexec/rbenv-global b/libexec/rbenv-global index c003359b..6de25eea 100755 --- a/libexec/rbenv-global +++ b/libexec/rbenv-global @@ -27,8 +27,5 @@ RBENV_VERSION_FILE="${RBENV_ROOT}/version" if [ -n "$RBENV_VERSION" ]; then rbenv-version-file-write "$RBENV_VERSION_FILE" "$RBENV_VERSION" else - rbenv-version-file-read "$RBENV_VERSION_FILE" || - rbenv-version-file-read "${RBENV_ROOT}/global" || - rbenv-version-file-read "${RBENV_ROOT}/default" || - echo system + rbenv-version-file-read "$RBENV_VERSION_FILE" || echo system fi diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index 1e70539f..55adbeb0 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -25,15 +25,7 @@ find_local_version_file() { find_global_version_file() { local global_version_file="${RBENV_ROOT}/version" - if [ -e "$global_version_file" ]; then - echo "$global_version_file" - elif [ -e "${RBENV_ROOT}/global" ]; then - echo "${RBENV_ROOT}/global" - elif [ -e "${RBENV_ROOT}/default" ]; then - echo "${RBENV_ROOT}/default" - else - echo "$global_version_file" - fi + echo "$global_version_file" } if [ -n "$target_dir" ]; then diff --git a/test/global.bats b/test/global.bats index f6dcc3e1..0256bcb4 100644 --- a/test/global.bats +++ b/test/global.bats @@ -3,7 +3,7 @@ load test_helper @test "default" { - run rbenv global + run rbenv-global assert_success assert_output "system" } @@ -20,7 +20,7 @@ load test_helper mkdir -p "$RBENV_ROOT/versions/1.2.3" run rbenv-global "1.2.3" assert_success - run rbenv global + run rbenv-global assert_success "1.2.3" } diff --git a/test/version-file.bats b/test/version-file.bats index ef7901f4..1e2c28e2 100644 --- a/test/version-file.bats +++ b/test/version-file.bats @@ -12,29 +12,15 @@ create_file() { touch "$1" } -@test "prints global file if no version files exist" { - assert [ ! -e "${RBENV_ROOT}/version" ] - assert [ ! -e ".ruby-version" ] +@test "detects global 'version' file" { + create_file "${RBENV_ROOT}/version" run rbenv-version-file assert_success "${RBENV_ROOT}/version" } -@test "detects 'global' file" { - create_file "${RBENV_ROOT}/global" - run rbenv-version-file - assert_success "${RBENV_ROOT}/global" -} - -@test "detects 'default' file" { - create_file "${RBENV_ROOT}/default" - run rbenv-version-file - assert_success "${RBENV_ROOT}/default" -} - -@test "'version' has precedence over 'global' and 'default'" { - create_file "${RBENV_ROOT}/version" - create_file "${RBENV_ROOT}/global" - create_file "${RBENV_ROOT}/default" +@test "prints global file if no version files exist" { + assert [ ! -e "${RBENV_ROOT}/version" ] + assert [ ! -e ".ruby-version" ] run rbenv-version-file assert_success "${RBENV_ROOT}/version" } From a95ccd09a2c7cff435d915756abd5a2fe096fb9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mislav=20Marohni=C4=87?= Date: Tue, 29 Dec 2015 14:44:32 +0100 Subject: [PATCH 24/34] Simplify fallback to global version file --- libexec/rbenv-version-file | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/libexec/rbenv-version-file b/libexec/rbenv-version-file index 0cb8d554..0ea8d3aa 100755 --- a/libexec/rbenv-version-file +++ b/libexec/rbenv-version-file @@ -19,16 +19,10 @@ find_local_version_file() { return 1 } -find_global_version_file() { - local global_version_file="${RBENV_ROOT}/version" - - echo "$global_version_file" -} - if [ -n "$target_dir" ]; then find_local_version_file "$target_dir" else find_local_version_file "$RBENV_DIR" || { [ "$RBENV_DIR" != "$PWD" ] && find_local_version_file "$PWD" - } || find_global_version_file + } || echo "${RBENV_ROOT}/version" fi From 2cc2ec160ede7bbace8d51ee298c68fb2b5ff6ba Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 29 Dec 2015 11:12:22 -0500 Subject: [PATCH 25/34] Remove redundant test Spaces in hook path is tested in test/hooks.bats --- test/exec.bats | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/test/exec.bats b/test/exec.bats index aeb0456c..42948c5c 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -43,17 +43,6 @@ ruby OUT } -@test "supports hook path with spaces" { - hook_path="${RBENV_TEST_DIR}/custom stuff/rbenv hooks" - mkdir -p "${hook_path}/exec" - echo "export HELLO='from hook'" > "${hook_path}/exec/hello.bash" - - export RBENV_VERSION=system - RBENV_HOOK_PATH="$hook_path" run rbenv-exec env - assert_success - assert_line "HELLO=from hook" -} - @test "carries original IFS within hooks" { hook_path="${RBENV_TEST_DIR}/rbenv.d" mkdir -p "${hook_path}/exec" From 5ccba5d7cc38a31b464ce6299173b5f0056b428e Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 29 Dec 2015 10:53:01 -0500 Subject: [PATCH 26/34] Extract common create_hook helper --- test/rbenv.bats | 1 + test/test_helper.bash | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/test/rbenv.bats b/test/rbenv.bats index 6ded889c..0f305bca 100644 --- a/test/rbenv.bats +++ b/test/rbenv.bats @@ -70,6 +70,7 @@ load test_helper } @test "RBENV_HOOK_PATH includes rbenv built-in plugins" { + unset RBENV_HOOK_PATH run rbenv echo "RBENV_HOOK_PATH" assert_success "${RBENV_ROOT}/rbenv.d:${BATS_TEST_DIRNAME%/*}/rbenv.d:/usr/local/etc/rbenv.d:/etc/rbenv.d:/usr/lib/rbenv/hooks" } diff --git a/test/test_helper.bash b/test/test_helper.bash index b62cdc15..aef883a4 100644 --- a/test/test_helper.bash +++ b/test/test_helper.bash @@ -17,6 +17,7 @@ if [ -z "$RBENV_TEST_DIR" ]; then export RBENV_ROOT="${RBENV_TEST_DIR}/root" export HOME="${RBENV_TEST_DIR}/home" + export RBENV_HOOK_PATH="${RBENV_ROOT}/rbenv.d" PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin PATH="${RBENV_TEST_DIR}/bin:$PATH" @@ -129,3 +130,11 @@ path_without() { path="${path#:}" echo "${path%:}" } + +create_hook() { + mkdir -p "${RBENV_HOOK_PATH}/$1" + touch "${RBENV_HOOK_PATH}/$1/$2" + if [ ! -t 0 ]; then + cat > "${RBENV_HOOK_PATH}/$1/$2" + fi +} From 0f7a2cad8d497cce55b25035e4cf65a5bbe588de Mon Sep 17 00:00:00 2001 From: Jason Karns Date: Tue, 29 Dec 2015 11:01:10 -0500 Subject: [PATCH 27/34] Use create_hook helper Use extracted create_hook helper in tests for: - exec - hooks - rehash - version-name - version-origin - which --- test/exec.bats | 6 ++---- test/hooks.bats | 27 +++++++++++++-------------- test/rehash.bats | 6 ++---- test/version-name.bats | 8 ++------ test/version-origin.bats | 7 ++----- test/which.bats | 6 ++---- 6 files changed, 23 insertions(+), 37 deletions(-) diff --git a/test/exec.bats b/test/exec.bats index 42948c5c..5413912b 100644 --- a/test/exec.bats +++ b/test/exec.bats @@ -44,15 +44,13 @@ OUT } @test "carries original IFS within hooks" { - hook_path="${RBENV_TEST_DIR}/rbenv.d" - mkdir -p "${hook_path}/exec" - cat > "${hook_path}/exec/hello.bash" <" @@ -15,11 +10,13 @@ create_hook() { @test "prints list of hooks" { path1="${RBENV_TEST_DIR}/rbenv.d" path2="${RBENV_TEST_DIR}/etc/rbenv_hooks" - create_hook "$path1" exec "hello.bash" - create_hook "$path1" exec "ahoy.bash" - create_hook "$path1" exec "invalid.sh" - create_hook "$path1" which "boom.bash" - create_hook "$path2" exec "bueno.bash" + RBENV_HOOK_PATH="$path1" + create_hook exec "hello.bash" + create_hook exec "ahoy.bash" + create_hook exec "invalid.sh" + create_hook which "boom.bash" + RBENV_HOOK_PATH="$path2" + create_hook exec "bueno.bash" RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec assert_success @@ -33,8 +30,10 @@ OUT @test "supports hook paths with spaces" { path1="${RBENV_TEST_DIR}/my hooks/rbenv.d" path2="${RBENV_TEST_DIR}/etc/rbenv hooks" - create_hook "$path1" exec "hello.bash" - create_hook "$path2" exec "ahoy.bash" + RBENV_HOOK_PATH="$path1" + create_hook exec "hello.bash" + RBENV_HOOK_PATH="$path2" + create_hook exec "ahoy.bash" RBENV_HOOK_PATH="$path1:$path2" run rbenv-hooks exec assert_success @@ -45,8 +44,8 @@ OUT } @test "resolves relative paths" { - path="${RBENV_TEST_DIR}/rbenv.d" - create_hook "$path" exec "hello.bash" + RBENV_HOOK_PATH="${RBENV_TEST_DIR}/rbenv.d" + create_hook exec "hello.bash" mkdir -p "$HOME" RBENV_HOOK_PATH="${HOME}/../rbenv.d" run rbenv-hooks exec diff --git a/test/rehash.bats b/test/rehash.bats index 74f55a97..15d7a89b 100755 --- a/test/rehash.bats +++ b/test/rehash.bats @@ -105,15 +105,13 @@ OUT } @test "carries original IFS within hooks" { - hook_path="${RBENV_TEST_DIR}/rbenv.d" - mkdir -p "${hook_path}/rehash" - cat > "${hook_path}/rehash/hello.bash" < "${RBENV_ROOT}/rbenv.d/version-name/test.bash" < "${RBENV_ROOT}/rbenv.d/version-origin/test.bash" < "${hook_path}/which/hello.bash" < Date: Tue, 29 Dec 2015 11:15:27 -0500 Subject: [PATCH 28/34] Test IFS handling in version-name/version-origin hooks --- test/version-name.bats | 12 ++++++++++++ test/version-origin.bats | 12 ++++++++++++ 2 files changed, 24 insertions(+) diff --git a/test/version-name.bats b/test/version-name.bats index 6d19ab02..c240757c 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -31,6 +31,18 @@ setup() { assert_success "1.9.3" } +@test "carries original IFS within hooks" { + create_hook version-name hello.bash < Date: Mon, 1 Feb 2016 11:17:56 +0000 Subject: [PATCH 29/34] Updated Mac OSX brew install command It seems rbenv now comes with ruby-build. I have not investigated fully, but the previously shown command: `brew install rbenv ruby-build` caused issues on my machine. After uninstalling both and simply running `brew install rbenv` everything worked fine. --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 64e8a3c1..7f59ad2d 100644 --- a/README.md +++ b/README.md @@ -234,7 +234,7 @@ manager on Mac OS X: ~~~ $ brew update -$ brew install rbenv ruby-build +$ brew install rbenv ~~~ Afterwards you'll still need to add `eval "$(rbenv init -)"` to your From 35ca51fe881822cfa6d5e4ed5d54bedec2c66c3e Mon Sep 17 00:00:00 2001 From: David Celis Date: Fri, 12 Feb 2016 16:05:59 -0800 Subject: [PATCH 30/34] Update `rbenv init` instructions The README details `eval`ing `rbenv init -`, but for some shells (such as fish) there's a difference in what should be run. It turns out that `rbenv init` on its own will print correct instructions, so we should point users to running that command instead. --- README.md | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 7f59ad2d..6c624b69 100644 --- a/README.md +++ b/README.md @@ -180,13 +180,8 @@ easy to fork and contribute any changes back upstream. **Zsh note**: Modify your `~/.zshrc` file instead of `~/.bash_profile`. -3. Add `rbenv init` to your shell to enable shims and autocompletion. - - ~~~ sh - $ echo 'eval "$(rbenv init -)"' >> ~/.bash_profile - ~~~ - - _Same as in previous step, use `~/.bashrc` on Ubuntu, or `~/.zshrc` for Zsh._ +3. Run `~/.rbenv/bin/rbenv init` for shell-specific instructions on how to + initialize rbenv to enable shims and autocompletion. 4. Restart your shell so that PATH changes take effect. (Opening a new terminal tab will usually do it.) Now check if rbenv was set up: @@ -237,9 +232,8 @@ $ brew update $ brew install rbenv ~~~ -Afterwards you'll still need to add `eval "$(rbenv init -)"` to your -profile as stated in the caveats. You'll only ever have to do this -once. +Afterwards you'll still need to run `rbenv init` for instructions +as stated in the caveats. You'll only ever have to do this once. ### How rbenv hooks into your shell From 29b4da77370af0a3413dce00a72c7631302a2b25 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Fri, 19 Feb 2016 12:28:40 -0600 Subject: [PATCH 31/34] Adopt Contributor Covenant 1.4 --- CONDUCT.md | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 CONDUCT.md diff --git a/CONDUCT.md b/CONDUCT.md new file mode 100644 index 00000000..aebb7899 --- /dev/null +++ b/CONDUCT.md @@ -0,0 +1,80 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported by contacting one of the project maintainers listed below. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. + +## Project Maintainers + +* Sam Stephenson <> +* Mislav Marohnić <> +* Erik Michaels-Ober <> + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at [http://contributor-covenant.org/version/1/4][version] + +[homepage]: http://contributor-covenant.org +[version]: http://contributor-covenant.org/version/1/4/ From be3fc6d8cbfcd0648a67abdb1f618f311d7f6dea Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Fri, 4 Mar 2016 00:00:53 +0000 Subject: [PATCH 32/34] Fix broken `pyenv local` --- libexec/pyenv-local | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/libexec/pyenv-local b/libexec/pyenv-local index 7efbf2a8..8a2a6747 100755 --- a/libexec/pyenv-local +++ b/libexec/pyenv-local @@ -32,27 +32,17 @@ fi versions=("$@") if [ "$versions" = "--unset" ]; then - rm -f .python-version .pyenv-version + rm -f .python-version elif [ -n "$versions" ]; then - previous_file="$(PYENV_VERSION= pyenv-version-origin || true)" pyenv-version-file-write .python-version "${versions[@]}" - if [ "$previous_file" -ef .pyenv-version ]; then - rm -f .pyenv-version - { echo "pyenv: removed existing \`.pyenv-version' file and migrated" - echo " local version specification to \`.python-version' file" - } >&2 - fi else - OLDIFS="$IFS" - IFS=: versions=($( - pyenv-version-file-read .python-version || - pyenv-version-file-read .pyenv-version || - { echo "pyenv: no local version configured for this directory" - exit 1 - } >&2 - )) - IFS="$OLDIFS" - for version in "${versions[@]}"; do - echo "$version" - done + if version_file="$(pyenv-version-file "$PWD")"; then + IFS=: versions=($(pyenv-version-file-read "$version_file")) + for version in "${versions[@]}"; do + echo "$version" + done + else + echo "pyenv: no local version configured for this directory" >&2 + exit 1 + fi fi From fd893ea3b0309a84b28fc933ed0c49ee2189422c Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Fri, 4 Mar 2016 00:10:48 +0000 Subject: [PATCH 33/34] Fix broken test for `pyenv-version-name` --- test/version-name.bats | 44 +++++++++++++++++++++--------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/test/version-name.bats b/test/version-name.bats index e1d721b0..d0990473 100644 --- a/test/version-name.bats +++ b/test/version-name.bats @@ -47,25 +47,25 @@ SH create_version "2.7.11" create_version "3.5.1" - cat > ".python-version" <<<"2.7.6" + cat > ".python-version" <<<"2.7.11" run pyenv-version-name - assert_success "2.7.6" + assert_success "2.7.11" - PYENV_VERSION=3.3.3 run pyenv-version-name - assert_success "3.3.3" + PYENV_VERSION=3.5.1 run pyenv-version-name + assert_success "3.5.1" } @test "local file has precedence over global" { - create_version "2.7.6" - create_version "3.3.3" + create_version "2.7.11" + create_version "3.5.1" - cat > "${PYENV_ROOT}/version" <<<"2.7.6" + cat > "${PYENV_ROOT}/version" <<<"2.7.11" run pyenv-version-name - assert_success "2.7.6" + assert_success "2.7.11" - cat > ".python-version" <<<"3.3.3" + cat > ".python-version" <<<"3.5.1" run pyenv-version-name - assert_success "3.3.3" + assert_success "3.5.1" } @test "missing version" { @@ -74,22 +74,22 @@ SH } @test "one missing version (second missing)" { - create_version "3.4.2" - PYENV_VERSION="3.4.2:1.2" run pyenv-version-name + create_version "3.5.1" + PYENV_VERSION="3.5.1:1.2" run pyenv-version-name assert_failure assert_output < ".python-version" <<<"python-2.7.6" + create_version "2.7.11" + cat > ".python-version" <<<"python-2.7.11" run pyenv-version-name assert_success - assert_output "2.7.6" + assert_output "2.7.11" } From 30538b0672323fde4d6e733d9f08b4a656ccd90b Mon Sep 17 00:00:00 2001 From: "Yamashita, Yuu" Date: Fri, 4 Mar 2016 00:31:04 +0000 Subject: [PATCH 34/34] Fix broken tests for `pyenv---version` I need to use release date versioning at least for now until preparing custom version comparator for brew's formula. --- test/--version.bats | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/--version.bats b/test/--version.bats index 9f2d5cff..25721cfc 100644 --- a/test/--version.bats +++ b/test/--version.bats @@ -19,7 +19,7 @@ git_commit() { assert [ ! -e "$PYENV_ROOT" ] run pyenv---version assert_success - [[ $output == "ybenv "?.?.? ]] + [[ $output == "pyenv 20"* ]] } @test "doesn't read version from non-pyenv repo" { @@ -30,19 +30,19 @@ git_commit() { run pyenv---version assert_success - [[ $output == "pyenv "?.?.? ]] + [[ $output == "pyenv 20"* ]] } @test "reads version from git repo" { git init git remote add origin https://github.com/yyuu/pyenv.git git_commit - git tag v0.4.1 + git tag v20380119 git_commit git_commit run pyenv---version - assert_success "pyenv 0.4.1-2-g$(git rev-parse --short HEAD)" + assert_success "pyenv 20380119-2-g$(git rev-parse --short HEAD)" } @test "prints default version if no tags in git repo" { @@ -51,5 +51,5 @@ git_commit() { git_commit run pyenv---version - [[ $output == "pyenv "?.?.? ]] + [[ $output == "pyenv 20"* ]] }