Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
gitlab-ce
Commits
ab814e4d
Commit
ab814e4d
authored
Nov 08, 2017
by
Michael Kozono
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Backport `which` from EE
parent
d6435b68
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
1 deletion
+26
-1
lib/gitlab/utils.rb
lib/gitlab/utils.rb
+17
-0
spec/lib/gitlab/utils_spec.rb
spec/lib/gitlab/utils_spec.rb
+9
-1
No files found.
lib/gitlab/utils.rb
View file @
ab814e4d
...
@@ -46,5 +46,22 @@ module Gitlab
...
@@ -46,5 +46,22 @@ module Gitlab
def
random_string
def
random_string
Random
.
rand
(
Float
::
MAX
.
to_i
).
to_s
(
36
)
Random
.
rand
(
Float
::
MAX
.
to_i
).
to_s
(
36
)
end
end
# See: http://stackoverflow.com/questions/2108727/which-in-ruby-checking-if-program-exists-in-path-from-ruby
# Cross-platform way of finding an executable in the $PATH.
#
# which('ruby') #=> /usr/bin/ruby
def
which
(
cmd
,
env
=
ENV
)
exts
=
env
[
'PATHEXT'
]
?
env
[
'PATHEXT'
].
split
(
';'
)
:
[
''
]
env
[
'PATH'
].
split
(
File
::
PATH_SEPARATOR
).
each
do
|
path
|
exts
.
each
do
|
ext
|
exe
=
File
.
join
(
path
,
"
#{
cmd
}#{
ext
}
"
)
return
exe
if
File
.
executable?
(
exe
)
&&
!
File
.
directory?
(
exe
)
end
end
nil
end
end
end
end
end
spec/lib/gitlab/utils_spec.rb
View file @
ab814e4d
require
'spec_helper'
require
'spec_helper'
describe
Gitlab
::
Utils
do
describe
Gitlab
::
Utils
do
delegate
:to_boolean
,
:boolean_to_yes_no
,
:slugify
,
:random_string
,
to: :described_class
delegate
:to_boolean
,
:boolean_to_yes_no
,
:slugify
,
:random_string
,
:which
,
to: :described_class
describe
'.slugify'
do
describe
'.slugify'
do
{
{
...
@@ -59,4 +59,12 @@ describe Gitlab::Utils do
...
@@ -59,4 +59,12 @@ describe Gitlab::Utils do
expect
(
random_string
).
to
be_kind_of
(
String
)
expect
(
random_string
).
to
be_kind_of
(
String
)
end
end
end
end
describe
'.which'
do
it
'finds the full path to an executable binary'
do
expect
(
File
).
to
receive
(
:executable?
).
with
(
'/bin/sh'
).
and_return
(
true
)
expect
(
which
(
'sh'
,
'PATH'
=>
'/bin'
)).
to
eq
(
'/bin/sh'
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment