MR: Handle broken diff ex. in case its too huge
This commit is contained in:
parent
d40b9ce26d
commit
0a6b64e6a9
3 changed files with 38 additions and 19 deletions
|
@ -3,6 +3,8 @@ require File.join(Rails.root, "app/models/commit")
|
||||||
class MergeRequest < ActiveRecord::Base
|
class MergeRequest < ActiveRecord::Base
|
||||||
include Upvote
|
include Upvote
|
||||||
|
|
||||||
|
BROKEN_DIFF = "--broken-diff"
|
||||||
|
|
||||||
UNCHECKED = 1
|
UNCHECKED = 1
|
||||||
CAN_BE_MERGED = 2
|
CAN_BE_MERGED = 2
|
||||||
CANNOT_BE_MERGED = 3
|
CANNOT_BE_MERGED = 3
|
||||||
|
@ -108,14 +110,25 @@ class MergeRequest < ActiveRecord::Base
|
||||||
def reloaded_diffs
|
def reloaded_diffs
|
||||||
if open? && unmerged_diffs.any?
|
if open? && unmerged_diffs.any?
|
||||||
self.st_diffs = unmerged_diffs
|
self.st_diffs = unmerged_diffs
|
||||||
save
|
self.save
|
||||||
end
|
end
|
||||||
diffs
|
|
||||||
|
rescue Grit::Git::GitTimeout
|
||||||
|
self.st_diffs = [BROKEN_DIFF]
|
||||||
|
self.save
|
||||||
|
end
|
||||||
|
|
||||||
|
def broken_diffs?
|
||||||
|
diffs == [BROKEN_DIFF]
|
||||||
|
end
|
||||||
|
|
||||||
|
def valid_diffs?
|
||||||
|
!broken_diffs?
|
||||||
end
|
end
|
||||||
|
|
||||||
def unmerged_diffs
|
def unmerged_diffs
|
||||||
commits = project.repo.commits_between(target_branch, source_branch).map {|c| Commit.new(c)}
|
commits = project.repo.commits_between(target_branch, source_branch).map {|c| Commit.new(c)}
|
||||||
diffs = project.repo.diff(commits.first.prev_commit.id, commits.last.id) rescue []
|
diffs = project.repo.diff(commits.first.prev_commit.id, commits.last.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
def last_commit
|
def last_commit
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
Issues
|
Issues
|
||||||
%span.count= @project.issues.opened.count
|
%span.count= @project.issues.opened.count
|
||||||
|
|
||||||
|
- if @project.repo_exists?
|
||||||
- if @project.merge_requests_enabled
|
- if @project.merge_requests_enabled
|
||||||
%li{:class => tab_class(:merge_requests)}
|
%li{:class => tab_class(:merge_requests)}
|
||||||
= link_to project_merge_requests_path(@project) do
|
= link_to project_merge_requests_path(@project) do
|
||||||
|
|
|
@ -1,3 +1,8 @@
|
||||||
= render "commits/diffs", :diffs => @diffs
|
- if @merge_request.valid_diffs?
|
||||||
- if @diffs.empty?
|
= render "commits/diffs", :diffs => @diffs
|
||||||
%p.cgray Nothing to merge
|
- elsif @merge_request.broken_diffs?
|
||||||
|
%h4.nothing_here_message
|
||||||
|
Can't load diff.
|
||||||
|
You can #{link_to "download MR patch", raw_project_merge_request_path(@project, @merge_request), :class => "vlink"} instead.
|
||||||
|
- else
|
||||||
|
%h4.nothing_here_message Nothing to merge
|
||||||
|
|
Loading…
Add table
Reference in a new issue