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
This commit is contained in:
Toon Claes 2018-08-02 13:30:24 +02:00
parent 7c9983c721
commit f4f321b902
3 changed files with 21 additions and 0 deletions

View file

@ -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

View file

@ -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
```

View file

@ -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