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
051fbfb8
Commit
051fbfb8
authored
Jun 22, 2017
by
Nick Thomas
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor squash and merge parts of MergeRequest into an EE module
parent
fb7c7515
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
116 additions
and
106 deletions
+116
-106
app/models/ee/merge_request.rb
app/models/ee/merge_request.rb
+47
-0
app/models/merge_request.rb
app/models/merge_request.rb
+2
-44
spec/models/ee/merge_request_spec.rb
spec/models/ee/merge_request_spec.rb
+67
-0
spec/models/merge_request_spec.rb
spec/models/merge_request_spec.rb
+0
-62
No files found.
app/models/ee/merge_request.rb
0 → 100644
View file @
051fbfb8
module
EE
module
MergeRequest
def
ff_merge_possible?
project
.
repository
.
is_ancestor?
(
target_branch_sha
,
diff_head_sha
)
end
def
should_be_rebased?
self
.
project
.
ff_merge_must_be_possible?
&&
!
ff_merge_possible?
end
def
rebase_dir_path
File
.
join
(
::
Gitlab
.
config
.
shared
.
path
,
'tmp/rebase'
,
source_project
.
id
.
to_s
,
id
.
to_s
).
to_s
end
def
squash_dir_path
File
.
join
(
::
Gitlab
.
config
.
shared
.
path
,
'tmp/squash'
,
source_project
.
id
.
to_s
,
id
.
to_s
).
to_s
end
def
rebase_in_progress?
# The source project can be deleted
return
false
unless
source_project
File
.
exist?
(
rebase_dir_path
)
&&
!
clean_stuck_rebase
end
def
squash_in_progress?
# The source project can be deleted
return
false
unless
source_project
File
.
exist?
(
squash_dir_path
)
&&
!
clean_stuck_squash
end
def
clean_stuck_rebase
if
File
.
mtime
(
rebase_dir_path
)
<
15
.
minutes
.
ago
FileUtils
.
rm_rf
(
rebase_dir_path
)
true
end
end
def
clean_stuck_squash
if
File
.
mtime
(
squash_dir_path
)
<
15
.
minutes
.
ago
FileUtils
.
rm_rf
(
squash_dir_path
)
true
end
end
end
end
app/models/merge_request.rb
View file @
051fbfb8
...
@@ -10,6 +10,8 @@ class MergeRequest < ActiveRecord::Base
...
@@ -10,6 +10,8 @@ class MergeRequest < ActiveRecord::Base
ignore_column
:position
ignore_column
:position
include
::
EE
::
MergeRequest
belongs_to
:target_project
,
class_name:
"Project"
belongs_to
:target_project
,
class_name:
"Project"
belongs_to
:source_project
,
class_name:
"Project"
belongs_to
:source_project
,
class_name:
"Project"
belongs_to
:merge_user
,
class_name:
"User"
belongs_to
:merge_user
,
class_name:
"User"
...
@@ -820,50 +822,6 @@ class MergeRequest < ActiveRecord::Base
...
@@ -820,50 +822,6 @@ class MergeRequest < ActiveRecord::Base
end
end
end
end
def
ff_merge_possible?
project
.
repository
.
is_ancestor?
(
target_branch_sha
,
diff_head_sha
)
end
def
should_be_rebased?
self
.
project
.
ff_merge_must_be_possible?
&&
!
ff_merge_possible?
end
def
rebase_dir_path
File
.
join
(
Gitlab
.
config
.
shared
.
path
,
'tmp/rebase'
,
source_project
.
id
.
to_s
,
id
.
to_s
).
to_s
end
def
squash_dir_path
File
.
join
(
Gitlab
.
config
.
shared
.
path
,
'tmp/squash'
,
source_project
.
id
.
to_s
,
id
.
to_s
).
to_s
end
def
rebase_in_progress?
# The source project can be deleted
return
false
unless
source_project
File
.
exist?
(
rebase_dir_path
)
&&
!
clean_stuck_rebase
end
def
clean_stuck_rebase
if
File
.
mtime
(
rebase_dir_path
)
<
15
.
minutes
.
ago
FileUtils
.
rm_rf
(
rebase_dir_path
)
true
end
end
def
squash_in_progress?
# The source project can be deleted
return
false
unless
source_project
File
.
exist?
(
squash_dir_path
)
&&
!
clean_stuck_squash
end
def
clean_stuck_squash
if
File
.
mtime
(
squash_dir_path
)
<
15
.
minutes
.
ago
FileUtils
.
rm_rf
(
squash_dir_path
)
true
end
end
def
diverged_commits_count
def
diverged_commits_count
cache
=
Rails
.
cache
.
read
(
:"merge_request_
#{
id
}
_diverged_commits"
)
cache
=
Rails
.
cache
.
read
(
:"merge_request_
#{
id
}
_diverged_commits"
)
...
...
spec/models/ee/merge_request_spec.rb
0 → 100644
View file @
051fbfb8
require
'spec_helper'
describe
MergeRequest
,
models:
true
do
subject
{
create
(
:merge_request
)
}
describe
'#rebase_in_progress?'
do
it
'returns true when there is a current rebase directory'
do
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:mtime
).
and_return
(
Time
.
now
)
expect
(
subject
.
rebase_in_progress?
).
to
be_truthy
end
it
'returns false when there is no rebase directory'
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
subject
.
rebase_dir_path
).
and_return
(
false
)
expect
(
subject
.
rebase_in_progress?
).
to
be_falsey
end
it
'returns false when the rebase directory has expired'
do
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:mtime
).
and_return
(
20
.
minutes
.
ago
)
expect
(
subject
.
rebase_in_progress?
).
to
be_falsey
end
it
'returns false when the source project has been removed'
do
allow
(
subject
).
to
receive
(
:source_project
).
and_return
(
nil
)
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:mtime
).
and_return
(
Time
.
now
)
expect
(
File
).
not_to
have_received
(
:exist?
)
expect
(
subject
.
rebase_in_progress?
).
to
be_falsey
end
end
describe
'#squash_in_progress?'
do
it
'returns true when there is a current squash directory'
do
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:mtime
).
and_return
(
Time
.
now
)
expect
(
subject
.
squash_in_progress?
).
to
be_truthy
end
it
'returns false when there is no squash directory'
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
subject
.
squash_dir_path
).
and_return
(
false
)
expect
(
subject
.
squash_in_progress?
).
to
be_falsey
end
it
'returns false when the squash directory has expired'
do
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:mtime
).
and_return
(
20
.
minutes
.
ago
)
expect
(
subject
.
squash_in_progress?
).
to
be_falsey
end
it
'returns false when the source project has been removed'
do
allow
(
subject
).
to
receive
(
:source_project
).
and_return
(
nil
)
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:mtime
).
and_return
(
Time
.
now
)
expect
(
File
).
not_to
have_received
(
:exist?
)
expect
(
subject
.
squash_in_progress?
).
to
be_falsey
end
end
end
spec/models/merge_request_spec.rb
View file @
051fbfb8
...
@@ -913,68 +913,6 @@ describe MergeRequest, models: true do
...
@@ -913,68 +913,6 @@ describe MergeRequest, models: true do
subject
{
create
:merge_request
,
:simple
}
subject
{
create
:merge_request
,
:simple
}
end
end
describe
'#rebase_in_progress?'
do
it
'returns true when there is a current rebase directory'
do
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:mtime
).
and_return
(
Time
.
now
)
expect
(
subject
.
rebase_in_progress?
).
to
be_truthy
end
it
'returns false when there is no rebase directory'
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
subject
.
rebase_dir_path
).
and_return
(
false
)
expect
(
subject
.
rebase_in_progress?
).
to
be_falsey
end
it
'returns false when the rebase directory has expired'
do
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:mtime
).
and_return
(
20
.
minutes
.
ago
)
expect
(
subject
.
rebase_in_progress?
).
to
be_falsey
end
it
'returns false when the source project has been removed'
do
allow
(
subject
).
to
receive
(
:source_project
).
and_return
(
nil
)
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:mtime
).
and_return
(
Time
.
now
)
expect
(
File
).
not_to
have_received
(
:exist?
)
expect
(
subject
.
rebase_in_progress?
).
to
be_falsey
end
end
describe
'#squash_in_progress?'
do
it
'returns true when there is a current squash directory'
do
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:mtime
).
and_return
(
Time
.
now
)
expect
(
subject
.
squash_in_progress?
).
to
be_truthy
end
it
'returns false when there is no squash directory'
do
allow
(
File
).
to
receive
(
:exist?
).
with
(
subject
.
squash_dir_path
).
and_return
(
false
)
expect
(
subject
.
squash_in_progress?
).
to
be_falsey
end
it
'returns false when the squash directory has expired'
do
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:mtime
).
and_return
(
20
.
minutes
.
ago
)
expect
(
subject
.
squash_in_progress?
).
to
be_falsey
end
it
'returns false when the source project has been removed'
do
allow
(
subject
).
to
receive
(
:source_project
).
and_return
(
nil
)
allow
(
File
).
to
receive
(
:exist?
).
and_return
(
true
)
allow
(
File
).
to
receive
(
:mtime
).
and_return
(
Time
.
now
)
expect
(
File
).
not_to
have_received
(
:exist?
)
expect
(
subject
.
squash_in_progress?
).
to
be_falsey
end
end
describe
'#commits_sha'
do
describe
'#commits_sha'
do
before
do
before
do
allow
(
subject
.
merge_request_diff
).
to
receive
(
:commits_sha
)
allow
(
subject
.
merge_request_diff
).
to
receive
(
:commits_sha
)
...
...
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