Skip to content

Commit

Permalink
Ability to create new branch via UI
Browse files Browse the repository at this point in the history
  • Loading branch information
dzaporozhets committed Jul 16, 2013
1 parent d65eb22 commit cbe9f56
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 4 deletions.
6 changes: 4 additions & 2 deletions app/controllers/projects/branches_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ def index
end

def create
# TODO: implement
@project.repository.add_branch(params[:branch_name], params[:ref])

redirect_to project_branches_path(@project)
end

def destroy
Expand All @@ -21,7 +23,7 @@ def destroy
end

respond_to do |format|
format.html { redirect_to project_branches_path }
format.html { redirect_to project_branches_path(@project) }
format.js { render nothing: true }
end
end
Expand Down
10 changes: 10 additions & 0 deletions app/models/repository.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,21 @@ def commits_between(target, source)
commits
end

def add_branch(branch_name, ref)
Rails.cache.delete(cache_key(:branch_names))

gitlab_shell.add_branch(path_with_namespace, branch_name, ref)
end

def rm_branch(branch_name)
Rails.cache.delete(cache_key(:branch_names))

gitlab_shell.rm_branch(path_with_namespace, branch_name)
end

def rm_tag(tag_name)
Rails.cache.delete(cache_key(:tag_names))

gitlab_shell.rm_tag(path_with_namespace, tag_name)
end

Expand Down
24 changes: 24 additions & 0 deletions app/views/projects/branches/new.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
%h3.page-title
%i.icon-code-fork
New branch
= form_tag project_branches_path, method: :post do
.control-group
= label_tag :branch_name, 'Name for new branch', class: 'control-label'
.controls
= text_field_tag :branch_name, nil, placeholder: 'feature/dashboard'
.control-group
= label_tag :ref, 'Create from', class: 'control-label'
.controls
= text_field_tag :ref, nil, placeholder: 'master'
.light branch name or commit SHA
.form-actions
= submit_tag 'Create branch', class: 'btn btn-create'
= link_to 'Cancel', project_branches_path(@project), class: 'btn btn-cancel'

:javascript
var availableTags = #{@project.repository.ref_names.to_json};

$("#ref").autocomplete({
source: availableTags,
minLength: 1
});
7 changes: 7 additions & 0 deletions app/views/projects/repositories/_filter.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,10 @@
%i.icon-lock
= nav_link(path: 'branches#index') do
= link_to 'All branches', project_branches_path(@project)


%hr
= link_to new_project_branch_path(@project), class: 'btn btn-create' do
%i.icon-add-sign
New branch

4 changes: 2 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,8 @@
end
end

resources :tags, only: [:index, :create, :destroy]
resources :branches, only: [:index, :create, :destroy]
resources :tags, only: [:index, :new, :create, :destroy]
resources :branches, only: [:index, :new, :create, :destroy]
resources :protected_branches, only: [:index, :create, :destroy]

resources :refs, only: [] do
Expand Down

0 comments on commit cbe9f56

Please sign in to comment.