From 2e33f0038a01969643a463235769e4c54f1f45b4 Mon Sep 17 00:00:00 2001 From: Vokhmin Alexey V Date: Thu, 11 Jul 2013 17:03:02 +0400 Subject: [PATCH] #214: added ability to destroy branch --- Gemfile.lock | 2 -- .../angularjs/models/project_ref.js | 4 +++ app/controllers/api/v1/projects_controller.rb | 2 ++ .../projects/git/trees_controller.rb | 9 +++---- .../api/v1/projects/refs_list.json.jbuilder | 3 ++- .../projects/git/trees/_header.html.haml | 10 ------- .../{refs.html.haml => branches.html.haml} | 25 +++++++---------- app/views/projects/git/trees/tags.html.haml | 27 +++++++++++++++++++ config/routes.rb | 3 +-- lib/modules/models/git.rb | 5 ++++ 10 files changed, 55 insertions(+), 35 deletions(-) delete mode 100644 app/views/projects/git/trees/_header.html.haml rename app/views/projects/git/trees/{refs.html.haml => branches.html.haml} (61%) create mode 100644 app/views/projects/git/trees/tags.html.haml diff --git a/Gemfile.lock b/Gemfile.lock index acd63234d..6eea35873 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -59,7 +59,6 @@ GEM ancestry (1.3.0) activerecord (>= 2.3.14) angularjs-rails (1.0.7) - angularjs-rails-resource (0.2.0) arel (3.0.2) attr_encrypted (1.2.1) encryptor (>= 1.1.1) @@ -411,7 +410,6 @@ DEPENDENCIES airbrake (~> 3.1.2) ancestry (~> 1.3.0) angularjs-rails - angularjs-rails-resource attr_encrypted (= 1.2.1) better_errors binding_of_caller diff --git a/app/assets/javascripts/angularjs/models/project_ref.js b/app/assets/javascripts/angularjs/models/project_ref.js index 3cae1999f..b13b40dc9 100644 --- a/app/assets/javascripts/angularjs/models/project_ref.js +++ b/app/assets/javascripts/angularjs/models/project_ref.js @@ -20,6 +20,10 @@ var ProjectRef = function(atts) { return '/' + project.fullname + '/diff/' + current_ref + '...' + self.ref; } + self.archive_path = function(project, type) { + return '/' + project.fullname + '/archive/' + project.name + '-' + self.ref + '.' + type; + } + //return the scope-safe instance return self; }; \ No newline at end of file diff --git a/app/controllers/api/v1/projects_controller.rb b/app/controllers/api/v1/projects_controller.rb index 01e891cca..125324a8b 100644 --- a/app/controllers/api/v1/projects_controller.rb +++ b/app/controllers/api/v1/projects_controller.rb @@ -23,6 +23,8 @@ class Api::V1::ProjectsController < Api::V1::BaseController end def refs_list + @refs = @project.repo.branches.sort_by(&:name) + + @project.repo.tags.select{ |t| t.commit }.sort_by(&:name).reverse end def update diff --git a/app/controllers/projects/git/trees_controller.rb b/app/controllers/projects/git/trees_controller.rb index cca6cef51..2cb5409e4 100644 --- a/app/controllers/projects/git/trees_controller.rb +++ b/app/controllers/projects/git/trees_controller.rb @@ -3,6 +3,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, :set_treeish_and_path, :only => :archive + before_filter lambda { raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) }, :only => [:branch, :destroy] + def show render('empty') and return if @project.is_empty? @tree = @tree / @path if @path.present? @@ -28,18 +30,15 @@ class Projects::Git::TreesController < Projects::Git::BaseController end def tags - @tags = @project.repo.tags.select{ |t| t.commit }.sort_by(&:name).reverse - render 'refs' end def destroy + raise Grit::NoSuchPathError unless @branch + @project.delete_branch @branch.name render :nothing => true end def branches - raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) # get wrong branch name to nonempty project - # @branches = @project.repo.branches.sort_by(&:name).select{ |b| b.name != @branch.name }.unshift(@branch).compact if @branch - render 'refs' end end diff --git a/app/views/api/v1/projects/refs_list.json.jbuilder b/app/views/api/v1/projects/refs_list.json.jbuilder index 7b913f98b..3307a1e59 100644 --- a/app/views/api/v1/projects/refs_list.json.jbuilder +++ b/app/views/api/v1/projects/refs_list.json.jbuilder @@ -1,8 +1,9 @@ -json.refs_list (@project.repo.branches + @project.repo.tags) do |json_grit, grit| +json.refs_list @refs do |json_grit, grit| json_grit.ref grit.name json_grit.object do |json_object| json_object.type (grit.class.name =~ /Tag/ ? 'tag' : 'commit') json_object.sha grit.commit.id + json_object.authored_date grit.commit.authored_date.strftime('%d.%m.%Y') end end json.url refs_list_api_v1_project_path(@project.id, :format => :json) \ No newline at end of file diff --git a/app/views/projects/git/trees/_header.html.haml b/app/views/projects/git/trees/_header.html.haml deleted file mode 100644 index 451651137..000000000 --- a/app/views/projects/git/trees/_header.html.haml +++ /dev/null @@ -1,10 +0,0 @@ -- subjects_name = action_name.to_s - -%h3= t("layout.projects.#{subjects_name}") -- if subject.blank? - %p= t("layout.projects.no_#{subjects_name}") -- elsif subject.count == 1 - %p= t("layout.projects.total_#{subjects_name.singularize}") -- else - %p= t("layout.projects.total_#{subjects_name}", :count => subject.count) -.both \ No newline at end of file diff --git a/app/views/projects/git/trees/refs.html.haml b/app/views/projects/git/trees/branches.html.haml similarity index 61% rename from app/views/projects/git/trees/refs.html.haml rename to app/views/projects/git/trees/branches.html.haml index a047b0cc0..e6f16284e 100644 --- a/app/views/projects/git/trees/refs.html.haml +++ b/app/views/projects/git/trees/branches.html.haml @@ -2,15 +2,17 @@ = render 'submenu' = render 'repo_block', :project => @project -= render 'header', :subject => (@branches || @tags) - %div{'ng-controller' => 'ProjectRefsController', 'ng-init' => "init('#{@project.id}','#{@branch.try(:name)}')"} + %h3= t('layout.projects.branches') + %p{'ng-show' => '!branches.length'}= t('layout.projects.no_branches') + %p{'ng-show' => 'branches.length == 1'}= t('layout.projects.total_branch') + %p{'ng-show' => 'branches.length > 1'}= t('layout.projects.total_branches', :count => '{{branches.length}}') .both - Search: - %input{'ng-model' => 'query.ref'} + + %input{'ng-model' => 'query.ref'} .both %table#project-branches @@ -23,16 +25,9 @@ %li.text{'ng-show' => 'branch.ref == current_ref'} = t('layout.projects.base_branch') %li{'ng-hide' => 'branch.ref == current_ref'} - %a{:href => '#', 'ng-click' => 'destroy(branch)'}= t('layout.projects.delete_branch') + %a{:href => '', 'ng-click' => 'destroy(branch)'} + = t('layout.projects.delete_branch') %li{'ng-hide' => 'branch.ref == current_ref'} - %a{'ng-href' => '{{branch.diff_path(project, current_ref)}}' }= t('layout.projects.compare') + %a{'ng-href' => '{{branch.diff_path(project, current_ref)}}' } + = t('layout.projects.compare') - -- if @tags.present? - %div#project-tags - %ol.release-list - = render :partial => 'tag', :collection => @tags -- elsif false # @branches.present? - %table#project-branches - %tbody - = render :partial => 'branch', :collection => @branches diff --git a/app/views/projects/git/trees/tags.html.haml b/app/views/projects/git/trees/tags.html.haml new file mode 100644 index 000000000..2cf881b53 --- /dev/null +++ b/app/views/projects/git/trees/tags.html.haml @@ -0,0 +1,27 @@ +-set_meta_tags :title => "#{title_object @project}" + += render 'submenu' += render 'repo_block', :project => @project + +%div{'ng-controller' => 'ProjectRefsController', 'ng-init' => "init('#{@project.id}')"} + + %h3= t('layout.projects.tags') + %p{'ng-show' => '!tags.length'}= t('layout.projects.no_tags') + %p{'ng-show' => 'tags.length == 1'}= t('layout.projects.total_tag') + %p{'ng-show' => 'tags.length > 1'}= t('layout.projects.total_tags', :count => '{{tags.length}}') + .both + + %input{'ng-model' => 'query.ref'} + .both + + #project-tags + %ol.release-list + %li{'ng-repeat' => 'tag in tags | filter:query'} + %a.detail-link{'ng-href' => '{{tag.path(project)}}' } + = t('layout.projects.browse_code') + - %w(zip tar.gz).each do |type| + %a.detail-link{'ng-href' => "{{tag.archive_path(project, '#{type}')}}" } + = t('layout.projects.source_code', :type => type) + %p.name + %b {{tag.ref}} + .date {{tag.object.authored_date}} diff --git a/config/routes.rb b/config/routes.rb index 907326ea0..f6009a048 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -331,10 +331,9 @@ Rosa::Application.routes.draw do get '/tree/:treeish(/*path)' => "git/trees#show", :as => :tree, :format => false # Tags get '/tags' => "git/trees#tags", :as => :tags - # delete '/tags/:treeish' => "git/trees#destroy", :as => :tags # Branches get '/branches/:treeish' => "git/trees#branches", :as => :branches - # delete '/branches/:treeish' => "git/trees#destroy", :as => :branches + delete '/branches/:treeish' => "git/trees#destroy", :as => :branches # Commits get '/commits/:treeish(/*path)' => "git/commits#index", :as => :commits, :format => false get '/commit/:id(.:format)' => "git/commits#show", :as => :commit diff --git a/lib/modules/models/git.rb b/lib/modules/models/git.rb index 6d96bd851..03eb25616 100644 --- a/lib/modules/models/git.rb +++ b/lib/modules/models/git.rb @@ -33,6 +33,11 @@ module Modules repo.tags.map(&:name) + repo.branches.map(&:name) end + def delete_branch(branch_name) + repo.git.native(:branch, {}, '-D', branch_name) + + end + def update_file(path, data, options = {}) head = options[:head].to_s || default_branch actor = get_actor(options[:actor])