Commit d20f78f70085b7a19df88f91e125fe76cf1b493e
Exists in
master
and in
4 other branches
Merge branch 'feature/create_branch'
Showing
5 changed files
with
47 additions
and
4 deletions
Show diff stats
app/controllers/projects/branches_controller.rb
| @@ -10,7 +10,9 @@ class Projects::BranchesController < Projects::ApplicationController | @@ -10,7 +10,9 @@ class Projects::BranchesController < Projects::ApplicationController | ||
| 10 | end | 10 | end |
| 11 | 11 | ||
| 12 | def create | 12 | def create |
| 13 | - # TODO: implement | 13 | + @project.repository.add_branch(params[:branch_name], params[:ref]) |
| 14 | + | ||
| 15 | + redirect_to project_branches_path(@project) | ||
| 14 | end | 16 | end |
| 15 | 17 | ||
| 16 | def destroy | 18 | def destroy |
| @@ -21,7 +23,7 @@ class Projects::BranchesController < Projects::ApplicationController | @@ -21,7 +23,7 @@ class Projects::BranchesController < Projects::ApplicationController | ||
| 21 | end | 23 | end |
| 22 | 24 | ||
| 23 | respond_to do |format| | 25 | respond_to do |format| |
| 24 | - format.html { redirect_to project_branches_path } | 26 | + format.html { redirect_to project_branches_path(@project) } |
| 25 | format.js { render nothing: true } | 27 | format.js { render nothing: true } |
| 26 | end | 28 | end |
| 27 | end | 29 | end |
app/models/repository.rb
| @@ -35,11 +35,21 @@ class Repository | @@ -35,11 +35,21 @@ class Repository | ||
| 35 | commits | 35 | commits |
| 36 | end | 36 | end |
| 37 | 37 | ||
| 38 | + def add_branch(branch_name, ref) | ||
| 39 | + Rails.cache.delete(cache_key(:branch_names)) | ||
| 40 | + | ||
| 41 | + gitlab_shell.add_branch(path_with_namespace, branch_name, ref) | ||
| 42 | + end | ||
| 43 | + | ||
| 38 | def rm_branch(branch_name) | 44 | def rm_branch(branch_name) |
| 45 | + Rails.cache.delete(cache_key(:branch_names)) | ||
| 46 | + | ||
| 39 | gitlab_shell.rm_branch(path_with_namespace, branch_name) | 47 | gitlab_shell.rm_branch(path_with_namespace, branch_name) |
| 40 | end | 48 | end |
| 41 | 49 | ||
| 42 | def rm_tag(tag_name) | 50 | def rm_tag(tag_name) |
| 51 | + Rails.cache.delete(cache_key(:tag_names)) | ||
| 52 | + | ||
| 43 | gitlab_shell.rm_tag(path_with_namespace, tag_name) | 53 | gitlab_shell.rm_tag(path_with_namespace, tag_name) |
| 44 | end | 54 | end |
| 45 | 55 |
| @@ -0,0 +1,24 @@ | @@ -0,0 +1,24 @@ | ||
| 1 | +%h3.page-title | ||
| 2 | + %i.icon-code-fork | ||
| 3 | + New branch | ||
| 4 | += form_tag project_branches_path, method: :post do | ||
| 5 | + .control-group | ||
| 6 | + = label_tag :branch_name, 'Name for new branch', class: 'control-label' | ||
| 7 | + .controls | ||
| 8 | + = text_field_tag :branch_name, nil, placeholder: 'feature/dashboard' | ||
| 9 | + .control-group | ||
| 10 | + = label_tag :ref, 'Create from', class: 'control-label' | ||
| 11 | + .controls | ||
| 12 | + = text_field_tag :ref, nil, placeholder: 'master' | ||
| 13 | + .light branch name or commit SHA | ||
| 14 | + .form-actions | ||
| 15 | + = submit_tag 'Create branch', class: 'btn btn-create' | ||
| 16 | + = link_to 'Cancel', project_branches_path(@project), class: 'btn btn-cancel' | ||
| 17 | + | ||
| 18 | +:javascript | ||
| 19 | + var availableTags = #{@project.repository.ref_names.to_json}; | ||
| 20 | + | ||
| 21 | + $("#ref").autocomplete({ | ||
| 22 | + source: availableTags, | ||
| 23 | + minLength: 1 | ||
| 24 | + }); |
app/views/projects/repositories/_filter.html.haml
| @@ -7,3 +7,10 @@ | @@ -7,3 +7,10 @@ | ||
| 7 | %i.icon-lock | 7 | %i.icon-lock |
| 8 | = nav_link(path: 'branches#index') do | 8 | = nav_link(path: 'branches#index') do |
| 9 | = link_to 'All branches', project_branches_path(@project) | 9 | = link_to 'All branches', project_branches_path(@project) |
| 10 | + | ||
| 11 | + | ||
| 12 | +%hr | ||
| 13 | + = link_to new_project_branch_path(@project), class: 'btn btn-create' do | ||
| 14 | + %i.icon-add-sign | ||
| 15 | + New branch | ||
| 16 | + |
config/routes.rb
| @@ -223,8 +223,8 @@ Gitlab::Application.routes.draw do | @@ -223,8 +223,8 @@ Gitlab::Application.routes.draw do | ||
| 223 | end | 223 | end |
| 224 | end | 224 | end |
| 225 | 225 | ||
| 226 | - resources :tags, only: [:index, :create, :destroy] | ||
| 227 | - resources :branches, only: [:index, :create, :destroy] | 226 | + resources :tags, only: [:index, :new, :create, :destroy] |
| 227 | + resources :branches, only: [:index, :new, :create, :destroy] | ||
| 228 | resources :protected_branches, only: [:index, :create, :destroy] | 228 | resources :protected_branches, only: [:index, :create, :destroy] |
| 229 | 229 | ||
| 230 | resources :refs, only: [] do | 230 | resources :refs, only: [] do |