#214: added ability to destroy branch

This commit is contained in:
Vokhmin Alexey V 2013-07-11 17:03:02 +04:00
parent ddbaffdb13
commit 2e33f0038a
10 changed files with 55 additions and 35 deletions

View File

@ -59,7 +59,6 @@ GEM
ancestry (1.3.0) ancestry (1.3.0)
activerecord (>= 2.3.14) activerecord (>= 2.3.14)
angularjs-rails (1.0.7) angularjs-rails (1.0.7)
angularjs-rails-resource (0.2.0)
arel (3.0.2) arel (3.0.2)
attr_encrypted (1.2.1) attr_encrypted (1.2.1)
encryptor (>= 1.1.1) encryptor (>= 1.1.1)
@ -411,7 +410,6 @@ DEPENDENCIES
airbrake (~> 3.1.2) airbrake (~> 3.1.2)
ancestry (~> 1.3.0) ancestry (~> 1.3.0)
angularjs-rails angularjs-rails
angularjs-rails-resource
attr_encrypted (= 1.2.1) attr_encrypted (= 1.2.1)
better_errors better_errors
binding_of_caller binding_of_caller

View File

@ -20,6 +20,10 @@ var ProjectRef = function(atts) {
return '/' + project.fullname + '/diff/' + current_ref + '...' + self.ref; 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 the scope-safe instance
return self; return self;
}; };

View File

@ -23,6 +23,8 @@ class Api::V1::ProjectsController < Api::V1::BaseController
end end
def refs_list def refs_list
@refs = @project.repo.branches.sort_by(&:name) +
@project.repo.tags.select{ |t| t.commit }.sort_by(&:name).reverse
end end
def update def update

View File

@ -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 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 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 def show
render('empty') and return if @project.is_empty? render('empty') and return if @project.is_empty?
@tree = @tree / @path if @path.present? @tree = @tree / @path if @path.present?
@ -28,18 +30,15 @@ class Projects::Git::TreesController < Projects::Git::BaseController
end end
def tags def tags
@tags = @project.repo.tags.select{ |t| t.commit }.sort_by(&:name).reverse
render 'refs'
end end
def destroy def destroy
raise Grit::NoSuchPathError unless @branch
@project.delete_branch @branch.name
render :nothing => true render :nothing => true
end end
def branches 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
end end

View File

@ -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.ref grit.name
json_grit.object do |json_object| json_grit.object do |json_object|
json_object.type (grit.class.name =~ /Tag/ ? 'tag' : 'commit') json_object.type (grit.class.name =~ /Tag/ ? 'tag' : 'commit')
json_object.sha grit.commit.id json_object.sha grit.commit.id
json_object.authored_date grit.commit.authored_date.strftime('%d.%m.%Y')
end end
end end
json.url refs_list_api_v1_project_path(@project.id, :format => :json) json.url refs_list_api_v1_project_path(@project.id, :format => :json)

View File

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

View File

@ -2,15 +2,17 @@
= render 'submenu' = render 'submenu'
= render 'repo_block', :project => @project = render 'repo_block', :project => @project
= render 'header', :subject => (@branches || @tags)
%div{'ng-controller' => 'ProjectRefsController', %div{'ng-controller' => 'ProjectRefsController',
'ng-init' => "init('#{@project.id}','#{@branch.try(:name)}')"} '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 .both
Search:
%input{'ng-model' => 'query.ref'} %input{'ng-model' => 'query.ref'}
.both .both
%table#project-branches %table#project-branches
@ -23,16 +25,9 @@
%li.text{'ng-show' => 'branch.ref == current_ref'} %li.text{'ng-show' => 'branch.ref == current_ref'}
= t('layout.projects.base_branch') = t('layout.projects.base_branch')
%li{'ng-hide' => 'branch.ref == current_ref'} %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'} %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

View File

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

View File

@ -331,10 +331,9 @@ Rosa::Application.routes.draw do
get '/tree/:treeish(/*path)' => "git/trees#show", :as => :tree, :format => false get '/tree/:treeish(/*path)' => "git/trees#show", :as => :tree, :format => false
# Tags # Tags
get '/tags' => "git/trees#tags", :as => :tags get '/tags' => "git/trees#tags", :as => :tags
# delete '/tags/:treeish' => "git/trees#destroy", :as => :tags
# Branches # Branches
get '/branches/:treeish' => "git/trees#branches", :as => :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 # Commits
get '/commits/:treeish(/*path)' => "git/commits#index", :as => :commits, :format => false get '/commits/:treeish(/*path)' => "git/commits#index", :as => :commits, :format => false
get '/commit/:id(.:format)' => "git/commits#show", :as => :commit get '/commit/:id(.:format)' => "git/commits#show", :as => :commit

View File

@ -33,6 +33,11 @@ module Modules
repo.tags.map(&:name) + repo.branches.map(&:name) repo.tags.map(&:name) + repo.branches.map(&:name)
end end
def delete_branch(branch_name)
repo.git.native(:branch, {}, '-D', branch_name)
end
def update_file(path, data, options = {}) def update_file(path, data, options = {})
head = options[:head].to_s || default_branch head = options[:head].to_s || default_branch
actor = get_actor(options[:actor]) actor = get_actor(options[:actor])