From 8860238da4a8ab7bec4b57dbc2d2e1be3c7e0f20 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 31 Jan 2013 22:26:49 +0600 Subject: [PATCH 1/4] [refs #878] fix some bugs when no master branch --- app/controllers/projects/git/base_controller.rb | 3 +-- app/controllers/projects/pull_requests_controller.rb | 4 ++-- app/models/project.rb | 8 ++++++++ app/models/pull_request.rb | 4 ++-- app/views/projects/base/_submenu.html.haml | 2 +- 5 files changed, 14 insertions(+), 7 deletions(-) diff --git a/app/controllers/projects/git/base_controller.rb b/app/controllers/projects/git/base_controller.rb index fbf60d44c..f8976c2d8 100644 --- a/app/controllers/projects/git/base_controller.rb +++ b/app/controllers/projects/git/base_controller.rb @@ -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 diff --git a/app/controllers/projects/pull_requests_controller.rb b/app/controllers/projects/pull_requests_controller.rb index 63ce7cdc0..b0157df05 100644 --- a/app/controllers/projects/pull_requests_controller.rb +++ b/app/controllers/projects/pull_requests_controller.rb @@ -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 diff --git a/app/models/project.rb b/app/models/project.rb index b9a795d45..2f58f40e7 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -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 diff --git a/app/models/pull_request.rb b/app/models/pull_request.rb index a67af1587..ae549e93e 100644 --- a/app/models/pull_request.rb +++ b/app/models/pull_request.rb @@ -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 diff --git a/app/views/projects/base/_submenu.html.haml b/app/views/projects/base/_submenu.html.haml index 67b6fb37d..e74348da6 100644 --- a/app/views/projects/base/_submenu.html.haml +++ b/app/views/projects/base/_submenu.html.haml @@ -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 From 913b8469fecbebf98a97b6f12eee7aafa5b475c6 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 31 Jan 2013 23:18:57 +0600 Subject: [PATCH 2/4] [refs #878] fix bug with default head --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 2f58f40e7..3a697e7af 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -180,7 +180,7 @@ class Project < ActiveRecord::Base def default_head treeish = nil # maybe need change 'head'? if repo.branches_and_tags.map(&:name).include?(treeish || default_branch) - treeish + treeish || default_branch else repo.branches_and_tags[0].try(:name) || 'master' end From 7185a46ed70401e9d1595fd1003b14c16aa10ae3 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 31 Jan 2013 23:26:41 +0600 Subject: [PATCH 3/4] [refs #878] fixed ActionController::RoutingError (Not Found) for archives --- app/controllers/projects/git/trees_controller.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/git/trees_controller.rb b/app/controllers/projects/git/trees_controller.rb index f32414efd..ad940afae 100644 --- a/app/controllers/projects/git/trees_controller.rb +++ b/app/controllers/projects/git/trees_controller.rb @@ -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 From 927c352f8a92f9041ddd8add0d36884da6b4fd1a Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 31 Jan 2013 23:44:02 +0600 Subject: [PATCH 4/4] [refs #878] fixed last value --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 3a697e7af..f1f395ff4 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -182,7 +182,7 @@ class Project < ActiveRecord::Base if repo.branches_and_tags.map(&:name).include?(treeish || default_branch) treeish || default_branch else - repo.branches_and_tags[0].try(:name) || 'master' + repo.branches_and_tags[0].try(:name) || default_branch end end