Merge pull request #879 from warpc/878-fix_bugs_with_git_without_master

[refs #878] Fix varios errors with missing default git branch what set in project settings.
This commit is contained in:
Vladimir Sharshov 2013-02-01 05:53:46 -08:00
commit f3033caac4
6 changed files with 16 additions and 9 deletions

View File

@ -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

View File

@ -1,7 +1,7 @@
# -*- encoding : utf-8 -*-
class Projects::Git::TreesController < Projects::Git::BaseController
before_filter lambda{redirect_to @project if params[:treeish] == @project.default_branch and params[:path].blank?}, :only => :show
skip_before_filter :set_branch_and_tree, :only => :archive
skip_before_filter :set_branch_and_tree, :set_treeish_and_path, :only => :archive
def show
@tree = @tree / @path if @path.present?
@ -10,7 +10,7 @@ class Projects::Git::TreesController < Projects::Git::BaseController
end
def archive
format = params[:format]
format, @treeish = params[:format], params[:treeish]
if (@treeish =~ /^#{@project.owner.uname}-#{@project.name}-/) && !(@treeish =~ /[\s]+/) && (format =~ /^(zip|tar\.gz)$/)
@treeish = @treeish.gsub(/^#{@project.owner.uname}-#{@project.name}-/, '')
@commit = @project.repo.commits(@treeish, 1).first

View File

@ -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

View File

@ -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 || default_branch
else
repo.branches_and_tags[0].try(:name) || default_branch
end
end
protected
def truncate_name

View File

@ -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

View File

@ -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