From 9f53a384dbfd5c23a3f4ee2a249632cc90d4a403 Mon Sep 17 00:00:00 2001 From: Alexander Machehin Date: Thu, 5 Mar 2015 10:57:28 +0500 Subject: [PATCH] [#369] dont redirect to project if get an ajax request --- app/controllers/projects/git/trees_controller.rb | 10 +++++++++- app/views/projects/git/trees/show.json.jbuilder | 1 + 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/app/controllers/projects/git/trees_controller.rb b/app/controllers/projects/git/trees_controller.rb index 4130a44da..99e0f69f3 100644 --- a/app/controllers/projects/git/trees_controller.rb +++ b/app/controllers/projects/git/trees_controller.rb @@ -1,6 +1,6 @@ class Projects::Git::TreesController < Projects::Git::BaseController - before_filter -> {redirect_to @project if params[:treeish] == @project.resolve_default_branch and params[:path].blank?}, only: :show + before_filter -> { redirect_to_project }, only: :show skip_before_filter :set_branch_and_tree, :set_treeish_and_path, only: :archive before_filter -> { raise Grit::NoSuchPathError if params[:treeish] != @branch.try(:name) }, only: [:branch, :destroy] @@ -79,4 +79,12 @@ class Projects::Git::TreesController < Projects::Git::BaseController end end + protected + + def redirect_to_project + if params[:treeish] == @project.resolve_default_branch && params[:path].blank? && !request.xhr? + redirect_to @project + end + end + end diff --git a/app/views/projects/git/trees/show.json.jbuilder b/app/views/projects/git/trees/show.json.jbuilder index 4d36e1d0b..3df7c30d3 100644 --- a/app/views/projects/git/trees/show.json.jbuilder +++ b/app/views/projects/git/trees/show.json.jbuilder @@ -10,6 +10,7 @@ if params[:info] == 'true' else page = params[:page].to_i + page = page < 1 ? 0 : page json.tree do json.array! @project.tree_info(@tree, @treeish, @path, page).each do |node, node_path, commit|