diff --git a/app/controllers/projects/branches_controller.rb b/app/controllers/projects/branches_controller.rb index 00811f17adb17f858fe5441b316d44c7eb989109..8c70ae45f06f7bb4932bb0be3fe41ede1d5ff1dd 100644 --- a/app/controllers/projects/branches_controller.rb +++ b/app/controllers/projects/branches_controller.rb @@ -7,7 +7,9 @@ class Projects::BranchesController < Projects::ApplicationController before_filter :authorize_push!, only: [:create, :destroy] def index - @branches = Kaminari.paginate_array(@repository.branches).page(params[:page]).per(30) + @sort = params[:sort] || 'name' + @branches = @repository.branches_sorted_by(@sort) + @branches = Kaminari.paginate_array(@branches).page(params[:page]).per(30) end def recent diff --git a/app/controllers/projects/protected_branches_controller.rb b/app/controllers/projects/protected_branches_controller.rb index cfc1bd99a2040e8a91ff549d7c72aa648ebdd718..e39e97af8dd1c9bb4fdc915af8bec19576ef655f 100644 --- a/app/controllers/projects/protected_branches_controller.rb +++ b/app/controllers/projects/protected_branches_controller.rb @@ -1,9 +1,9 @@ class Projects::ProtectedBranchesController < Projects::ApplicationController # Authorize - before_filter :authorize_read_project! before_filter :require_non_empty_project + before_filter :authorize_admin_project! - before_filter :authorize_admin_project!, only: [:destroy, :create] + layout "project_settings" def index @branches = @project.protected_branches.to_a diff --git a/app/helpers/tab_helper.rb b/app/helpers/tab_helper.rb index bd373c5f3cfa62def8429e9388cfbbb0c8c69599..610175f844791eead95398cc3d02966c0fab0ded 100644 --- a/app/helpers/tab_helper.rb +++ b/app/helpers/tab_helper.rb @@ -75,7 +75,7 @@ module TabHelper def project_tab_class return "active" if current_page?(controller: "/projects", action: :edit, id: @project) - if ['services', 'hooks', 'deploy_keys', 'team_members'].include? controller.controller_name + if ['services', 'hooks', 'deploy_keys', 'team_members', 'protected_branches'].include? controller.controller_name "active" end end diff --git a/app/models/repository.rb b/app/models/repository.rb index eadc34127c2bd9109c9c3e9dee9ddfe3b08324a0..b7239236aea1b6787bfb1ee986569c9b778b6476 100644 --- a/app/models/repository.rb +++ b/app/models/repository.rb @@ -55,12 +55,6 @@ class Repository tags.find { |tag| tag.name == name } end - def recent_branches(limit = 20) - branches.sort do |a, b| - commit(b.target).committed_date <=> commit(a.target).committed_date - end[0..limit] - end - def add_branch(branch_name, ref) Rails.cache.delete(cache_key(:branch_names)) @@ -220,4 +214,19 @@ class Repository def clean_old_archives Gitlab::Popen.popen(%W(find #{Gitlab.config.gitlab.repository_downloads_path} -mmin +120 -delete)) end + + def branches_sorted_by(value) + case value + when 'recently_updated' + branches.sort do |a, b| + commit(b.target).committed_date <=> commit(a.target).committed_date + end + when 'last_updated' + branches.sort do |a, b| + commit(a.target).committed_date <=> commit(b.target).committed_date + end + else + branches + end + end end diff --git a/app/views/layouts/nav/_project.html.haml b/app/views/layouts/nav/_project.html.haml index 1f70cf17987217bb4a55f9ec43380833874af640..d7d330e2a616ef20ee5105068bb6fc98adc52432 100644 --- a/app/views/layouts/nav/_project.html.haml +++ b/app/views/layouts/nav/_project.html.haml @@ -8,7 +8,7 @@ = link_to 'Files', project_tree_path(@project, @ref || @repository.root_ref) - if project_nav_tab? :commits - = nav_link(controller: %w(commit commits compare repositories protected_branches tags branches)) do + = nav_link(controller: %w(commit commits compare repositories tags branches)) do = link_to "Commits", project_commits_path(@project, @ref || @repository.root_ref) - if project_nav_tab? :network diff --git a/app/views/projects/_settings_nav.html.haml b/app/views/projects/_settings_nav.html.haml index 4c7b088ae9a54be71b49d0a3c2026b54d0a8dbfe..9b73f06a5be55381efc828d8e85ed8419bd2b33a 100644 --- a/app/views/projects/_settings_nav.html.haml +++ b/app/views/projects/_settings_nav.html.haml @@ -19,3 +19,7 @@ = link_to project_services_path(@project) do %i.icon-cogs Services + = nav_link(controller: :protected_branches) do + = link_to project_protected_branches_path(@project) do + %i.icon-lock + Protected branches diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml index 87f4dd88c27e04dc212f1fadcd1aabcdafa3e4e6..a5f382c9a5cfda34c3a16637e85affec375f4f15 100644 --- a/app/views/projects/branches/_branch.html.haml +++ b/app/views/projects/branches/_branch.html.haml @@ -8,6 +8,7 @@ - if @project.protected_branch? branch.name %span.label.label-success %i.icon-lock + protected .pull-right - if can?(current_user, :download_code, @project) = render 'projects/repositories/download_archive', ref: branch.name, btn_class: 'btn-grouped btn-group-small' @@ -21,13 +22,8 @@ %i.icon-trash - if commit - %p - = link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do - = commit.short_id - = image_tag avatar_icon(commit.author_email), class: "avatar s16", alt: '' - %span.light - = gfm escape_once(truncate(commit.title, length: 40)) - #{time_ago_with_tooltip(commit.committed_date)} + %ul.list-unstyled + = render 'projects/commits/inline_commit', commit: commit, project: @project - else %p Cant find HEAD commit for this branch diff --git a/app/views/projects/branches/_filter.html.haml b/app/views/projects/branches/_filter.html.haml deleted file mode 100644 index 7e1478292e01b3deb8c3aaed00d311ded225cbbd..0000000000000000000000000000000000000000 --- a/app/views/projects/branches/_filter.html.haml +++ /dev/null @@ -1,27 +0,0 @@ -%ul.nav.nav-pills.nav-stacked - = nav_link(path: 'branches#recent') do - = link_to recent_project_branches_path(@project) do - Recent - .pull-right - = @repository.recent_branches.count - - = nav_link(path: 'protected_branches#index') do - = link_to project_protected_branches_path(@project) do - Protected - %i.icon-lock - .pull-right - = @project.protected_branches.count - - = nav_link(path: 'branches#index') do - = link_to project_branches_path(@project) do - All branches - .pull-right - = @repository.branch_names.count - - -%hr -- if can? current_user, :push_code, @project - = link_to new_project_branch_path(@project), class: 'btn btn-create' do - %i.icon-add-sign - New branch - diff --git a/app/views/projects/branches/index.html.haml b/app/views/projects/branches/index.html.haml index bee04eb013ebbb6c7315a21c0236de2ed8fd88a5..8bc4a8f7e989c7a054c2207ebcc0e6dd488a630e 100644 --- a/app/views/projects/branches/index.html.haml +++ b/app/views/projects/branches/index.html.haml @@ -1,10 +1,31 @@ = render "projects/commits/head" -.row - .col-md-3 - = render "filter" - .col-md-9 - - unless @branches.empty? - %ul.bordered-list.top-list.all-branches - - @branches.each do |branch| - = render "projects/branches/branch", branch: branch - = paginate @branches, theme: 'gitlab' +%h3.page-title + Branches + .pull-right + - if can? current_user, :push_code, @project + = link_to new_project_branch_path(@project), class: 'btn btn-create' do + %i.icon-add-sign + New branch + + .dropdown.inline + %a.dropdown-toggle.btn{href: '#', "data-toggle" => "dropdown"} + %span.light sort: + - if @sort.present? + = @sort.humanize + - else + Name + %b.caret + %ul.dropdown-menu + %li + = link_to project_branches_path(sort: nil) do + Name + = link_to project_branches_path(sort: 'recently_updated') do + Recently updated + = link_to project_branches_path(sort: 'last_updated') do + Last updated +%hr +- unless @branches.empty? + %ul.bordered-list.top-list.all-branches + - @branches.each do |branch| + = render "projects/branches/branch", branch: branch + = paginate @branches, theme: 'gitlab' diff --git a/app/views/projects/branches/recent.html.haml b/app/views/projects/branches/recent.html.haml deleted file mode 100644 index 37d7919121e7d3132e841e122a476eff53dca2eb..0000000000000000000000000000000000000000 --- a/app/views/projects/branches/recent.html.haml +++ /dev/null @@ -1,8 +0,0 @@ -= render "projects/commits/head" -.row - .col-md-3 - = render "filter" - .col-md-9 - %ul.bordered-list.top-list - - @branches.each do |branch| - = render "projects/branches/branch", branch: branch diff --git a/app/views/projects/commits/_head.html.haml b/app/views/projects/commits/_head.html.haml index 81e337439115067a5146285c975bc81029f896ed..0facfc4b5f1d52f88a7dce9ddc23fd8bc3e541d3 100644 --- a/app/views/projects/commits/_head.html.haml +++ b/app/views/projects/commits/_head.html.haml @@ -7,9 +7,9 @@ = link_to 'Compare', project_compare_index_path(@project, from: @repository.root_ref, to: @ref || @repository.root_ref) = nav_link(html_options: {class: branches_tab_class}) do - = link_to recent_project_branches_path(@project) do + = link_to project_branches_path(@project) do Branches - %span.badge= @repository.branches.length + %span.badge= @repository.branches.size = nav_link(controller: :tags) do = link_to project_tags_path(@project) do diff --git a/app/views/projects/protected_branches/index.html.haml b/app/views/projects/protected_branches/index.html.haml index e9f67b671bf10e0f8e9ab2b53fdca5681b73d7d0..e51bf1d3a8cdc5b54865c0766ce54ddcc56e49e3 100644 --- a/app/views/projects/protected_branches/index.html.haml +++ b/app/views/projects/protected_branches/index.html.haml @@ -1,52 +1,50 @@ -= render "projects/commits/head" -.row - .col-md-3 - = render "projects/branches/filter" - .col-md-9 - .bs-callout.bs-callout-info - %p Protected branches designed to - %ul - %li prevent push for all except #{link_to "masters", help_permissions_path, class: "vlink"}. - %li prevent branch from force push - %li prevent branch from removal - %p This ability allows to keep stable branches secured and force code review before merge to protected branches - %p Read more about project permissions #{link_to "here", help_permissions_path, class: "underlined-link"} +%h3.page-title Protected branches +%p.light This ability allows to keep stable branches secured and force code review before merge to protected branches +%hr - - if can? current_user, :admin_project, @project - = form_for [@project, @protected_branch], html: { class: 'form-horizontal' } do |f| - -if @protected_branch.errors.any? - .alert.alert-danger - %ul - - @protected_branch.errors.full_messages.each do |msg| - %li= msg +.bs-callout.bs-callout-info + %p Protected branches designed to + %ul + %li prevent push for all except #{link_to "masters", help_permissions_path, class: "vlink"}. + %li prevent branch from force push + %li prevent branch from removal + %p Read more about project permissions #{link_to "here", help_permissions_path, class: "underlined-link"} - .form-group - = f.label :name, "Branch", class: 'control-label' - .col-sm-10 - = f.select(:name, @project.open_branches.map { |br| [br.name, br.name] } , {include_blank: "Select branch"}, {class: "select2"}) - .form-actions - = f.submit 'Protect', class: "btn-create btn" - - unless @branches.empty? - %h5 Already Protected: - %ul.bordered-list.protected-branches-list - - @branches.each do |branch| - %li - %h4 - = link_to project_commits_path(@project, branch.name) do - %strong= branch.name - - if @project.root_ref?(branch.name) - %span.label.label-info default - %span.label.label-success - %i.icon-lock - .pull-right - - if can? current_user, :admin_project, @project - = link_to 'Unprotect', [@project, branch], data: { confirm: 'Branch will be writable for developers. Are you sure?' }, method: :delete, class: "btn btn-remove btn-small" +- if can? current_user, :admin_project, @project + = form_for [@project, @protected_branch], html: { class: 'form-horizontal' } do |f| + -if @protected_branch.errors.any? + .alert.alert-danger + %ul + - @protected_branch.errors.full_messages.each do |msg| + %li= msg - - if commit = branch.commit - = link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do - = commit.short_id - %span.light - = gfm escape_once(truncate(commit.title, length: 40)) - #{time_ago_with_tooltip(commit.committed_date)} - - else - (branch was removed from repository) + .form-group + = f.label :name, "Branch", class: 'control-label' + .col-sm-10 + = f.select(:name, @project.open_branches.map { |br| [br.name, br.name] } , {include_blank: "Select branch"}, {class: "select2"}) + .form-actions + = f.submit 'Protect', class: "btn-create btn" +- unless @branches.empty? + %h5 Already Protected: + %ul.bordered-list.protected-branches-list + - @branches.each do |branch| + %li + %h4 + = link_to project_commits_path(@project, branch.name) do + %strong= branch.name + - if @project.root_ref?(branch.name) + %span.label.label-info default + %span.label.label-success + %i.icon-lock + .pull-right + - if can? current_user, :admin_project, @project + = link_to 'Unprotect', [@project, branch], data: { confirm: 'Branch will be writable for developers. Are you sure?' }, method: :delete, class: "btn btn-remove btn-small" + + - if commit = branch.commit + = link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do + = commit.short_id + %span.light + = gfm escape_once(truncate(commit.title, length: 40)) + #{time_ago_with_tooltip(commit.committed_date)} + - else + (branch was removed from repository) diff --git a/config/routes.rb b/config/routes.rb index da5a1ba7a871c00a60fce53e72344cd9de6f1ab7..ada9bb1d77a998d203b5605b4d09e96c3a509914 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -243,12 +243,7 @@ Gitlab::Application.routes.draw do end end - resources :branches, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex } do - collection do - get :recent, constraints: { id: Gitlab::Regex.git_reference_regex } - end - end - + resources :branches, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex } resources :tags, only: [:index, :new, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex } resources :protected_branches, only: [:index, :create, :destroy], constraints: { id: Gitlab::Regex.git_reference_regex }