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
140ac8d2
Commit
140ac8d2
authored
Aug 23, 2017
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add changelog and tests
parent
5f811894
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
88 additions
and
3 deletions
+88
-3
app/services/projects/import_export/cleanup_service.rb
app/services/projects/import_export/cleanup_service.rb
+4
-1
changelogs/unreleased/36807-gc-unwanted-refs-after-import.yml
...gelogs/unreleased/36807-gc-unwanted-refs-after-import.yml
+5
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+11
-2
spec/services/projects/housekeeping_service_spec.rb
spec/services/projects/housekeeping_service_spec.rb
+13
-0
spec/services/projects/import_export/cleanup_service_spec.rb
spec/services/projects/import_export/cleanup_service_spec.rb
+55
-0
No files found.
app/services/projects/import_export/cleanup_service.rb
View file @
140ac8d2
module
Projects
module
ImportExport
class
CleanupService
RESERVED_REFS_NAMES
=
%w[heads tags merge-requests keep-around environments]
RESERVED_REFS_REGEXP
=
%r{
\A
refs/(?:heads|tags|merge
\-
requests|keep
\-
around|environments)/}
%r{
\A
refs/(?:
#{
RESERVED_REFS_NAMES
.
map
(
&
Regexp
.
method
(
:escape
)).
join
(
'|'
)
}
)/}x
attr_reader
:project
...
...
changelogs/unreleased/36807-gc-unwanted-refs-after-import.yml
0 → 100644
View file @
140ac8d2
---
title
:
Remove unwanted refs after importing a project
merge_request
:
13766
author
:
type
:
other
spec/models/project_spec.rb
View file @
140ac8d2
...
...
@@ -1563,10 +1563,18 @@ describe Project do
describe
'project import state transitions'
do
context
'state transition: [:started] => [:finished]'
do
let
(
:housekeeping_service
)
{
spy
}
let
(
:cleanup_service
)
{
spy
(
:cleanup_service
)
}
let
(
:housekeeping_service
)
{
spy
(
:housekeeping_service
)
}
before
do
allow
(
Projects
::
HousekeepingService
).
to
receive
(
:new
)
{
housekeeping_service
}
allow
(
Projects
::
ImportExport
::
CleanupService
)
.
to
receive
(
:new
)
{
cleanup_service
}
allow
(
cleanup_service
)
.
to
receive
(
:execute
)
{
housekeeping_service
.
execute
}
allow
(
Projects
::
HousekeepingService
)
.
to
receive
(
:new
)
{
housekeeping_service
}
end
it
'resets project import_error'
do
...
...
@@ -1581,6 +1589,7 @@ describe Project do
project
.
import_finish
expect
(
cleanup_service
).
to
have_received
(
:execute
)
expect
(
housekeeping_service
).
to
have_received
(
:execute
)
end
...
...
spec/services/projects/housekeeping_service_spec.rb
View file @
140ac8d2
...
...
@@ -23,6 +23,12 @@ describe Projects::HousekeepingService do
expect
(
project
.
reload
.
pushes_since_gc
).
to
eq
(
0
)
end
it
'yields the block if given'
do
expect
do
|
b
|
subject
.
execute
(
&
b
)
end
.
to
yield_with_no_args
end
context
'when no lease can be obtained'
do
before
do
expect
(
subject
).
to
receive
(
:try_obtain_lease
).
and_return
(
false
)
...
...
@@ -39,6 +45,13 @@ describe Projects::HousekeepingService do
expect
{
subject
.
execute
}.
to
raise_error
(
Projects
::
HousekeepingService
::
LeaseTaken
)
end
.
not_to
change
{
project
.
pushes_since_gc
}
end
it
'does not yield'
do
expect
do
|
b
|
expect
{
subject
.
execute
(
&
b
)
}
.
to
raise_error
(
Projects
::
HousekeepingService
::
LeaseTaken
)
end
.
not_to
yield_with_no_args
end
end
end
...
...
spec/services/projects/import_export/cleanup_service_spec.rb
0 → 100644
View file @
140ac8d2
require
'spec_helper'
describe
Projects
::
ImportExport
::
CleanupService
do
subject
{
described_class
.
new
(
project
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:repository
)
{
project
.
repository
}
let
(
:sha
)
{
project
.
commit
.
sha
}
let
(
:housekeeping_service
)
{
double
(
:housekeeping_service
)
}
describe
'#execute'
do
before
do
allow
(
Projects
::
HousekeepingService
)
.
to
receive
(
:new
).
with
(
project
).
and_return
(
housekeeping_service
)
allow
(
housekeeping_service
)
.
to
receive
(
:execute
).
and_yield
end
it
'performs housekeeping'
do
subject
.
execute
expect
(
housekeeping_service
).
to
have_received
(
:execute
)
end
context
'with some refs in refs/pull/**/*'
do
before
do
repository
.
write_ref
(
'refs/pull/1/head'
,
sha
)
repository
.
write_ref
(
'refs/pull/1/merge'
,
sha
)
subject
.
execute
end
it
'removes refs/pull/**/*'
do
expect
(
repository
.
rugged
.
references
.
map
(
&
:name
))
.
not_to
include
(
%r{
\A
refs/pull/}
)
end
end
described_class
::
RESERVED_REFS_NAMES
.
each
do
|
name
|
context
"with a ref in refs/
#{
name
}
/tmp"
do
before
do
repository
.
write_ref
(
"refs/
#{
name
}
/tmp"
,
sha
)
subject
.
execute
end
it
"does not remove refs/
#{
name
}
/tmp"
do
expect
(
repository
.
rugged
.
references
.
map
(
&
:name
))
.
to
include
(
"refs/
#{
name
}
/tmp"
)
end
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