Commit cbe9f56afae2b1e55de96f59eed36859eea6eb82

Authored by Dmitriy Zaporozhets
1 parent d65eb22e

Ability to create new branch via UI

app/controllers/projects/branches_controller.rb
... ... @@ -10,7 +10,9 @@ class Projects::BranchesController < Projects::ApplicationController
10 10 end
11 11  
12 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 16 end
15 17  
16 18 def destroy
... ... @@ -21,7 +23,7 @@ class Projects::BranchesController < Projects::ApplicationController
21 23 end
22 24  
23 25 respond_to do |format|
24   - format.html { redirect_to project_branches_path }
  26 + format.html { redirect_to project_branches_path(@project) }
25 27 format.js { render nothing: true }
26 28 end
27 29 end
... ...
app/models/repository.rb
... ... @@ -35,11 +35,21 @@ class Repository
35 35 commits
36 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 44 def rm_branch(branch_name)
  45 + Rails.cache.delete(cache_key(:branch_names))
  46 +
39 47 gitlab_shell.rm_branch(path_with_namespace, branch_name)
40 48 end
41 49  
42 50 def rm_tag(tag_name)
  51 + Rails.cache.delete(cache_key(:tag_names))
  52 +
43 53 gitlab_shell.rm_tag(path_with_namespace, tag_name)
44 54 end
45 55  
... ...
app/views/projects/branches/new.html.haml 0 → 100644
... ... @@ -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 7 %i.icon-lock
8 8 = nav_link(path: 'branches#index') do
9 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 223 end
224 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 228 resources :protected_branches, only: [:index, :create, :destroy]
229 229  
230 230 resources :refs, only: [] do
... ...