diff --git a/app/controllers/commits_controller.rb b/app/controllers/commits_controller.rb index 712b842..b508d28 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 0000000..1124fd0 --- /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/commits/compare.html.haml b/app/views/commits/compare.html.haml deleted file mode 100644 index db15ba5..0000000 --- a/app/views/commits/compare.html.haml +++ /dev/null @@ -1,53 +0,0 @@ -= render "head" - -%h3.page_title - Compare View -%hr - -%div - %p.slead - Fill input field with commit id like - %code.label_branch 4eedf23 - or branch/tag name like - %code.label_branch master - and press compare button for commits list, code diff. - - %br - - = form_tag compare_project_commits_path(@project), method: :get do - .clearfix - = text_field_tag :from, params[:from], placeholder: "master", class: "xlarge" - = "..." - = text_field_tag :to, params[:to], placeholder: "aa8b4ef", class: "xlarge" - - if @refs_are_same - .alert - %span Refs are the same - .actions - = submit_tag "Compare", class: "btn primary wide commits-compare-btn" - -- if @commits.present? - %div.ui-box - %h5.small Commits (#{@commits.count}) - %ul.unstyled= render @commits - - - unless @diffs.empty? - %h4 Diff - = render "commits/diffs", diffs: @diffs - -:javascript - $(function() { - var availableTags = #{@project.ref_names.to_json}; - - $("#from").autocomplete({ - source: availableTags, - minLength: 1 - }); - - $("#to").autocomplete({ - source: availableTags, - minLength: 1 - }); - - disableButtonIfEmptyField('#to', '.commits-compare-btn'); - }); - diff --git a/app/views/compare/_head.html.haml b/app/views/compare/_head.html.haml new file mode 100644 index 0000000..a8111a7 --- /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/compare/show.html.haml b/app/views/compare/show.html.haml new file mode 100644 index 0000000..db15ba5 --- /dev/null +++ b/app/views/compare/show.html.haml @@ -0,0 +1,53 @@ += render "head" + +%h3.page_title + Compare View +%hr + +%div + %p.slead + Fill input field with commit id like + %code.label_branch 4eedf23 + or branch/tag name like + %code.label_branch master + and press compare button for commits list, code diff. + + %br + + = form_tag compare_project_commits_path(@project), method: :get do + .clearfix + = text_field_tag :from, params[:from], placeholder: "master", class: "xlarge" + = "..." + = text_field_tag :to, params[:to], placeholder: "aa8b4ef", class: "xlarge" + - if @refs_are_same + .alert + %span Refs are the same + .actions + = submit_tag "Compare", class: "btn primary wide commits-compare-btn" + +- if @commits.present? + %div.ui-box + %h5.small Commits (#{@commits.count}) + %ul.unstyled= render @commits + + - unless @diffs.empty? + %h4 Diff + = render "commits/diffs", diffs: @diffs + +:javascript + $(function() { + var availableTags = #{@project.ref_names.to_json}; + + $("#from").autocomplete({ + source: availableTags, + minLength: 1 + }); + + $("#to").autocomplete({ + source: availableTags, + minLength: 1 + }); + + disableButtonIfEmptyField('#to', '.commits-compare-btn'); + }); + diff --git a/config/routes.rb b/config/routes.rb index af7b9bd..708dd7d 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 04164d5..2939f2f 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 -- libgit2 0.21.2