[refs #878] fix some bugs when no master branch
This commit is contained in:
parent
6473b73859
commit
8860238da4
|
@ -10,8 +10,7 @@ class Projects::Git::BaseController < Projects::BaseController
|
|||
protected
|
||||
|
||||
def set_treeish_and_path
|
||||
@treeish = params[:treeish].presence || @project.default_branch
|
||||
@path = params[:path]
|
||||
@treeish, @path = @project.default_head(params[:treeish]), params[:path]
|
||||
end
|
||||
|
||||
def set_branch_and_tree
|
||||
|
|
|
@ -152,8 +152,8 @@ class Projects::PullRequestsController < Projects::BaseController
|
|||
@pull.issue.body = pull_params[:issue_attributes][:body].presence
|
||||
end
|
||||
@pull.from_project = @project
|
||||
@pull.to_ref = (pull_params[:to_ref].presence if pull_params) || @pull.to_project.default_branch
|
||||
@pull.from_ref = params[:treeish].presence || (pull_params[:from_ref].presence if pull_params) || @pull.from_project.default_branch
|
||||
@pull.to_ref = (pull_params[:to_ref].presence if pull_params) || @pull.to_project.default_head(params[:treeish])
|
||||
@pull.from_ref = params[:treeish].presence || (pull_params[:from_ref].presence if pull_params) || @pull.from_project.default_head(params[:treeish])
|
||||
@pull.from_project_owner_uname = @pull.from_project.owner.uname
|
||||
@pull.from_project_name = @pull.from_project.name
|
||||
end
|
||||
|
|
|
@ -178,6 +178,14 @@ class Project < ActiveRecord::Base
|
|||
AbfWorker::BuildListsPublishTaskManager.destroy_project_from_repository self, repository
|
||||
end
|
||||
|
||||
def default_head treeish = nil # maybe need change 'head'?
|
||||
if repo.branches_and_tags.map(&:name).include?(treeish || default_branch)
|
||||
treeish
|
||||
else
|
||||
repo.branches_and_tags[0].try(:name) || 'master'
|
||||
end
|
||||
end
|
||||
|
||||
protected
|
||||
|
||||
def truncate_name
|
||||
|
|
|
@ -125,7 +125,7 @@ class PullRequest < ActiveRecord::Base
|
|||
def self.check_ref(record, attr, value)
|
||||
project = attr == :from_ref ? record.from_project : record.to_project
|
||||
return if project.blank?
|
||||
if record.to_project.repo.commits.count > 0
|
||||
if record.to_project.repo.branches.count > 0
|
||||
record.errors.add attr, I18n.t('projects.pull_requests.wrong_ref') unless project.repo.branches_and_tags.map(&:name).include?(value)
|
||||
else
|
||||
record.errors.add attr, I18n.t('projects.pull_requests.empty_repo')
|
||||
|
@ -179,8 +179,8 @@ class PullRequest < ActiveRecord::Base
|
|||
system 'git', 'tag', '-d', from_ref, to_ref
|
||||
system 'git fetch --tags'
|
||||
tags, head = repo.tags.map(&:name), to_project == from_project ? 'origin' : 'head'
|
||||
system 'git', 'checkout', to_ref
|
||||
unless tags.include? to_ref
|
||||
system 'git', 'checkout', to_ref
|
||||
system 'git', 'reset', '--hard', "origin/#{to_ref}"
|
||||
end
|
||||
unless tags.include? from_ref
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
- content_for :submenu do
|
||||
- act = action_name.to_sym; contr = controller_name.to_sym; treeish = params[:treeish].presence || @project.default_branch
|
||||
- act = action_name.to_sym; contr = controller_name.to_sym; treeish = @project.default_head(params[:treeish])
|
||||
.left
|
||||
.table-sort-left=image_tag visibility_icon(@project.visibility)
|
||||
.table-sort-right=@project.name
|
||||
|
|
Loading…
Reference in New Issue