Skip to content

Add MR mergeability check for locked LFS files

Joe Woodward requested to merge feat/428247-locked-files-mergeability-check into master

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

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

image

Passing

image

How to set up and validate locally

  1. 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
  2. Copy the path to the project from the URL e.g. "gitlab-org/gitlab"
  3. In the rails console ensure the project has no LfsFileLocks Project.find_by_full_path('my/path').lfs_file_locks.destroy_all
  4. Enable the FF Feature.enable(:locked_lfs_files_mergeability_check)
  5. 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
  6. 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 return Locked test.txt
  7. 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">
  8. 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
  9. 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
  10. Create the MR. The widget should pass as this is your locked file
  11. Now unlock the file git lfs unlock test.txt
  12. 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 it export GIT_SSH_COMMAND="ssh -i /path/to/git-private-access-key")
  13. 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
  14. Now go back to the MR and reload the page. The MR should now be blocked.
Edited by Ash McKenzie

Merge request reports

Loading