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
cb20cfa2
Commit
cb20cfa2
authored
Apr 05, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Retrieve Git-specific env in Gitlab::Git::Repository#rugged
Signed-off-by:
Rémy Coutable
<
remy@rymai.me
>
parent
710cd82c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletion
+39
-1
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+9
-1
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+30
-0
No files found.
lib/gitlab/git/repository.rb
View file @
cb20cfa2
...
...
@@ -8,6 +8,10 @@ module Gitlab
class
Repository
include
Gitlab
::
Git
::
Popen
ALLOWED_OBJECT_DIRECTORIES_VARIABLES
=
%w[
GIT_OBJECT_DIRECTORY
GIT_ALTERNATE_OBJECT_DIRECTORIES
]
.
freeze
SEARCH_CONTEXT_LINES
=
3
NoRepository
=
Class
.
new
(
StandardError
)
...
...
@@ -58,7 +62,7 @@ module Gitlab
end
def
rugged
@rugged
||=
Rugged
::
Repository
.
new
(
path
)
@rugged
||=
Rugged
::
Repository
.
new
(
path
,
alternates:
alternate_object_directories
)
rescue
Rugged
::
RepositoryError
,
Rugged
::
OSError
raise
NoRepository
.
new
(
'no repository for such path'
)
end
...
...
@@ -978,6 +982,10 @@ module Gitlab
private
def
alternate_object_directories
Gitlab
::
Git
::
Env
.
all
.
values_at
(
*
ALLOWED_OBJECT_DIRECTORIES_VARIABLES
).
compact
end
# Get the content of a blob for a given commit. If the blob is a commit
# (for submodules) then return the blob's OID.
def
blob_content
(
commit
,
blob_name
)
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
cb20cfa2
...
...
@@ -40,6 +40,36 @@ describe Gitlab::Git::Repository, seed_helper: true do
end
end
describe
"#rugged"
do
context
'with no Git env stored'
do
before
do
expect
(
Gitlab
::
Git
::
Env
).
to
receive
(
:all
).
and_return
({})
end
it
"whitelist some variables and pass them via the alternates keyword argument"
do
expect
(
Rugged
::
Repository
).
to
receive
(
:new
).
with
(
repository
.
path
,
alternates:
[])
repository
.
rugged
end
end
context
'with some Git env stored'
do
before
do
expect
(
Gitlab
::
Git
::
Env
).
to
receive
(
:all
).
and_return
({
'GIT_OBJECT_DIRECTORY'
=>
'foo'
,
'GIT_ALTERNATE_OBJECT_DIRECTORIES'
=>
'bar'
,
'GIT_OTHER'
=>
'another_env'
})
end
it
"whitelist some variables and pass them via the alternates keyword argument"
do
expect
(
Rugged
::
Repository
).
to
receive
(
:new
).
with
(
repository
.
path
,
alternates:
%w[foo bar]
)
repository
.
rugged
end
end
end
describe
"#discover_default_branch"
do
let
(
:master
)
{
'master'
}
let
(
:feature
)
{
'feature'
}
...
...
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