Skip to content

Commit

Permalink
Closes #196 fixing PATH issue with hook when ran from Git GUI Clients
Browse files Browse the repository at this point in the history
Also, this fix most likely closes many other issues around the same
problem, will try to verify on various clients.
  • Loading branch information
matthutchinson committed Sep 10, 2014
1 parent 0507b20 commit 07b7789
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
9 changes: 6 additions & 3 deletions lib/lolcommits/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -213,15 +213,18 @@ def self.can_animate?
end

# Cross-platform way of finding an executable in the $PATH.
# idea taken from http://bit.ly/qDaTbY
# idea taken from http://bit.ly/qDaTbY, if only_path is true, only the path
# is returned (not the path and command)
#
# which('ruby') #=> /usr/bin/ruby
def self.command_which(cmd)
def self.command_which(cmd, only_path = false)
exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
exts.each do |ext|
exe = "#{path}/#{cmd}#{ext}"
return exe if File.executable? exe
if File.executable? exe
return only_path ? path : exe
end
end
end
nil
Expand Down
5 changes: 3 additions & 2 deletions lib/lolcommits/installation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ def self.do_disable
protected

def self.hook_script(add_shebang = true)
ruby_path = Lolcommits::Configuration.command_which('ruby')
hook_export = "export PATH=\"#{ruby_path}:$PATH\"\n" if ruby_path
ruby_path = Lolcommits::Configuration.command_which('ruby', true)
imagick_path = Lolcommits::Configuration.command_which('identify', true)
hook_export = "export PATH=\"#{ruby_path}:#{imagick_path}:$PATH\"\n"
capture_cmd = 'lolcommits --capture'
capture_args = " #{ARGV[1..-1].join(' ')}" if ARGV.length > 1

Expand Down
4 changes: 2 additions & 2 deletions rubocop-todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ UselessAssignment:
Documentation:
Enabled: false

# Offence count: 2
# Offence count: 3
# Configuration parameters: CountComments.
ClassLength:
Max: 178
Max: 179

# Offence count: 73
LineLength:
Expand Down

0 comments on commit 07b7789

Please sign in to comment.