From 11d56a1551e2b5d57656433f912a4dec1cee3008 Mon Sep 17 00:00:00 2001 From: Kia Mei Somabes Date: Fri, 20 Jul 2018 16:13:29 +0800 Subject: [PATCH] Redirect commits to root_ref if no ref is provided --- app/controllers/application_controller.rb | 4 ++++ .../unreleased/31576-redirect-commits-to-root-if-no-ref.yml | 5 +++++ config/routes/repository.rb | 1 + 3 files changed, 10 insertions(+) create mode 100644 changelogs/unreleased/31576-redirect-commits-to-root-if-no-ref.yml diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 21cc6dfdd16..13eedba54a5 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -63,6 +63,10 @@ class ApplicationController < ActionController::Base render_503 end + def redirect_commits_root + redirect_to :controller => 'commits', :action => 'show', :id => @repository.root_ref + end + def redirect_back_or_default(default: root_path, options: {}) redirect_to request.referer.present? ? :back : default, options end diff --git a/changelogs/unreleased/31576-redirect-commits-to-root-if-no-ref.yml b/changelogs/unreleased/31576-redirect-commits-to-root-if-no-ref.yml new file mode 100644 index 00000000000..d117e9ad3d7 --- /dev/null +++ b/changelogs/unreleased/31576-redirect-commits-to-root-if-no-ref.yml @@ -0,0 +1,5 @@ +--- +title: Redirect commits to root if no ref is provided (31576) +merge_request: +author: Kia Mei Somabes +type: added diff --git a/config/routes/repository.rb b/config/routes/repository.rb index e2bf8d6a7ff..87101a69bba 100644 --- a/config/routes/repository.rb +++ b/config/routes/repository.rb @@ -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: 'application#redirect_commits_root', as: :commits_root get '/commits/*id/signatures', to: 'commits#signatures', as: :signatures get '/commits/*id', to: 'commits#show', as: :commits