diff options
author | Toon Claes <toon@gitlab.com> | 2018-08-02 13:30:24 +0200 |
---|---|---|
committer | Toon Claes <toon@gitlab.com> | 2018-08-20 16:39:32 +0200 |
commit | f4f321b9023d5aba76541f442fe1061d70186f27 (patch) | |
tree | 3ad1567bde2e55c9e3b6a0ff0dba1520c890a36b | |
parent | 7c9983c721ab47d25c9d437035e04b385e8af7c9 (diff) | |
download | gitlab-ce-f4f321b9023d5aba76541f442fe1061d70186f27.tar.gz |
Clean up LFS objects when creating fork relation
A forked project stores its LFS objects in the `forked_from_project`.
So the LFS objects become inaccessible, and therefore delete them from
the database so they'll get cleaned up.
To be refactored when implementing
https://gitlab.com/gitlab-org/gitlab-ce/issues/39769
-rw-r--r-- | app/services/projects/fork_service.rb | 8 | ||||
-rw-r--r-- | doc/api/projects.md | 5 | ||||
-rw-r--r-- | spec/services/projects/fork_service_spec.rb | 8 |
3 files changed, 21 insertions, 0 deletions
diff --git a/app/services/projects/fork_service.rb b/app/services/projects/fork_service.rb index 33ad2120a75..cbbb88a9410 100644 --- a/app/services/projects/fork_service.rb +++ b/app/services/projects/fork_service.rb @@ -17,6 +17,14 @@ module Projects link_fork_network(fork_to_project) + # A forked project stores its LFS objects in the `forked_from_project`. + # So the LFS objects become inaccessible, and therefore delete them from + # the database so they'll get cleaned up. + # + # TODO: refactor this to get the correct lfs objects when implementing + # https://gitlab.com/gitlab-org/gitlab-ce/issues/39769 + fork_to_project.lfs_objects_projects.delete_all + fork_to_project end diff --git a/doc/api/projects.md b/doc/api/projects.md index 448562b8dec..0936ff52dae 100644 --- a/doc/api/projects.md +++ b/doc/api/projects.md @@ -1419,6 +1419,11 @@ Allows modification of the forked relationship between existing projects. Availa ### Create a forked from/to relation between existing projects +CAUTION: **Warning:** +This will destroy the LFS objects stored in the fork. +So to retain the LFS objects, make sure you've pulled them **before** creating the fork relation, +and push them again **after** creating the fork relation. + ``` POST /projects/:id/fork/:forked_from_id ``` diff --git a/spec/services/projects/fork_service_spec.rb b/spec/services/projects/fork_service_spec.rb index f89f9b54f53..947cb61038d 100644 --- a/spec/services/projects/fork_service_spec.rb +++ b/spec/services/projects/fork_service_spec.rb @@ -264,6 +264,14 @@ describe Projects::ForkService do expect(fork_from_project.forks_count).to eq(1) end + + it 'leaves no LFS objects dangling' do + create(:lfs_objects_project, project: fork_to_project) + + expect { subject.execute(fork_to_project) } + .to change { fork_to_project.lfs_objects_projects.count } + .to(0) + end end end end |