BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
6515ec09
Unverified
Commit
6515ec09
authored
Aug 02, 2016
by
Dmitriy Zaporozhets
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Chnage the way how merge request diff is initialized and saved
Signed-off-by:
Dmitriy Zaporozhets
<
dmitriy.zaporozhets@gmail.com
>
parent
f8aeb8cd
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
37 additions
and
45 deletions
+37
-45
merge_request.rb
app/models/merge_request.rb
+6
-9
merge_request_diff.rb
app/models/merge_request_diff.rb
+24
-16
create_service.rb
app/services/merge_requests/create_service.rb
+0
-1
merge_requests.feature
features/project/merge_requests.feature
+1
-1
merge_requests.rb
features/steps/project/merge_requests.rb
+3
-3
merge_requests.rb
spec/factories/merge_requests.rb
+0
-6
merge_request_diff_spec.rb
spec/models/merge_request_diff_spec.rb
+3
-9
No files found.
app/models/merge_request.rb
View file @
6515ec09
...
...
@@ -11,11 +11,13 @@ class MergeRequest < ActiveRecord::Base
belongs_to
:merge_user
,
class_name:
"User"
has_many
:merge_request_diffs
,
dependent: :destroy
has_one
:merge_request_diff
has_many
:events
,
as: :target
,
dependent: :destroy
serialize
:merge_params
,
Hash
after_update
:update_merge_request_diff
after_create
:ensure_merge_request_diff
,
unless: :importing?
after_update
:reload_diff_if_branch_changed
delegate
:commits
,
:real_size
,
to: :merge_request_diff
,
prefix:
nil
...
...
@@ -94,7 +96,6 @@ class MergeRequest < ActiveRecord::Base
validates
:merge_user
,
presence:
true
,
if: :merge_when_build_succeeds?
validate
:validate_branches
,
unless:
[
:allow_broken
,
:importing?
]
validate
:validate_fork
validates_associated
:merge_request_diff
,
on: :create
,
unless:
[
:allow_broken
,
:importing?
]
scope
:by_branch
,
->
(
branch_name
)
{
where
(
"(source_branch LIKE :branch) OR (target_branch LIKE :branch)"
,
branch:
branch_name
)
}
scope
:cared
,
->
(
user
)
{
where
(
'assignee_id = :user OR author_id = :user'
,
user:
user
.
id
)
}
...
...
@@ -282,11 +283,11 @@ class MergeRequest < ActiveRecord::Base
end
end
def
creat
e_merge_request_diff
merge_request_diff
s
.
create
def
ensur
e_merge_request_diff
merge_request_diff
||
create_merge_request_diff
end
def
update_merge_request_diff
def
reload_diff_if_branch_changed
if
source_branch_changed?
||
target_branch_changed?
reload_diff
end
...
...
@@ -689,8 +690,4 @@ class MergeRequest < ActiveRecord::Base
def
keep_around_commit
project
.
repository
.
keep_around
(
self
.
merge_commit_sha
)
end
def
merge_request_diff
merge_request_diffs
.
first
end
end
app/models/merge_request_diff.rb
View file @
6515ec09
...
...
@@ -22,28 +22,28 @@ class MergeRequestDiff < ActiveRecord::Base
serialize
:st_commits
serialize
:st_diffs
validates
:start_commit_sha
,
presence:
true
,
unless: :importing?
validates
:head_commit_sha
,
presence:
true
,
unless: :importing?
# For compatibility with old MergeRequestDiff which
# does not store those variables in database
after_initialize
:ensure_commits_sha
,
if: :persisted?
after_initialize
:initialize_commits_sha
,
unless: :importing?
# All diff information is collected from repository after object is created.
# It allows you to override variables like head_commit_sha before getting diff.
after_create
:save_git_content
,
unless: :importing?
after_save
:keep_around_commits
,
unless: :importing?
# Those variables are used for collecting commits and diff from git repository.
# After object is created those sha are stored in the database.
# However some old MergeRequestDiff records don't
# have those variables in the database so we try to initialize it
def
initialize_commits_sha
self
.
start_commit_sha
||=
merge_request
.
target_branch_sha
self
.
head_commit_sha
||=
persisted?
?
last_commit
.
sha
:
merge_request
.
source_branch_sha
self
.
base_commit_sha
||=
find_base_sha
end
# Collect information about commits and diff from repository
# and save it to the database as serialized data
def
save_git_content
ensure_commits_sha
save_commits
reload_commits
save_diffs
keep_around_commits
end
def
ensure_commits_sha
self
.
start_commit_sha
||=
merge_request
.
target_branch_sha
self
.
head_commit_sha
||=
last_commit
.
try
(
:sha
)
||
merge_request
.
source_branch_sha
self
.
base_commit_sha
||=
find_base_sha
end
def
size
...
...
@@ -52,7 +52,8 @@ class MergeRequestDiff < ActiveRecord::Base
def
diffs
(
options
=
{})
if
options
[
:ignore_whitespace_change
]
@diffs_no_whitespace
||=
begin
@diffs_no_whitespace
||=
begin
compare
=
Gitlab
::
Git
::
Compare
.
new
(
repository
.
raw_repository
,
start_commit_sha
,
...
...
@@ -70,6 +71,11 @@ class MergeRequestDiff < ActiveRecord::Base
@commits
||=
load_commits
(
st_commits
||
[])
end
def
reload_commits
@commits
=
nil
commits
end
def
last_commit
commits
.
first
end
...
...
@@ -192,7 +198,6 @@ class MergeRequestDiff < ActiveRecord::Base
new_attributes
[
:st_diffs
]
=
new_diffs
update_columns_serialized
(
new_attributes
)
keep_around_commits
end
def
project
...
...
@@ -207,6 +212,9 @@ class MergeRequestDiff < ActiveRecord::Base
return
unless
head_commit_sha
&&
start_commit_sha
project
.
merge_base_commit
(
head_commit_sha
,
start_commit_sha
).
try
(
:sha
)
rescue
Rugged
::
OdbError
# In case head or start commit does not exist in the repository any more
nil
end
def
utf8_st_diffs
...
...
app/services/merge_requests/create_service.rb
View file @
6515ec09
...
...
@@ -16,7 +16,6 @@ module MergeRequests
merge_request
.
target_project
||=
source_project
merge_request
.
author
=
current_user
merge_request
.
merge_params
[
'force_remove_source_branch'
]
=
force_remove_source_branch
merge_request
.
merge_request_diffs
.
build
if
merge_request
.
save
merge_request
.
update_attributes
(
label_ids:
label_params
)
...
...
features/project/merge_requests.feature
View file @
6515ec09
...
...
@@ -24,7 +24,7 @@ Feature: Project Merge Requests
Scenario
:
I
should see target branch when it is different from default
Given
project
"Shop"
have
"Bug NS-06"
open merge request
When
I visit project
"Shop"
merge requests page
Then
I should see
"
other_branch
"
branch
Then
I should see
"
feature_conflict
"
branch
Scenario
:
I
should not see the numbers of diverged commits if the branch is rebased on the target
Given
project
"Shop"
have
"Bug NS-07"
open merge request with rebased branch
...
...
features/steps/project/merge_requests.rb
View file @
6515ec09
...
...
@@ -56,8 +56,8 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
expect
(
find
(
'.merge-request-info'
)).
not_to
have_content
"master"
end
step
'I should see "
other_branch
" branch'
do
expect
(
page
).
to
have_content
"
other_branch
"
step
'I should see "
feature_conflict
" branch'
do
expect
(
page
).
to
have_content
"
feature_conflict
"
end
step
'I should see "Bug NS-04" in merge requests'
do
...
...
@@ -122,7 +122,7 @@ class Spinach::Features::ProjectMergeRequests < Spinach::FeatureSteps
source_project:
project
,
target_project:
project
,
source_branch:
'fix'
,
target_branch:
'
other_branch
'
,
target_branch:
'
feature_conflict
'
,
author:
project
.
users
.
first
,
description:
"# Description header"
)
...
...
spec/factories/merge_requests.rb
View file @
6515ec09
...
...
@@ -68,11 +68,5 @@ FactoryGirl.define do
factory
:closed_merge_request
,
traits:
[
:closed
]
factory
:reopened_merge_request
,
traits:
[
:reopened
]
factory
:merge_request_with_diffs
,
traits:
[
:with_diffs
]
after
:create
do
|
merge_request
|
unless
merge_request
.
merge_request_diff
merge_request
.
create_merge_request_diff
end
end
end
end
spec/models/merge_request_diff_spec.rb
View file @
6515ec09
require
'spec_helper'
describe
MergeRequestDiff
,
models:
true
do
describe
'initialize new object'
do
subject
{
build
(
:merge_request
).
merge_request_diffs
.
build
}
it
{
expect
(
subject
).
to
be_valid
}
it
{
expect
(
subject
.
head_commit_sha
).
to
eq
(
'5937ac0a7beb003549fc5fd26fc247adbce4a52e'
)
}
it
{
expect
(
subject
.
base_commit_sha
).
to
eq
(
'ae73cb07c9eeaf35924a10f713b364d32b2dd34f'
)
}
it
{
expect
(
subject
.
start_commit_sha
).
to
eq
(
'0b4bc9a49b562e85de7cc9e834518ea6828729b9'
)
}
end
describe
'create new record'
do
subject
{
create
(
:merge_request
).
merge_request_diff
}
...
...
@@ -17,6 +8,9 @@ describe MergeRequestDiff, models: true do
it
{
expect
(
subject
).
to
be_persisted
}
it
{
expect
(
subject
.
commits
.
count
).
to
eq
(
5
)
}
it
{
expect
(
subject
.
diffs
.
count
).
to
eq
(
8
)
}
it
{
expect
(
subject
.
head_commit_sha
).
to
eq
(
'5937ac0a7beb003549fc5fd26fc247adbce4a52e'
)
}
it
{
expect
(
subject
.
base_commit_sha
).
to
eq
(
'ae73cb07c9eeaf35924a10f713b364d32b2dd34f'
)
}
it
{
expect
(
subject
.
start_commit_sha
).
to
eq
(
'0b4bc9a49b562e85de7cc9e834518ea6828729b9'
)
}
end
describe
'#diffs'
do
...
...
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