postCommitCommand is run through Git's post-commit hook. The hook passes no arguments. This hook checks that files which are lockable and not locked are made read-only, optimising that based on what was added / modified in the commit. This is mainly to catch added files, since modified files should
(cmd *cobra.Command, args []string)
| 17 | // locked. If we didn't do this, any added files would remain read/write on disk |
| 18 | // even without a lock unless something else checked. |
| 19 | func postCommitCommand(cmd *cobra.Command, args []string) { |
| 20 | |
| 21 | // Skip entire hook if lockable read only feature is disabled |
| 22 | if !cfg.SetLockableFilesReadOnly() { |
| 23 | os.Exit(0) |
| 24 | } |
| 25 | |
| 26 | requireGitVersion() |
| 27 | |
| 28 | lockClient := newLockClient() |
| 29 | |
| 30 | // Skip this hook if no lockable patterns have been configured |
| 31 | if len(lockClient.GetLockablePatterns()) == 0 { |
| 32 | os.Exit(0) |
| 33 | } |
| 34 | |
| 35 | tracerx.Printf("post-commit: checking file write flags at HEAD") |
| 36 | // We can speed things up by looking at what changed in |
| 37 | // HEAD, and only checking those lockable files |
| 38 | files, err := git.GetFilesChanged("HEAD", "") |
| 39 | |
| 40 | if err != nil { |
| 41 | LoggedError(err, tr.Tr.Get("Warning: post-commit failed: %v", err)) |
| 42 | os.Exit(1) |
| 43 | } |
| 44 | tracerx.Printf("post-commit: checking write flags on %v", files) |
| 45 | err = lockClient.FixLockableFileWriteFlags(files) |
| 46 | if err != nil { |
| 47 | LoggedError(err, tr.Tr.Get("Warning: post-commit locked file check failed: %v", err)) |
| 48 | } |
| 49 | |
| 50 | } |
| 51 | |
| 52 | func init() { |
| 53 | RegisterCommand("post-commit", postCommitCommand, nil) |
nothing calls this directly
no test coverage detected