2014-09-02 18:07:02 +05:30
|
|
|
# Controller for viewing a repository's file structure
|
2015-04-26 12:48:37 +05:30
|
|
|
class Projects::TreeController < Projects::ApplicationController
|
|
|
|
include ExtractsPath
|
2016-01-14 18:37:52 +05:30
|
|
|
include CreatesCommit
|
2015-10-24 18:46:33 +05:30
|
|
|
include ActionView::Helpers::SanitizeHelper
|
2015-04-26 12:48:37 +05:30
|
|
|
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :require_non_empty_project, except: [:new, :create]
|
|
|
|
before_action :assign_ref_vars
|
2015-10-24 18:46:33 +05:30
|
|
|
before_action :assign_dir_vars, only: [:create_dir]
|
2015-09-11 14:41:01 +05:30
|
|
|
before_action :authorize_download_code!
|
2016-01-14 18:37:52 +05:30
|
|
|
before_action :authorize_edit_tree!, only: [:create_dir]
|
2014-09-02 18:07:02 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
def show
|
2015-10-24 18:46:33 +05:30
|
|
|
return render_404 unless @repository.commit(@ref)
|
2015-09-11 14:41:01 +05:30
|
|
|
|
2014-09-02 18:07:02 +05:30
|
|
|
if tree.entries.empty?
|
|
|
|
if @repository.blob_at(@commit.id, @path)
|
2017-08-17 22:00:37 +05:30
|
|
|
return redirect_to(
|
2017-09-10 17:25:29 +05:30
|
|
|
project_blob_path(@project,
|
2015-04-26 12:48:37 +05:30
|
|
|
File.join(@ref, @path))
|
2017-08-17 22:00:37 +05:30
|
|
|
)
|
2015-09-11 14:41:01 +05:30
|
|
|
elsif @path.present?
|
2015-10-24 18:46:33 +05:30
|
|
|
return render_404
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
respond_to do |format|
|
2017-09-10 17:25:29 +05:30
|
|
|
format.html do
|
2018-03-17 18:26:18 +05:30
|
|
|
lfs_blob_ids
|
2017-09-10 17:25:29 +05:30
|
|
|
@last_commit = @repository.last_commit_for_path(@commit.id, @tree.path) || @commit
|
|
|
|
end
|
|
|
|
|
|
|
|
format.js do
|
|
|
|
# Disable cache so browser history works
|
|
|
|
no_cache_headers
|
|
|
|
end
|
|
|
|
|
|
|
|
format.json do
|
2018-03-27 19:54:05 +05:30
|
|
|
page_title @path.presence || _("Files"), @ref, @project.full_name
|
2018-03-17 18:26:18 +05:30
|
|
|
|
|
|
|
# n+1: https://gitlab.com/gitlab-org/gitlab-ce/issues/38261
|
|
|
|
Gitlab::GitalyClient.allow_n_plus_1_calls do
|
|
|
|
render json: TreeSerializer.new(project: @project, repository: @repository, ref: @ref).represent(@tree)
|
|
|
|
end
|
2017-09-10 17:25:29 +05:30
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|
|
|
|
end
|
2015-10-24 18:46:33 +05:30
|
|
|
|
|
|
|
def create_dir
|
|
|
|
return render_404 unless @commit_params.values.all?
|
|
|
|
|
2016-01-14 18:37:52 +05:30
|
|
|
create_commit(Files::CreateDirService, success_notice: "The directory has been successfully created.",
|
2017-09-10 17:25:29 +05:30
|
|
|
success_path: project_tree_path(@project, File.join(@branch_name, @dir_name)),
|
|
|
|
failure_path: project_tree_path(@project, @ref))
|
2015-10-24 18:46:33 +05:30
|
|
|
end
|
|
|
|
|
2015-11-26 14:37:03 +05:30
|
|
|
private
|
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
def assign_dir_vars
|
2017-08-17 22:00:37 +05:30
|
|
|
@branch_name = params[:branch_name]
|
2016-01-14 18:37:52 +05:30
|
|
|
|
2015-10-24 18:46:33 +05:30
|
|
|
@dir_name = File.join(@path, params[:dir_name])
|
|
|
|
@commit_params = {
|
|
|
|
file_path: @dir_name,
|
2017-09-10 17:25:29 +05:30
|
|
|
commit_message: params[:commit_message]
|
2015-10-24 18:46:33 +05:30
|
|
|
}
|
|
|
|
end
|
2014-09-02 18:07:02 +05:30
|
|
|
end
|