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
d76416f5
Commit
d76416f5
authored
8 years ago
by
Grzegorz Bizon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Evade some exceptions when using invalid references
parent
c8e8a1bb
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
1 deletion
+54
-1
app/models/repository.rb
app/models/repository.rb
+5
-1
spec/models/repository_spec.rb
spec/models/repository_spec.rb
+49
-0
No files found.
app/models/repository.rb
View file @
d76416f5
...
...
@@ -84,15 +84,17 @@ class Repository
def
commit
(
ref
=
'HEAD'
)
return
nil
unless
exists?
commit
=
if
ref
.
is_a?
(
Gitlab
::
Git
::
Commit
)
ref
else
Gitlab
::
Git
::
Commit
.
find
(
raw_repository
,
ref
)
end
commit
=
::
Commit
.
new
(
commit
,
@project
)
if
commit
commit
rescue
Rugged
::
OdbError
rescue
Rugged
::
OdbError
,
Rugged
::
TreeError
nil
end
...
...
@@ -232,6 +234,8 @@ class Repository
def
ref_exists?
(
ref
)
rugged
.
references
.
exist?
(
ref
)
rescue
Rugged
::
ReferenceError
false
end
def
update_ref!
(
name
,
newrev
,
oldrev
)
...
...
This diff is collapsed.
Click to expand it.
spec/models/repository_spec.rb
View file @
d76416f5
...
...
@@ -113,6 +113,26 @@ describe Repository, models: true do
end
end
describe
'#ref_exists?'
do
context
'when ref exists'
do
it
'returns true'
do
expect
(
repository
.
ref_exists?
(
'refs/heads/master'
)).
to
be
true
end
end
context
'when ref does not exist'
do
it
'returns false'
do
expect
(
repository
.
ref_exists?
(
'refs/heads/non-existent'
)).
to
be
false
end
end
context
'when ref format is incorrect'
do
it
'returns false'
do
expect
(
repository
.
ref_exists?
(
'refs/heads/invalid:master'
)).
to
be
false
end
end
end
describe
'#last_commit_for_path'
do
subject
{
repository
.
last_commit_for_path
(
sample_commit
.
id
,
'.gitignore'
).
id
}
...
...
@@ -197,6 +217,35 @@ describe Repository, models: true do
end
end
describe
'#commit'
do
context
'when ref exists'
do
it
'returns commit object'
do
expect
(
repository
.
commit
(
'master'
))
.
to
be_an_instance_of
Commit
end
end
context
'when ref does not exist'
do
it
'returns nil'
do
expect
(
repository
.
commit
(
'non-existent-ref'
)).
to
be_nil
end
end
context
'when ref is not valid'
do
context
'when preceding tree element exists'
do
it
'returns nil'
do
expect
(
repository
.
commit
(
'master:ref'
)).
to
be_nil
end
end
context
'when preceding tree element does not exist'
do
it
'returns nil'
do
expect
(
repository
.
commit
(
'non-existent:ref'
)).
to
be_nil
end
end
end
end
describe
"#commit_dir"
do
it
"commits a change that creates a new directory"
do
expect
do
...
...
This diff is collapsed.
Click to expand it.
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