Commit graph

130 commits

Author SHA1 Message Date
Daniel Hahler d061cb4651 Have rbenv init print instructions that hardcode the detected shell
This speeds up subsequent `rbenv init -` executions for the user who
followed these instructions because the shell will no longer have to be
detected each time.
2021-05-06 00:43:16 +02:00
Mislav Marohnić 059bb2c151
Merge pull request #1243 from scop/nounset
Make work in set -u (nounset) mode
2021-05-06 00:13:20 +02:00
Mislav Marohnić dcba8b4064 Supply head -n flag explicitly
The syntax `head -NUM` was deprecated in the POSIX standard.
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/head.html
2021-05-05 22:42:56 +02:00
Ville Skyttä 6b842a7670 test(init): remove misleading arg in detect from parent shell case
The generated script does not take/use any arguments, so passing
/bin/zsh to it serves only to cause confusion.
2021-03-23 23:41:55 +02:00
Hiroshi SHIBATA 4086bbe562
Merge pull request #1119 from blueyed/test-run
test/run: handle optional paths/args for bats
2020-12-03 13:41:17 +09:00
Ville Skyttä a5a1c4d50d Make work in set -u (nounset) mode 2020-05-24 09:08:05 +03:00
Ville Skyttä 59004d77ed Spelling fix 2020-04-23 07:59:28 +03:00
Roman Levin 74c2486a2c Fix fish instructions test 2020-02-17 21:46:25 +01:00
Mislav Marohnić 569d464d36 Remove fish completion script
fish ships with a much more capable rbenv completion script since fish 2.0.

Fixes #1212
2020-01-28 17:47:59 +01:00
Jeffrey 'jf' Lim 137e705db7 Fix (revert) test/version-origin.bats 2020-01-16 23:24:42 +08:00
Jeffrey 'jf' Lim 40db754168 Fix tests for #1203 2020-01-08 16:41:14 +08:00
Mislav Marohnić 370c26a6c9 Disallow path segments and directory traversal in .ruby-version files
A malicious `.ruby-version` file in the current directory could inject
`../../../` into the version string and trigger execution of binaries
outside of `RBENV_ROOT/versions/`.

Fixes #977 OVE-20170303-0004
2019-04-03 12:58:25 +02:00
Daniel Hahler ae2e7a3f0b test/run: handle optional paths/args for bats
This allows to run a single test file more easily, although that could be
done by calling bats directly.
2018-09-19 08:24:48 +02:00
Daniel Hahler 806f3f6ae2 rbenv-prefix: do not silence rbenv-which for system version
This suppressed any output when using RBENV_DEBUG=1 and does not really
hurt to have in the unlikely case that it should fail; you would get
two error messages now:

rbenv: ruby: command not found
rbenv: system version not found in PATH
2018-08-07 01:44:13 +02:00
Victor Lim 9daf81f16e Fix https://github.com/rbenv/rbenv/issues/1065
Command `rbenv version-name > .ruby-version` will create an empty `.ruby-version` file
before running `rbenv-version-file`. This causes `rbenv-version-file` to return empty
string which in turn causes `rbenv-version-name` to return `system`.

Ensure size of `.ruby-version` is non-zero as a workaround.
2018-02-26 16:49:37 +08:00
Marco Hinz 643023d98f
Add tests for shell integration 2017-12-07 02:32:35 +01:00
Daniel Hahler a9ca72ab8e test/which.bats: do not export PATH
Otherwise `sed` might not be found later in bats/libexec/bats-exec-test,
in case `/usr/bin` gets removed.
2017-11-20 04:22:05 +01:00
Jeff Kowalski a81da8d864 Revert quoting change in previous commit; adjust test to match code
Revert back to original quoting style used before previous commit.
Adjust init.bats to reflect changes for successful tests.
2017-05-16 13:36:06 -07:00
Jason Karns 8eb97549e1
Conforms OLD_RBENV_VERSION to RBENV_* convention
Keeping rbenv-controlled variables to RBENV_* "namespace" helps with
discoverability (and tools like rbenv-env) but also consistency and a
very minor degree of safety/isolation from env impact.
2016-12-19 17:21:45 -05:00
Mislav Marohnić 6ced4e25de Merge pull request #873 from dmerand/patch-1
Fish shell "." is deprecated in favor of "source"
2016-11-25 20:32:54 +01:00
Mislav Marohnić 2207c27cb4 Merge branch 'shell-undo' 2016-11-25 20:26:24 +01:00
Mislav Marohnić c4d97ad392 Finalize rbenv shell - implementation
This ensures that OLD_RBENV_VERSION is never exported. This makes the
implementation a little bit more complex, since more logic needs to be
pushed down into eval'd code.
2016-11-25 20:24:16 +01:00
Yamashita, Yuu 36138f4901 Rewrite with using here document syntax 2016-08-03 06:29:59 +00:00
Yamashita, Yuu 83e874a165 Add explicit shebang to executable for testing 2016-08-03 01:33:35 +00:00
Yamashita, Yuu 8eefa41a4d Remove useless touch line 2016-08-03 00:58:05 +00:00
Yamashita, Yuu a456528be8 Keep original ordering of PATH configuration 2016-08-02 00:21:28 +00:00
Yamashita, Yuu 2485257424 Add a test to confirm the prefix doesn't work fine with /bin/ruby 2016-08-01 00:31:11 +00:00
Donald Merand 8b0b51a166 convert references to '.' to 'source' for fish shell 2016-02-20 10:27:39 -05:00
Aaron Patterson 6a912bf104 add support for rbenv shell -
`rbenv shell -` allows you to switch to the previously activated ruby
version.  Similar to `cd -` or `git checkout -`.

This tries to implement `rbenv shell -` as proposed in #854.  However,
adding support seemed to break the "shell change version" test.  I'm not
very good at Bash programming, can someone tell me what is wrong with
what I'm doing?  I'd like to add a bit more functionality to this, but
I'm really just cargo cult programming Bash.

Thank you!

fix tests
2016-01-12 15:32:59 -08:00
Jason Karns 565798d617 Test IFS handling in version-name/version-origin hooks 2016-01-04 09:14:28 -05:00
Jason Karns 0f7a2cad8d Use create_hook helper
Use extracted create_hook helper in tests for:

- exec
- hooks
- rehash
- version-name
- version-origin
- which
2016-01-04 09:14:25 -05:00
Jason Karns 5ccba5d7cc Extract common create_hook helper 2016-01-04 09:14:04 -05:00
Jason Karns 2cc2ec160e Remove redundant test
Spaces in hook path is tested in test/hooks.bats
2016-01-04 09:13:58 -05:00
Mislav Marohnić e199a3d8f7 Merge pull request #850 from jasonkarns/remove-legacy-global-version-file
Remove support for legacy global version files
2015-12-29 14:40:37 +01:00
Jason Karns fe809ea90d Remove support for legacy global version files
`default` was made legacy back in 2011 with
5be66da9f4 (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`.
2015-12-28 22:05:00 -05:00
Jason Karns f880dc6d6f Remove support for legacy version file 2015-12-28 21:34:07 -05:00
Jason Karns 3c9674453f fix local --unset test 2015-12-28 21:33:50 -05:00
Mislav Marohnić e554cd86c3 Strip leading : from RBENV_HOOK_PATH 2015-12-24 19:12:47 +01:00
Mislav Marohnić f9d8b551dc Add test for detecting shell when rbenv init is called from script
References #730
2015-12-24 13:20:49 +01:00
Mislav Marohnić 1a0be6f0ad 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.
2015-12-24 03:52:33 +01:00
Mislav Marohnić 6481cbb172 Merge branch 'version-hooks'
Closes #739
2015-12-23 17:42:44 +01:00
Mislav Marohnić 6e30032278 Simplify version-name, version-origin hook tests
No need for helper function that's gonna be used just once.
2015-12-23 17:39:14 +01:00
Mislav Marohnić 4fde4ecbaf 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.
2015-12-23 17:26:53 +01:00
Mislav Marohnić 40c1d27445 Merge remote-tracking branch 'origin/master' into version-hooks 2015-12-23 17:22:43 +01:00
Jason Karns c3a5f91ed0 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.
2015-12-23 17:22:31 +01:00
Jason Karns 258e4413b1 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.
2015-12-23 17:22:30 +01:00
Mislav Marohnić ba072adcb9 Have rbenv local read version from parent directories as well
Fixes #807
2015-12-23 15:21:24 +01:00
Mislav Marohnić ca25259900 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.
2015-12-23 15:19:54 +01:00
Mislav Marohnić 90373d78b9 Add test for not including current directory in PATH search
Confirms #836
2015-12-14 11:59:01 +01:00
Chulki Lee df4c16ecb4 update urls to rbenv 2015-12-07 11:03:07 -08:00