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
iv
gitlab-ce
Commits
9f85b7bc
Commit
9f85b7bc
authored
Apr 26, 2016
by
Jacob Vosmaer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Initialize wikis on legacy projects during check
parent
f127edd0
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
51 additions
and
16 deletions
+51
-16
app/workers/repository_check/single_repository_worker.rb
app/workers/repository_check/single_repository_worker.rb
+23
-11
spec/workers/repository_check/single_repository_worker_spec.rb
...workers/repository_check/single_repository_worker_spec.rb
+28
-5
No files found.
app/workers/repository_check/single_repository_worker.rb
View file @
9f85b7bc
module
RepositoryCheck
module
RepositoryCheck
class
SingleRepositoryWorker
class
SingleRepositoryWorker
include
Sidekiq
::
Worker
include
Sidekiq
::
Worker
sidekiq_options
retry:
false
sidekiq_options
retry:
false
def
perform
(
project_id
)
def
perform
(
project_id
)
project
=
Project
.
find
(
project_id
)
project
=
Project
.
find
(
project_id
)
project
.
update_columns
(
project
.
update_columns
(
...
@@ -11,20 +11,32 @@ module RepositoryCheck
...
@@ -11,20 +11,32 @@ module RepositoryCheck
last_repository_check_at:
Time
.
now
,
last_repository_check_at:
Time
.
now
,
)
)
end
end
private
private
def
check
(
project
)
def
check
(
project
)
repositories
=
[
project
.
repository
]
if
!
git_fsck
(
project
.
repository
)
repositories
<<
project
.
wiki
.
repository
if
project
.
wiki_enabled?
false
# Use 'map do', not 'all? do', to prevent short-circuiting
elsif
project
.
wiki_enabled?
repositories
.
map
{
|
repository
|
git_fsck
(
repository
.
path_to_repo
)
}.
all?
# Historically some projects never had their wiki repos initialized;
# this happens on project creation now. Let's initialize an empty repo
# if it is not already there.
begin
project
.
create_wiki
rescue
Rugged
::
RepositoryError
end
git_fsck
(
project
.
wiki
.
repository
)
else
true
end
end
end
def
git_fsck
(
path
)
def
git_fsck
(
repository
)
path
=
repository
.
path_to_repo
cmd
=
%W(nice git --git-dir=
#{
path
}
fsck)
cmd
=
%W(nice git --git-dir=
#{
path
}
fsck)
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
output
,
status
=
Gitlab
::
Popen
.
popen
(
cmd
)
if
status
.
zero?
if
status
.
zero?
true
true
else
else
...
...
spec/workers/repository_check/single_repository_worker_spec.rb
View file @
9f85b7bc
...
@@ -12,7 +12,7 @@ describe RepositoryCheck::SingleRepositoryWorker do
...
@@ -12,7 +12,7 @@ describe RepositoryCheck::SingleRepositoryWorker do
subject
.
perform
(
project
.
id
)
subject
.
perform
(
project
.
id
)
expect
(
project
.
reload
.
last_repository_check_failed
).
to
eq
(
false
)
expect
(
project
.
reload
.
last_repository_check_failed
).
to
eq
(
false
)
destroy
_wiki
(
project
)
break
_wiki
(
project
)
subject
.
perform
(
project
.
id
)
subject
.
perform
(
project
.
id
)
expect
(
project
.
reload
.
last_repository_check_failed
).
to
eq
(
true
)
expect
(
project
.
reload
.
last_repository_check_failed
).
to
eq
(
true
)
...
@@ -20,15 +20,38 @@ describe RepositoryCheck::SingleRepositoryWorker do
...
@@ -20,15 +20,38 @@ describe RepositoryCheck::SingleRepositoryWorker do
it
'skips wikis when disabled'
do
it
'skips wikis when disabled'
do
project
=
create
(
:project_empty_repo
,
wiki_enabled:
false
)
project
=
create
(
:project_empty_repo
,
wiki_enabled:
false
)
# Make sure the test would fail if
it checked the wiki repo
# Make sure the test would fail if
the wiki repo was checked
destroy
_wiki
(
project
)
break
_wiki
(
project
)
subject
.
perform
(
project
.
id
)
subject
.
perform
(
project
.
id
)
expect
(
project
.
reload
.
last_repository_check_failed
).
to
eq
(
false
)
expect
(
project
.
reload
.
last_repository_check_failed
).
to
eq
(
false
)
end
end
def
destroy_wiki
(
project
)
it
'creates missing wikis'
do
FileUtils
.
rm_rf
(
project
.
wiki
.
repository
.
path_to_repo
)
project
=
create
(
:project_empty_repo
,
wiki_enabled:
true
)
FileUtils
.
rm_rf
(
wiki_path
(
project
))
subject
.
perform
(
project
.
id
)
expect
(
project
.
reload
.
last_repository_check_failed
).
to
eq
(
false
)
end
it
'does not create a wiki if the main repo does not exist at all'
do
project
=
create
(
:project_empty_repo
)
FileUtils
.
rm_rf
(
project
.
repository
.
path_to_repo
)
FileUtils
.
rm_rf
(
wiki_path
(
project
))
subject
.
perform
(
project
.
id
)
expect
(
File
.
exist?
(
wiki_path
(
project
))).
to
eq
(
false
)
end
def
break_wiki
(
project
)
FileUtils
.
rm_rf
(
wiki_path
(
project
)
+
'/objects'
)
end
def
wiki_path
(
project
)
project
.
wiki
.
repository
.
path_to_repo
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