Commit 13b97d3f authored by Douwe Maan's avatar Douwe Maan

Merge branch '31576-redirect-commits-to-root-if-no-ref' into 'master'

Resolve "Define /commits/ behaviour"

Closes #31576

See merge request gitlab-org/gitlab-ce!20738
parents 64661425 1dbf32d8
......@@ -4,13 +4,17 @@ class Projects::CommitsController < Projects::ApplicationController
include ExtractsPath
include RendersCommits
before_action :whitelist_query_limiting
before_action :whitelist_query_limiting, except: :commits_root
before_action :require_non_empty_project
before_action :assign_ref_vars
before_action :assign_ref_vars, except: :commits_root
before_action :authorize_download_code!
before_action :set_commits
before_action :set_commits, except: :commits_root
before_action :set_request_format, only: :show
def commits_root
redirect_to project_commits_path(@project, @project.default_branch)
end
def show
@merge_request = MergeRequestsFinder.new(current_user, project_id: @project.id).execute.opened
.find_by(source_project: @project, source_branch: @ref, target_branch: @repository.root_ref)
......
---
title: Redirect commits to root if no ref is provided (31576)
merge_request: 20738
author: Kia Mei Somabes
type: added
......@@ -83,6 +83,7 @@ scope format: false do
get '/raw/*id', to: 'raw#show', as: :raw
get '/blame/*id', to: 'blame#show', as: :blame
get '/commits', to: 'commits#commits_root', as: :commits_root
get '/commits/*id/signatures', to: 'commits#signatures', as: :signatures
get '/commits/*id', to: 'commits#show', as: :commits
......
......@@ -9,6 +9,18 @@ describe Projects::CommitsController do
project.add_maintainer(user)
end
describe "GET commits_root" do
context "no ref is provided" do
it 'should redirect to the default branch of the project' do
get(:commits_root,
namespace_id: project.namespace,
project_id: project)
expect(response).to redirect_to project_commits_path(project)
end
end
end
describe "GET show" do
render_views
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment