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
dd916a52
Commit
dd916a52
authored
Jun 02, 2020
by
Francisco Javier López
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix snippet import from export files without snippet dir
parent
942c30de
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
67 additions
and
16 deletions
+67
-16
changelogs/unreleased/fj-fix-import-from-different-types-exports.yml
...unreleased/fj-fix-import-from-different-types-exports.yml
+5
-0
lib/gitlab/import_export/snippets_repo_restorer.rb
lib/gitlab/import_export/snippets_repo_restorer.rb
+0
-2
spec/lib/gitlab/import_export/snippets_repo_restorer_spec.rb
spec/lib/gitlab/import_export/snippets_repo_restorer_spec.rb
+62
-14
No files found.
changelogs/unreleased/fj-fix-import-from-different-types-exports.yml
0 → 100644
View file @
dd916a52
---
title
:
Fix snippet repository import fail with older export files
merge_request
:
33584
author
:
type
:
fixed
lib/gitlab/import_export/snippets_repo_restorer.rb
View file @
dd916a52
...
...
@@ -10,8 +10,6 @@ module Gitlab
end
def
restore
return
true
unless
Dir
.
exist?
(
snippets_repo_bundle_path
)
@project
.
snippets
.
find_each
.
all?
do
|
snippet
|
Gitlab
::
ImportExport
::
SnippetRepoRestorer
.
new
(
snippet:
snippet
,
user:
@user
,
...
...
spec/lib/gitlab/import_export/snippets_repo_restorer_spec.rb
View file @
dd916a52
...
...
@@ -8,42 +8,90 @@ describe Gitlab::ImportExport::SnippetsRepoRestorer do
describe
'bundle a snippet Git repo'
do
let_it_be
(
:user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
namespace:
user
.
namespace
)
}
let_it_be
(
:snippet_with_repo
)
{
create
(
:project_snippet
,
:repository
,
project:
project
,
author:
user
)
}
let_it_be
(
:snippet_without_repo
)
{
create
(
:project_snippet
,
project:
project
,
author:
user
)
}
let!
(
:snippet1
)
{
create
(
:project_snippet
,
project:
project
,
author:
user
)
}
let!
(
:snippet2
)
{
create
(
:project_snippet
,
project:
project
,
author:
user
)
}
let
(
:shared
)
{
project
.
import_export_shared
}
let
(
:exporter
)
{
Gitlab
::
ImportExport
::
SnippetsRepoSaver
.
new
(
current_user:
user
,
project:
project
,
shared:
shared
)
}
let
(
:bundle_dir
)
{
::
Gitlab
::
ImportExport
.
snippets_repo_bundle_path
(
shared
.
export_path
)
}
let
(
:service
)
{
instance_double
(
Gitlab
::
ImportExport
::
SnippetRepoRestorer
)
}
let
(
:restorer
)
do
described_class
.
new
(
user:
user
,
shared:
shared
,
project:
project
)
end
let
(
:service
)
{
instance_double
(
Gitlab
::
ImportExport
::
SnippetRepoRestorer
)
}
after
do
FileUtils
.
rm_rf
(
shared
.
export_path
)
end
shared_examples
'imports snippet repositories'
do
before
do
snippet1
.
snippet_repository
&
.
delete
snippet1
.
repository
.
remove
snippet2
.
snippet_repository
&
.
delete
snippet2
.
repository
.
remove
end
specify
do
expect
(
snippet1
.
repository_exists?
).
to
be
false
expect
(
snippet2
.
repository_exists?
).
to
be
false
expect
(
Gitlab
::
ImportExport
::
SnippetRepoRestorer
).
to
receive
(
:new
).
with
(
hash_including
(
snippet:
snippet1
,
path_to_bundle:
bundle_path
(
snippet1
))).
and_call_original
expect
(
Gitlab
::
ImportExport
::
SnippetRepoRestorer
).
to
receive
(
:new
).
with
(
hash_including
(
snippet:
snippet2
,
path_to_bundle:
bundle_path
(
snippet2
))).
and_call_original
expect
(
restorer
.
restore
).
to
be_truthy
snippet1
.
repository
.
expire_exists_cache
snippet2
.
repository
.
expire_exists_cache
expect
(
snippet1
.
blobs
).
not_to
be_empty
expect
(
snippet2
.
blobs
).
not_to
be_empty
end
end
context
'when export has no snippet repository bundle'
do
before
do
expect
(
Dir
.
exist?
(
bundle_dir
)).
to
be
false
end
it_behaves_like
'imports snippet repositories'
end
context
'when export has snippet repository bundles and snippets without them'
do
let!
(
:snippet1
)
{
create
(
:project_snippet
,
:repository
,
project:
project
,
author:
user
)
}
let!
(
:snippet2
)
{
create
(
:project_snippet
,
project:
project
,
author:
user
)
}
before
do
exporter
.
save
expect
(
File
.
exist?
(
bundle_path
(
snippet1
))).
to
be
true
expect
(
File
.
exist?
(
bundle_path
(
snippet2
))).
to
be
false
end
after
do
FileUtils
.
rm_rf
(
shared
.
export_path
)
it_behaves_like
'imports snippet repositories'
end
it
'calls SnippetRepoRestorer per each snippet with the bundle path'
do
allow
(
service
).
to
receive
(
:restore
).
and_return
(
true
)
context
'when export has only snippet bundles'
do
let!
(
:snippet1
)
{
create
(
:project_snippet
,
:repository
,
project:
project
,
author:
user
)
}
let!
(
:snippet2
)
{
create
(
:project_snippet
,
:repository
,
project:
project
,
author:
user
)
}
expect
(
Gitlab
::
ImportExport
::
SnippetRepoRestorer
).
to
receive
(
:new
).
with
(
hash_including
(
snippet:
snippet_with_repo
,
path_to_bundle:
bundle_path
(
snippet_with_repo
))).
and_return
(
service
)
expect
(
Gitlab
::
ImportExport
::
SnippetRepoRestorer
).
to
receive
(
:new
).
with
(
hash_including
(
snippet:
snippet_without_repo
,
path_to_bundle:
bundle_path
(
snippet_without_repo
))).
and_return
(
service
)
before
do
exporter
.
save
expect
(
restorer
.
restore
).
to
be_truthy
expect
(
File
.
exist?
(
bundle_path
(
snippet1
))).
to
be
true
expect
(
File
.
exist?
(
bundle_path
(
snippet2
))).
to
be
true
end
it_behaves_like
'imports snippet repositories'
end
context
'when one snippet cannot be saved'
do
it
'returns false and do not process other snippets'
do
allow
(
Gitlab
::
ImportExport
::
SnippetRepoRestorer
).
to
receive
(
:new
).
with
(
hash_including
(
snippet:
snippet
_with_repo
)).
and_return
(
service
)
allow
(
Gitlab
::
ImportExport
::
SnippetRepoRestorer
).
to
receive
(
:new
).
with
(
hash_including
(
snippet:
snippet
1
)).
and_return
(
service
)
allow
(
service
).
to
receive
(
:restore
).
and_return
(
false
)
expect
(
Gitlab
::
ImportExport
::
SnippetRepoRestorer
).
not_to
receive
(
:new
).
with
(
hash_including
(
snippet:
snippet
_without_repo
))
expect
(
Gitlab
::
ImportExport
::
SnippetRepoRestorer
).
not_to
receive
(
:new
).
with
(
hash_including
(
snippet:
snippet
2
))
expect
(
restorer
.
restore
).
to
be_falsey
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