diff options
Diffstat (limited to 'app/controllers')
-rw-r--r-- | app/controllers/projects/blob_controller.rb | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/app/controllers/projects/blob_controller.rb b/app/controllers/projects/blob_controller.rb index 92d26a13da9..fb2cfdedd9b 100644 --- a/app/controllers/projects/blob_controller.rb +++ b/app/controllers/projects/blob_controller.rb @@ -83,7 +83,7 @@ class Projects::BlobController < Projects::ApplicationController def destroy create_commit(Files::DeleteService, success_notice: "The file has been successfully deleted.", - success_path: -> { project_tree_path(@project, @branch_name) }, + success_path: -> { after_delete_path }, failure_view: :show, failure_path: project_blob_path(@project, @id)) end @@ -191,6 +191,15 @@ class Projects::BlobController < Projects::ApplicationController end # rubocop: enable CodeReuse/ActiveRecord + def after_delete_path + branch = BranchesFinder.new(@repository, search: @ref).execute.first + if @repository.tree(branch.target, tree_path).entries.empty? + project_tree_path(@project, @ref) + else + project_tree_path(@project, File.join(@ref, tree_path)) + end + end + def editor_variables @branch_name = params[:branch_name] @@ -255,9 +264,6 @@ class Projects::BlobController < Projects::ApplicationController def show_json set_last_commit_sha - path_segments = @path.split('/') - path_segments.pop - tree_path = path_segments.join('/') json = { id: @blob.id, @@ -283,4 +289,8 @@ class Projects::BlobController < Projects::ApplicationController render json: json end + + def tree_path + @path.rpartition('/').first + end end |