locking: add pre-commit hook to detect inappropriately modified files#1816
locking: add pre-commit hook to detect inappropriately modified files#1816ttaylorr wants to merge 8 commits intolocking-pre-pushfrom
Conversation
sinbad
left a comment
There was a problem hiding this comment.
I could make some other comments here, such as it not supporting cases where you don't commit from staging, but the major, I think insurmountable, problem with this approach is that it makes committing require remote access. This would break a fundamental principle of git that you can work offline if you need to, until push/pull.
I have work ongoing (backported from my earlier PR) for making lockable files read-only in post-checkout which will hopefully discourage people from editing files that should be locked without locking them first. Yes, locking itself requires remote access but the idea is that you do that first before going offline and can then commit as much as you want offline. If you forget to lock beforehand you can always take a risk by making the file read/write locally while offline and hope that no-one else does (will need resolving at push time; this will be more than just checking current locks)
|
I think that's a great point. Let's hold off on this and see if it's actually needed in real use. |
I agree, let's close for now 👍 |
This pull-request adds a
pre-commithook that detects and prevents commits changing locked files owned by someone other than the current committer.This hook looks at the currently staged files when it is called (before the user is told to edit the
.git/COMMIT_EDITMSG) and inspects each one of them to see if they are locked by someone other than the current committer. The current committer is used since it is the latest and most accurate information determinable about who will commit the file.Here's a breakdown of the changes:
pre-commithookpre-commithookpre-commitcommandSome things that we should investigate before merging:
filter-branch,rebaseorcommit --amend?git.StagedFiles(), to better handle a case where there are many staged files?/cc @git-lfs/core