Add MR mergeability check for locked LFS files
What does this MR do and why?
Add MR mergeability check for locked LFS files
This change introduces a new check. This check will prevent merging MRs which include locked files.
We also have a check which runs when a user pushes code that prevents pushing files that are locked by other users.
This change will allow us to enable the fix for Git LFS lock in GitLab prevents pushes of new f... (#23625 - closed)
Related
- Spike: Introduce new mergeability check to ensu... (#428247 - closed)
- [Feature flag] Rollout of `locked_lfs_files_mer... (#474485 - closed)
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Screenshots or screen recordings
Screenshots are required for UI changes, and strongly recommended for all other merge requests.
### Failing
Passing
How to set up and validate locally
- Go to a project in GDK and ensure LFS is enabled https://docs.gitlab.com/ee/topics/git/lfs/#enable-or-disable-git-lfs-for-a-project
- Copy the path to the project from the URL e.g. "gitlab-org/gitlab"
- In the rails console ensure the project has no LfsFileLocks
Project.find_by_full_path('my/path').lfs_file_locks.destroy_all
- Enable the FF
Feature.enable(:locked_lfs_files_mergeability_check)
- Mark a type (can use
.txt
, doesn't need to be a binary) of file as lockable in LFS via the shell https://docs.gitlab.com/ee/user/project/file_lock.html#configure-exclusive-file-locks - In the project you are working on, lock a file that you will push e.g.
test.txt
->git lfs lock test.txt
. This should returnLocked test.txt
- In the console verify that there is a new
LfsFileLock
LfsFileLock.last
should be similar to=> #<LfsFileLock:0x0000000163975dd8 id: 14, project_id: 21, user_id: 2, created_at: Mon, 29 Jul 2024 11:26:18.089282000 UTC +00:00, path: "test.txt">
- In a new branch well create and push the file
git checkout -b test-feature && touch test.txt && git add . && git commit -m 'test feature' && git push origin test-feature
- In the response, click the link to create the merge request e.g.
remote: http://gdk.test:3000/playground/lfslockissue/-/merge_requests/new?merge_request%5Bsource_branch%5D=test-feature
- Create the MR. The widget should pass as this is your locked file
- Now unlock the file
git lfs unlock test.txt
- Lock it with a different user. (If you haven't set up an alternate user yet you'll need to generate a new ssh key, upload it to one of the other users in the project and then prepend your shell commands with
GIT_SSH_COMMAND="ssh -i /path/to/your/private/key"
or in a new terminal set it for the entire session by exporting itexport GIT_SSH_COMMAND="ssh -i /path/to/git-private-access-key"
) - Now verify that the LfsFileLock exists for the other user
LfsFileLock.last
should be similar to=> #<LfsFileLock:0x0000000163975dd8 id: 14, project_id: 21, user_id: 5, created_at: Mon, 29 Jul 2024 11:26:18.089282000 UTC +00:00, path: "test.txt">
(the user_id must be different to the one in step 7 - Now go back to the MR and reload the page. The MR should now be blocked.
Edited by Ash McKenzie