diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index 712b842c66d..b508d2877a4 100644 --- a/app/controllers/commits_controller.rb +++ b/app/controllers/commits_controller.rb @@ -45,18 +45,6 @@ class CommitsController < ApplicationController # end # end - def compare - result = Commit.compare(project, params[:from], params[:to]) - - @commits = result[:commits] - @commit = result[:commit] - @diffs = result[:diffs] - @refs_are_same = result[:same] - @line_notes = [] - - @commits = CommitDecorator.decorate(@commits) - end - def patch @commit = project.commit(params[:id]) diff --git a/app/controllers/compare_controller.rb b/app/controllers/compare_controller.rb new file mode 100644 index 00000000000..1124fd0caa3 --- /dev/null +++ b/app/controllers/compare_controller.rb @@ -0,0 +1,22 @@ +class CompareController < ApplicationController + before_filter :project + layout "project" + + # Authorize + before_filter :add_project_abilities + before_filter :authorize_read_project! + before_filter :authorize_code_access! + before_filter :require_non_empty_project + + def show + result = Commit.compare(project, params[:from], params[:to]) + + @commits = result[:commits] + @commit = result[:commit] + @diffs = result[:diffs] + @refs_are_same = result[:same] + @line_notes = [] + + @commits = CommitDecorator.decorate(@commits) + end +end diff --git a/app/views/compare/_head.html.haml b/app/views/compare/_head.html.haml new file mode 100644 index 00000000000..a8111a72ed5 --- /dev/null +++ b/app/views/compare/_head.html.haml @@ -0,0 +1,23 @@ +%ul.nav.nav-tabs + %li= render partial: 'shared/ref_switcher', locals: {destination: 'commits'} + %li{class: "#{'active' if current_page?(project_commits_path(@project)) }"} + = link_to project_commits_path(@project) do + Commits + %li{class: "#{'active' if current_page?(compare_project_commits_path(@project)) }"} + = link_to compare_project_commits_path(@project) do + Compare + %li{class: "#{branches_tab_class}"} + = link_to project_repository_path(@project) do + Branches + %span.badge= @project.repo.branch_count + + %li{class: "#{'active' if current_page?(tags_project_repository_path(@project)) }"} + = link_to tags_project_repository_path(@project) do + Tags + %span.badge= @project.repo.tag_count + + - if current_page?(project_commits_path(@project)) && current_user.private_token + %li.right + %span.rss-icon + = link_to project_commits_path(@project, :atom, { private_token: current_user.private_token, ref: @ref }), title: "Feed" do + = image_tag "rss_ui.png", title: "feed" diff --git a/app/views/commits/compare.html.haml b/app/views/compare/show.html.haml similarity index 100% rename from app/views/commits/compare.html.haml rename to app/views/compare/show.html.haml diff --git a/config/routes.rb b/config/routes.rb index af7b9bd4533..708dd7d58f1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -162,10 +162,6 @@ Gitlab::Application.routes.draw do resources :commit, only: [:show], constraints: {id: /[[:alnum:]]{6,40}/} resources :commits, only: [:index, :show] do - collection do - get :compare - end - member do get :patch end @@ -194,6 +190,7 @@ Gitlab::Application.routes.draw do resources :blob, only: [:show], constraints: {id: /.+/} # resources :raw, only: [:show], constraints: {id: /.+/} resources :tree, only: [:show], constraints: {id: /.+/} + match "/compare/:from...:to" => "compare#show", as: "compare", constraints: {from: /.+/, to: /.+/} end root to: "dashboard#index" diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index 04164d5d068..2939f2fcfcc 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -289,16 +289,11 @@ describe CommitController, "routing" do end end -# compare_project_commits GET /:project_id/commits/compare(.:format) commits#compare # patch_project_commit GET /:project_id/commits/:id/patch(.:format) commits#patch # project_commits GET /:project_id/commits(.:format) commits#index # POST /:project_id/commits(.:format) commits#create # project_commit GET /:project_id/commits/:id(.:format) commits#show describe CommitsController, "routing" do - it "to #compare" do - get("/gitlabhq/commits/compare").should route_to('commits#compare', project_id: 'gitlabhq') - end - it "to #patch" do get("/gitlabhq/commits/1/patch").should route_to('commits#patch', project_id: 'gitlabhq', id: '1') end @@ -407,6 +402,13 @@ describe TreeController, "routing" do end end +describe CompareController, "routing" do + it "to #show" do + get("/gitlabhq/compare/master...stable").should route_to('compare#show', project_id: 'gitlabhq', from: 'master', to: 'stable') + get("/gitlabhq/compare/issue/1234...stable").should route_to('compare#show', project_id: 'gitlabhq', from: 'issue/1234', to: 'stable') + end +end + # TODO: Pending # # /:project_id/blame/*path