BigW Consortium Gitlab

tree_controller.rb 820 Bytes
Newer Older
1
# Controller for viewing a repository's file structure
2 3 4
class Projects::TreeController < Projects::ApplicationController
  include ExtractsPath

5 6 7
  before_action :require_non_empty_project, except: [:new, :create]
  before_action :assign_ref_vars
  before_action :authorize_download_code!
8

9
  def show
10 11
    return not_found! unless @repository.commit(@ref)

12 13
    if tree.entries.empty?
      if @repository.blob_at(@commit.id, @path)
Vinnie Okada committed
14 15 16 17
        redirect_to(
          namespace_project_blob_path(@project.namespace, @project,
                                      File.join(@ref, @path))
        ) and return
18
      elsif @path.present?
19 20 21
        return not_found!
      end
    end
22

23 24 25 26 27 28 29
    respond_to do |format|
      format.html
      # Disable cache so browser history works
      format.js { no_cache_headers }
    end
  end
end