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
74227c9e
Commit
74227c9e
authored
Mar 09, 2022
by
John Cai
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Wiki: do not set default branch
parent
dc860cb9
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
6 additions
and
39 deletions
+6
-39
app/models/wiki.rb
app/models/wiki.rb
+1
-12
ee/spec/models/group_wiki_spec.rb
ee/spec/models/group_wiki_spec.rb
+3
-2
spec/support/shared_examples/models/wiki_shared_examples.rb
spec/support/shared_examples/models/wiki_shared_examples.rb
+2
-25
No files found.
app/models/wiki.rb
View file @
74227c9e
...
...
@@ -87,8 +87,7 @@ class Wiki
end
def
create_wiki_repository
repository
.
create_if_not_exists
change_head_to_default_branch
repository
.
create_if_not_exists
(
default_branch
)
raise
CouldNotCreateWikiError
unless
repository_exists?
rescue
StandardError
=>
err
...
...
@@ -322,16 +321,6 @@ class Wiki
def
default_message
(
action
,
title
)
"
#{
user
.
username
}
#{
action
}
page:
#{
title
}
"
end
def
change_head_to_default_branch
# If the wiki has commits in the 'HEAD' branch means that the current
# HEAD is pointing to the right branch. If not, it could mean that either
# the repo has just been created or that 'HEAD' is pointing
# to the wrong branch and we need to rewrite it
return
if
repository
.
raw_repository
.
commit_count
(
'HEAD'
)
!=
0
repository
.
raw_repository
.
write_ref
(
'HEAD'
,
"refs/heads/
#{
default_branch
}
"
)
end
end
Wiki
.
prepend_mod_with
(
'Wiki'
)
ee/spec/models/group_wiki_spec.rb
View file @
74227c9e
...
...
@@ -12,14 +12,15 @@ RSpec.describe GroupWiki do
end
describe
'#create_wiki_repository'
do
let
(
:shard
)
{
'foo'
}
it
'tracks the repository storage in the database'
do
shard
=
'foo'
# Use a custom storage shard value, to make sure we're not falling back to the default.
allow
(
subject
).
to
receive
(
:repository_storage
).
and_return
(
shard
)
allow
(
subject
).
to
receive
(
:default_branch
).
and_return
(
'bar'
)
# Don't actually create the repository, because the storage shard doesn't exist.
expect
(
subject
.
repository
).
to
receive
(
:create_if_not_exists
)
expect
(
subject
).
to
receive
(
:change_head_to_default_branch
)
allow
(
subject
).
to
receive
(
:repository_exists?
).
and_return
(
true
)
expect
(
subject
).
to
receive
(
:track_wiki_repository
).
with
(
shard
)
...
...
spec/support/shared_examples/models/wiki_shared_examples.rb
View file @
74227c9e
...
...
@@ -599,36 +599,13 @@ RSpec.shared_examples 'wiki model' do
context
'when repository is empty'
do
let
(
:wiki_container
)
{
wiki_container_without_repo
}
it
'changes the HEAD reference to the default branch'
do
wiki
.
repository
.
create_if_not_exists
wiki
.
repository
.
raw_repository
.
write_ref
(
'HEAD'
,
'refs/heads/bar'
)
it
'creates the repository with the default branch'
do
wiki
.
repository
.
create_if_not_exists
(
default_branch
)
subject
expect
(
File
.
read
(
head_path
).
squish
).
to
eq
"ref: refs/heads/
#{
default_branch
}
"
end
end
context
'when repository is not empty'
do
before
do
wiki
.
create_page
(
'index'
,
'test content'
)
end
it
'does nothing when HEAD points to the right branch'
do
expect
(
wiki
.
repository
.
raw_repository
).
not_to
receive
(
:write_ref
)
subject
end
context
'when HEAD points to the wrong branch'
do
it
'rewrites HEAD with the right branch'
do
wiki
.
repository
.
raw_repository
.
write_ref
(
'HEAD'
,
'refs/heads/bar'
)
subject
expect
(
File
.
read
(
head_path
).
squish
).
to
eq
"ref: refs/heads/
#{
default_branch
}
"
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