Step 1: Version Control for Snippets: Create repository model for snippets (MVP)
Important: All the new functionality must be implemented behind the feature flag :version_snippets
. Besides, it has to be scoped for projects. Therefore, instead of checking if the feature flag is enabled or not (Feature.enabled?(:version_snippets)
), we will check if the feature flag is enabled for specific projects (Feature.enabled?(:version_snippets, project)
). This way, for testing purposes, we can enable the feature flag on the project gitlab-org/gitlab
for example, instead of enabling it globally.
In order to implement the new functionality for versioned control snippets, we need several models to be created. One of the would be the Snippets::Repository
.
This repository will be very similar to DesignManagement::Repository
. The main thing different is that we're not going to enable LFS be default and that every snippet get their own repository.
The new snippet repositories will be stored in a different hashed directory than the project, wiki, and design management repository. Nevertheless, we need to scope them somehow because compare to the other types of repositories, we can have several snippet repositories in the same place as the other repositories.
There are two options:
- create a new folder for all snippet repositories (
/hashed_repository_dir/snippets/
). Inside we will save every snippet repo. use a suffix that identifies the snippet that the repository belongs to:/hashed_repository_dir/<repository_hash>.snippet.<snippet_id>.git
I'm not sure which option would be better but, at the moment, I prefer option 2 because it's simpler for cloning and pushing routes. Nevertheless, option 2 has the benefit of allowing hashing the snippets directory in the future and also perform global operations like delete all snippet repositories when the project is deleted.
We have to create as well a new method in the project model:
def snippet_repository(snippet_id)
@snippet_repositories[snippet_id] ||= Snippets::Repository(self, snippet_id)
end
Then, in the snippet we can create:
def repository
project&.snippet_repository(self.id)
end
The new logic for snippets should live (for now) inside the ProjectSnippet
model. Nevertheless, I think we will have scenarios and views where we will use the same code indistinctively for project and personal snippets. Therefore, it makes sense if we add the new code to the Snippet
model.
We have to create a new TYPE
for this new kind of repository in lib/gitlab/gl_repository.rb
.
This page may contain information related to upcoming products, features and functionality. It is important to note that the information presented is for informational purposes only, so please do not rely on the information for purchasing or planning purposes. Just like with all projects, the items mentioned on the page are subject to change or delay, and the development, release, and timing of any products, features, or functionality remain at the sole discretion of GitLab Inc.