MCPcopy
hub / github.com/git-lfs/git-lfs / postCommitCommand

Function postCommitCommand

commands/command_post_commit.go:19–50  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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.
19func 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
52func init() {
53 RegisterCommand("post-commit", postCommitCommand, nil)

Callers

nothing calls this directly

Calls 8

GetFilesChangedFunction · 0.92
requireGitVersionFunction · 0.85
newLockClientFunction · 0.85
LoggedErrorFunction · 0.85
GetLockablePatternsMethod · 0.80
GetMethod · 0.65

Tested by

no test coverage detected