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
3ff3b414
Commit
3ff3b414
authored
Jul 05, 2021
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Track the previous default branch for a project when it changes
parent
189c2075
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
21 additions
and
3 deletions
+21
-3
app/models/project.rb
app/models/project.rb
+1
-0
app/services/projects/update_service.rb
app/services/projects/update_service.rb
+2
-0
spec/services/projects/update_service_spec.rb
spec/services/projects/update_service_spec.rb
+18
-3
No files found.
app/models/project.rb
View file @
3ff3b414
...
@@ -416,6 +416,7 @@ class Project < ApplicationRecord
...
@@ -416,6 +416,7 @@ class Project < ApplicationRecord
prefix: :import
,
to: :import_state
,
allow_nil:
true
prefix: :import
,
to: :import_state
,
allow_nil:
true
delegate
:squash_always?
,
:squash_never?
,
:squash_enabled_by_default?
,
:squash_readonly?
,
to: :project_setting
delegate
:squash_always?
,
:squash_never?
,
:squash_enabled_by_default?
,
:squash_readonly?
,
to: :project_setting
delegate
:squash_option
,
to: :project_setting
delegate
:squash_option
,
to: :project_setting
delegate
:previous_default_branch
,
:previous_default_branch
=
,
to: :project_setting
delegate
:no_import?
,
to: :import_state
,
allow_nil:
true
delegate
:no_import?
,
to: :import_state
,
allow_nil:
true
delegate
:name
,
to: :owner
,
allow_nil:
true
,
prefix:
true
delegate
:name
,
to: :owner
,
allow_nil:
true
,
prefix:
true
delegate
:members
,
to: :team
,
prefix:
true
delegate
:members
,
to: :team
,
prefix:
true
...
...
app/services/projects/update_service.rb
View file @
3ff3b414
...
@@ -66,6 +66,8 @@ module Projects
...
@@ -66,6 +66,8 @@ module Projects
previous_default_branch
=
project
.
default_branch
previous_default_branch
=
project
.
default_branch
if
project
.
change_head
(
params
[
:default_branch
])
if
project
.
change_head
(
params
[
:default_branch
])
params
[
:previous_default_branch
]
=
previous_default_branch
after_default_branch_change
(
previous_default_branch
)
after_default_branch_change
(
previous_default_branch
)
else
else
raise
ValidationError
,
s_
(
"UpdateProject|Could not set the default branch"
)
raise
ValidationError
,
s_
(
"UpdateProject|Could not set the default branch"
)
...
...
spec/services/projects/update_service_spec.rb
View file @
3ff3b414
...
@@ -200,17 +200,32 @@ RSpec.describe Projects::UpdateService do
...
@@ -200,17 +200,32 @@ RSpec.describe Projects::UpdateService do
context
'when updating a default branch'
do
context
'when updating a default branch'
do
let
(
:project
)
{
create
(
:project
,
:repository
)
}
let
(
:project
)
{
create
(
:project
,
:repository
)
}
it
'changes a default branch'
do
it
'changes default branch, tracking the previous branch'
do
previous_default_branch
=
project
.
default_branch
update_project
(
project
,
admin
,
default_branch:
'feature'
)
update_project
(
project
,
admin
,
default_branch:
'feature'
)
expect
(
Project
.
find
(
project
.
id
).
default_branch
).
to
eq
'feature'
project
.
reload
expect
(
project
.
default_branch
).
to
eq
(
'feature'
)
expect
(
project
.
previous_default_branch
).
to
eq
(
previous_default_branch
)
update_project
(
project
,
admin
,
default_branch:
previous_default_branch
)
project
.
reload
expect
(
project
.
default_branch
).
to
eq
(
previous_default_branch
)
expect
(
project
.
previous_default_branch
).
to
eq
(
'feature'
)
end
end
it
'does not change a default branch'
do
it
'does not change a default branch'
do
# The branch 'unexisted-branch' does not exist.
# The branch 'unexisted-branch' does not exist.
update_project
(
project
,
admin
,
default_branch:
'unexisted-branch'
)
update_project
(
project
,
admin
,
default_branch:
'unexisted-branch'
)
expect
(
Project
.
find
(
project
.
id
).
default_branch
).
to
eq
'master'
project
.
reload
expect
(
project
.
default_branch
).
to
eq
'master'
expect
(
project
.
previous_default_branch
).
to
be_nil
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