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
1
Merge Requests
1
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
nexedi
gitlab-ce
Commits
fb0b4a31
Commit
fb0b4a31
authored
Sep 16, 2020
by
Markus Koller
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'release-tools/update-gitaly' into 'master'
Update Gitaly version See merge request gitlab-org/gitlab!42043
parents
a140300d
ab886fb2
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
48 additions
and
22 deletions
+48
-22
GITALY_SERVER_VERSION
GITALY_SERVER_VERSION
+1
-1
app/models/snippet.rb
app/models/snippet.rb
+9
-4
app/models/snippet_repository.rb
app/models/snippet_repository.rb
+1
-1
app/models/snippet_statistics.rb
app/models/snippet_statistics.rb
+1
-1
app/services/snippets/create_service.rb
app/services/snippets/create_service.rb
+1
-1
app/services/snippets/repository_validation_service.rb
app/services/snippets/repository_validation_service.rb
+2
-2
app/services/snippets/update_service.rb
app/services/snippets/update_service.rb
+1
-1
lib/gitlab/checks/snippet_check.rb
lib/gitlab/checks/snippet_check.rb
+4
-4
lib/gitlab/git_access_snippet.rb
lib/gitlab/git_access_snippet.rb
+1
-1
spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb
...ackground_migration/backfill_snippet_repositories_spec.rb
+1
-1
spec/lib/gitlab/checks/snippet_check_spec.rb
spec/lib/gitlab/checks/snippet_check_spec.rb
+12
-2
spec/models/snippet_repository_spec.rb
spec/models/snippet_repository_spec.rb
+3
-2
spec/models/snippet_spec.rb
spec/models/snippet_spec.rb
+10
-0
spec/models/snippet_statistics_spec.rb
spec/models/snippet_statistics_spec.rb
+1
-1
No files found.
GITALY_SERVER_VERSION
View file @
fb0b4a31
d2e978f8e8f47a49c3bcfbd470b2f790e52c5ee2
715240131ad98ef4cdd69c8344962099e25a54ee
app/models/snippet.rb
View file @
fb0b4a31
...
...
@@ -214,7 +214,7 @@ class Snippet < ApplicationRecord
def
blobs
return
[]
unless
repository_exists?
repository
.
ls_files
(
repository
.
root_ref
).
map
{
|
file
|
Blob
.
lazy
(
repository
,
repository
.
root_ref
,
file
)
}
repository
.
ls_files
(
default_branch
).
map
{
|
file
|
Blob
.
lazy
(
repository
,
default_branch
,
file
)
}
end
def
hook_attrs
...
...
@@ -309,6 +309,11 @@ class Snippet < ApplicationRecord
end
end
override
:default_branch
def
default_branch
super
||
'master'
end
def
repository_storage
snippet_repository
&
.
shard_name
||
self
.
class
.
pick_repository_storage
end
...
...
@@ -336,17 +341,17 @@ class Snippet < ApplicationRecord
def
file_name_on_repo
return
if
repository
.
empty?
list_files
(
repository
.
root_ref
).
first
list_files
(
default_branch
).
first
end
def
list_files
(
ref
=
nil
)
return
[]
if
repository
.
empty?
repository
.
ls_files
(
ref
)
repository
.
ls_files
(
ref
||
default_branch
)
end
def
multiple_files?
list_files
(
repository
.
root_ref
)
.
size
>
1
list_files
.
size
>
1
end
class
<<
self
...
...
app/models/snippet_repository.rb
View file @
fb0b4a31
...
...
@@ -93,7 +93,7 @@ class SnippetRepository < ApplicationRecord
end
def
get_last_empty_file_index
repository
.
ls_files
(
nil
).
inject
(
0
)
do
|
max
,
file
|
repository
.
ls_files
(
snippet
.
default_branch
).
inject
(
0
)
do
|
max
,
file
|
idx
=
file
[
EMPTY_FILE_PATTERN
,
1
].
to_i
[
idx
,
max
].
max
end
...
...
app/models/snippet_statistics.rb
View file @
fb0b4a31
...
...
@@ -25,7 +25,7 @@ class SnippetStatistics < ApplicationRecord
def
update_file_count
count
=
if
snippet
.
repository_exists?
repository
.
ls_files
(
repository
.
root_ref
).
size
repository
.
ls_files
(
snippet
.
default_branch
).
size
else
0
end
...
...
app/services/snippets/create_service.rb
View file @
fb0b4a31
...
...
@@ -82,7 +82,7 @@ module Snippets
def
create_commit
commit_attrs
=
{
branch_name:
'master'
,
branch_name:
@snippet
.
default_branch
,
message:
'Initial commit'
}
...
...
app/services/snippets/repository_validation_service.rb
View file @
fb0b4a31
...
...
@@ -39,7 +39,7 @@ module Snippets
def
check_branch_name_default!
branches
=
repository
.
branch_names
return
if
branches
.
first
==
Gitlab
::
Checks
::
SnippetCheck
::
DEFAULT_BRANCH
return
if
branches
.
first
==
snippet
.
default_branch
raise
RepositoryValidationError
,
_
(
'Repository has an invalid default branch name.'
)
end
...
...
@@ -51,7 +51,7 @@ module Snippets
end
def
check_file_count!
file_count
=
repository
.
ls_files
(
nil
).
size
file_count
=
repository
.
ls_files
(
snippet
.
default_branch
).
size
limit
=
Snippet
.
max_file_limit
(
current_user
)
if
file_count
>
limit
...
...
app/services/snippets/update_service.rb
View file @
fb0b4a31
...
...
@@ -93,7 +93,7 @@ module Snippets
raise
UpdateError
unless
snippet
.
snippet_repository
commit_attrs
=
{
branch_name:
'master'
,
branch_name:
snippet
.
default_branch
,
message:
'Update snippet'
}
...
...
lib/gitlab/checks/snippet_check.rb
View file @
fb0b4a31
...
...
@@ -3,7 +3,6 @@
module
Gitlab
module
Checks
class
SnippetCheck
<
BaseChecker
DEFAULT_BRANCH
=
'master'
.
freeze
ERROR_MESSAGES
=
{
create_delete_branch:
'You can not create or delete branches.'
}.
freeze
...
...
@@ -11,17 +10,18 @@ module Gitlab
ATTRIBUTES
=
%i[oldrev newrev ref branch_name tag_name logger]
.
freeze
attr_reader
(
*
ATTRIBUTES
)
def
initialize
(
change
,
logger
:)
def
initialize
(
change
,
default_branch
:,
logger
:)
@oldrev
,
@newrev
,
@ref
=
change
.
values_at
(
:oldrev
,
:newrev
,
:ref
)
@branch_name
=
Gitlab
::
Git
.
branch_name
(
@ref
)
@tag_name
=
Gitlab
::
Git
.
tag_name
(
@ref
)
@default_branch
=
default_branch
@logger
=
logger
@logger
.
append_message
(
"Running checks for ref:
#{
@branch_name
||
@tag_name
}
"
)
end
def
validate!
if
creation?
||
deletion?
if
!
@default_branch
||
creation?
||
deletion?
raise
GitAccess
::
ForbiddenError
,
ERROR_MESSAGES
[
:create_delete_branch
]
end
...
...
@@ -31,7 +31,7 @@ module Gitlab
private
def
creation?
@branch_name
!=
DEFAULT_BRANCH
&&
super
@branch_name
!=
@default_branch
&&
super
end
end
end
...
...
lib/gitlab/git_access_snippet.rb
View file @
fb0b4a31
...
...
@@ -119,7 +119,7 @@ module Gitlab
override
:check_single_change_access
def
check_single_change_access
(
change
,
_skip_lfs_integrity_check:
false
)
Checks
::
SnippetCheck
.
new
(
change
,
logger:
logger
).
validate!
Checks
::
SnippetCheck
.
new
(
change
,
default_branch:
snippet
.
default_branch
,
logger:
logger
).
validate!
Checks
::
PushFileCountCheck
.
new
(
change
,
repository:
repository
,
limit:
Snippet
.
max_file_limit
(
user
),
logger:
logger
).
validate!
rescue
Checks
::
TimedLogger
::
TimeoutError
raise
TimeoutError
,
logger
.
full_message
...
...
spec/lib/gitlab/background_migration/backfill_snippet_repositories_spec.rb
View file @
fb0b4a31
...
...
@@ -327,6 +327,6 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillSnippetRepositories, :migrat
end
def
ls_files
(
snippet
)
raw_repository
(
snippet
).
ls_files
(
nil
)
raw_repository
(
snippet
).
ls_files
(
snippet
.
default_branch
)
end
end
spec/lib/gitlab/checks/snippet_check_spec.rb
View file @
fb0b4a31
...
...
@@ -5,10 +5,12 @@ require 'spec_helper'
RSpec
.
describe
Gitlab
::
Checks
::
SnippetCheck
do
include_context
'change access checks context'
let
(
:snippet
)
{
create
(
:personal_snippet
,
:repository
)
}
let_it_be
(
:snippet
)
{
create
(
:personal_snippet
,
:repository
)
}
let
(
:user_access
)
{
Gitlab
::
UserAccessSnippet
.
new
(
user
,
snippet:
snippet
)
}
let
(
:default_branch
)
{
snippet
.
default_branch
}
subject
{
Gitlab
::
Checks
::
SnippetCheck
.
new
(
changes
,
logger:
logger
)
}
subject
{
Gitlab
::
Checks
::
SnippetCheck
.
new
(
changes
,
default_branch:
default_branch
,
logger:
logger
)
}
describe
'#validate!'
do
it
'does not raise any error'
do
...
...
@@ -39,5 +41,13 @@ RSpec.describe Gitlab::Checks::SnippetCheck do
end
end
end
context
'when default_branch is nil'
do
let
(
:default_branch
)
{
nil
}
it
'raises an error'
do
expect
{
subject
.
validate!
}.
to
raise_error
(
Gitlab
::
GitAccess
::
ForbiddenError
,
'You can not create or delete branches.'
)
end
end
end
end
spec/models/snippet_repository_spec.rb
View file @
fb0b4a31
...
...
@@ -108,6 +108,7 @@ RSpec.describe SnippetRepository do
before
do
allow
(
snippet
).
to
receive
(
:repository
).
and_return
(
repo
)
allow
(
repo
).
to
receive
(
:ls_files
).
and_return
([])
allow
(
repo
).
to
receive
(
:root_ref
).
and_return
(
'master'
)
end
it
'infers the commit action based on the parameters if not present'
do
...
...
@@ -197,7 +198,7 @@ RSpec.describe SnippetRepository do
shared_examples
'snippet repository with file names'
do
|*
filenames
|
it
'sets a name for unnamed files'
do
ls_files
=
snippet
.
repository
.
ls_files
(
nil
)
ls_files
=
snippet
.
repository
.
ls_files
(
snippet
.
default_branch
)
expect
(
ls_files
).
to
include
(
*
filenames
)
end
end
...
...
@@ -306,6 +307,6 @@ RSpec.describe SnippetRepository do
end
def
first_blob
(
snippet
)
snippet
.
repository
.
blob_at
(
'master'
,
snippet
.
repository
.
ls_files
(
nil
).
first
)
snippet
.
repository
.
blob_at
(
'master'
,
snippet
.
repository
.
ls_files
(
snippet
.
default_branch
).
first
)
end
end
spec/models/snippet_spec.rb
View file @
fb0b4a31
...
...
@@ -744,6 +744,16 @@ RSpec.describe Snippet do
subject
end
context
'when ref is nil'
do
let
(
:ref
)
{
nil
}
it
'lists files from the repository from the deafult_branch'
do
expect
(
snippet
.
repository
).
to
receive
(
:ls_files
).
with
(
snippet
.
default_branch
)
subject
end
end
end
context
'when snippet does not have a repository'
do
...
...
spec/models/snippet_statistics_spec.rb
View file @
fb0b4a31
...
...
@@ -36,7 +36,7 @@ RSpec.describe SnippetStatistics do
subject
{
statistics
.
update_file_count
}
it
'updates the count of files'
do
file_count
=
snippet_with_repo
.
repository
.
ls_files
(
nil
).
count
file_count
=
snippet_with_repo
.
repository
.
ls_files
(
snippet_with_repo
.
default_branch
).
count
subject
...
...
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