piotrmurach/tty-pager

Pager throws exception if git is not installed

slowbro opened this issue · 8 comments

I have a feeling this is due to not checking if there is a 'git' executable before doing over this section:

def self.executables
[ENV['GIT_PAGER'], ENV['PAGER'],
`git config --get-all core.pager`,
'less', 'more', 'cat', 'pager']
end

The solution was to just install git, but it would be great if the lib checked for git first.

Hi Katelyn,

Thank you for trying this library out!

I agree with you that checking for git executable is important but as far as this library goes that's exactly what happens. The executables is an array of binaries but the real usage happens here https://github.com/piotrmurach/tty-pager/blob/master/lib/tty/pager/system.rb#L47 where each command is checked for existence. This check is done based on PATH environment variable which in your case must have contained git even when it was not installed. Is this possible?

Ah, that's odd! I already installed it, but let me see if I can replicate the issue. It shouldn't have been in my PATH. This is on FreeBSD, too, so maybe that command behaves differently. I'll update later today with what I can find!

Also, great libs. We just started using tty-* for all our internal CLI utils, and it's made them 1000% prettier.

Alright, here is an example of it not working.

#!/usr/bin/env ruby
require 'tty-pager'

pager = TTY::Pager.new

info = "info"*600000

pager.page(info)
$ ./test.rb
/usr/local/lib/ruby/gems/2.3/gems/tty-pager-0.10.0/lib/tty/pager/system.rb:102:in ``': No such file or directory - git (Errno::ENOENT)
        from /usr/local/lib/ruby/gems/2.3/gems/tty-pager-0.10.0/lib/tty/pager/system.rb:102:in `executables'
        from /usr/local/lib/ruby/gems/2.3/gems/tty-pager-0.10.0/lib/tty/pager/system.rb:44:in `available'
        from /usr/local/lib/ruby/gems/2.3/gems/tty-pager-0.10.0/lib/tty/pager/system.rb:62:in `available?'
        from /usr/local/lib/ruby/gems/2.3/gems/tty-pager-0.10.0/lib/tty/pager.rb:93:in `find_available'
        from /usr/local/lib/ruby/gems/2.3/gems/tty-pager-0.10.0/lib/tty/pager.rb:31:in `initialize'
        from ./test.rb:4:in `new'
        from ./test.rb:4:in `<main>'
[katelyn@holp ~]$ sudo pkg info | grep git
[katelyn@holp ~]$ which git
[katelyn@holp ~]$ echo $PATH
/sbin:/bin:/usr/sbin:/usr/bin:/usr/games:/usr/local/sbin:/usr/local/bin:/home/k/katelyn/bin

I verified that git is not in any of the directories in my PATH.

$ ruby -v
ruby 2.3.0p0 (2015-12-25 revision 53290) [amd64-freebsd10]
$ gem list tty-pager

*** LOCAL GEMS ***

tty-pager (0.10.0)

I think this is just being caused by the backticks in 'executables'. It's making ruby execute it when you set it there, and not at L47.

That would be great help!

Thank you for using tty-* gems, that makes it more worthwhile developing them and I'm also glad they make your CLI utils look great ✨

Thank you for looking into this. I agree that the cause is probably the backticks execution.

Would you have time to submit PR fixing this? A test case trapping this bug would be great as well.

PR#1 (woot!) is in now.

Whoops, i messed up that PR.. did it on my own project :| actually submitted, now

Released v0.11.0 with your fix!