Locking Files Using Git LFS
Posted: Wed Oct 25, 2023 4:30 pm
Hello,
I recently noticed the support for Git LFS in the 5.2.0 version of the Git client and decided to experiment locking the .xpr file (or any file in Git) as suggested in this article:
https://docs.gitlab.com/ee/user/project/file_lock.html
I’m curious to know if there are any reasons why we shouldn’t implement this across all our repos. We’ve tested it and it seems to work well. This could potentially solve our recurring issue of new writers unintentionally committing and pushing the .xpr project file.
Here’s the procedure we followed:
1. Created a .gitattribute file containing the following line and added it to a test repository:
2. Executed the following command to lock the sample.xpr file:
The system prompts for the GitLab username and password:
Now, when another user tries to edit the sample.xpr project file in Oxygen XML Author, they can commit the file, but when attempting a push, they receive a dialog with the message:
“Cannot push. The pre-receive server-side hook declined the operation.” When I tried to push from the git command line, I received the following message:
And for unlocking the files,
Once the file is unlocked, users can push it from the Git Client without any issues. This method allows admins to keep the project file locked and only unlock it when they need to update it.
I would appreciate any insights or suggestions regarding this approach.
Thanks,
Kenneth
I recently noticed the support for Git LFS in the 5.2.0 version of the Git client and decided to experiment locking the .xpr file (or any file in Git) as suggested in this article:
https://docs.gitlab.com/ee/user/project/file_lock.html
I’m curious to know if there are any reasons why we shouldn’t implement this across all our repos. We’ve tested it and it seems to work well. This could potentially solve our recurring issue of new writers unintentionally committing and pushing the .xpr project file.
Here’s the procedure we followed:
1. Created a .gitattribute file containing the following line and added it to a test repository:
Code: Select all
*.xpr lockable
Code: Select all
git lfs lock sample.xpr
Code: Select all
C:\Users\user1\git\repo>git lfs lock sample.xpr
Username for 'https://gitlab.com': user1
Password for 'https://user1@gitlab.com':
Locked sample.xpr
“Cannot push. The pre-receive server-side hook declined the operation.” When I tried to push from the git command line, I received the following message:
Code: Select all
C:\Users\user2\git\repo>git push
Username for 'https://gitlab.com': user2
Password for 'https://user2@gitlab.com':
Enumerating objects: 5, done.
Counting objects: 100% (5/5), done.
Delta compression using up to 8 threads
Compressing objects: 100% (3/3), done.
Writing objects: 100% (3/3), 1.83 KiB | 1.83 MiB/s, done.
Total 3 (delta 1), reused 0 (delta 0), pack-reused 0
remote: GitLab: The path 'sample.xpr' is locked in Git LFS by user1
To https://gitlab.com/repo/test.git
! [remote rejected] branch1 -> branch1 (pre-receive hook declined)
error: failed to push some refs to 'https://gitlab.com/repo/test.git'
- For the user who locked the file, the command is:
Code: Select all
git lfs unlock sample.xpr
- If another user wants to unlock it, they need to use the --force flag:
Code: Select all
C:\Users\user2\git\repo>git lfs unlock sample.xpr --force
Username for 'https://gitlab.com': user2
Password for 'https://user2@gitlab.com':
Unlocked sample.xpr
I would appreciate any insights or suggestions regarding this approach.
Thanks,
Kenneth