summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Van Landuyt <bob@vanlanduyt.co>2017-10-17 16:33:30 +0200
committerBob Van Landuyt <bob@vanlanduyt.co>2017-10-17 16:46:07 +0200
commit2c0b677604e438b9bf608e6ea17b47e5640b4700 (patch)
tree5b2fd56ea9796af05980ad9ea754f16cf41e53f7
parentf69b54682fc1770a73c528032b1a86f3e7d547a1 (diff)
downloadgitlab-ce-2c0b677604e438b9bf608e6ea17b47e5640b4700.tar.gz
Fix errors when deleting a forked project
The problem would occur when the `ForkedProjectLink` was deleted, but the `ForkNetworkMember` was not. The delete would be rolled back and retried. But the error would not be saved because `Project#forked?` would still be true, because the `ForkNetworkMember` exists. But the `Project#forked_project_link` would be `nil`. So the validation for the visibility level would fail.
-rw-r--r--app/models/project.rb2
-rw-r--r--app/services/projects/unlink_fork_service.rb2
-rw-r--r--changelogs/unreleased/bvl-fix-deleting-forked-projects.yml5
-rw-r--r--spec/services/projects/destroy_service_spec.rb17
4 files changed, 24 insertions, 2 deletions
diff --git a/app/models/project.rb b/app/models/project.rb
index 6e1cf9e31ee..4689b588906 100644
--- a/app/models/project.rb
+++ b/app/models/project.rb
@@ -1272,7 +1272,7 @@ class Project < ActiveRecord::Base
# self.forked_from_project will be nil before the project is saved, so
# we need to go through the relation
- original_project = forked_project_link.forked_from_project
+ original_project = forked_project_link&.forked_from_project
return true unless original_project
level <= original_project.visibility_level
diff --git a/app/services/projects/unlink_fork_service.rb b/app/services/projects/unlink_fork_service.rb
index abe414d0c05..2b82e5732e4 100644
--- a/app/services/projects/unlink_fork_service.rb
+++ b/app/services/projects/unlink_fork_service.rb
@@ -15,8 +15,8 @@ module Projects
refresh_forks_count(@project.forked_from_project)
- @project.forked_project_link.destroy
@project.fork_network_member.destroy
+ @project.forked_project_link.destroy
end
def refresh_forks_count(project)
diff --git a/changelogs/unreleased/bvl-fix-deleting-forked-projects.yml b/changelogs/unreleased/bvl-fix-deleting-forked-projects.yml
new file mode 100644
index 00000000000..95f56facc4b
--- /dev/null
+++ b/changelogs/unreleased/bvl-fix-deleting-forked-projects.yml
@@ -0,0 +1,5 @@
+---
+title: Fix error when updating a forked project with deleted `ForkedProjectLink`
+merge_request: 14916
+author:
+type: fixed
diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb
index c90bad46295..0bec2054f50 100644
--- a/spec/services/projects/destroy_service_spec.rb
+++ b/spec/services/projects/destroy_service_spec.rb
@@ -1,6 +1,8 @@
require 'spec_helper'
describe Projects::DestroyService do
+ include ProjectForksHelper
+
let!(:user) { create(:user) }
let!(:project) { create(:project, :repository, namespace: user.namespace) }
let!(:path) { project.repository.path_to_repo }
@@ -212,6 +214,21 @@ describe Projects::DestroyService do
end
end
+ context 'for a forked project with LFS objects' do
+ let(:forked_project) { fork_project(project, user) }
+
+ before do
+ project.lfs_objects << create(:lfs_object)
+ forked_project.forked_project_link.destroy
+ forked_project.reload
+ end
+
+ it 'destroys the fork' do
+ expect { destroy_project(forked_project, user) }
+ .not_to raise_error
+ end
+ end
+
context 'as the root of a fork network' do
let!(:fork_network) { create(:fork_network, root_project: project) }