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

Function lockCommand

commands/command_lock.go:21–73  ·  view source on GitHub ↗
(cmd *cobra.Command, args []string)

Source from the content-addressed store, hash-verified

19)
20
21func lockCommand(cmd *cobra.Command, args []string) {
22 if len(lockRemote) > 0 {
23 cfg.SetRemote(lockRemote)
24 }
25
26 lockData, err := computeLockData()
27 if err != nil {
28 ExitWithError(err)
29 }
30
31 refUpdate := git.NewRefUpdate(cfg.Git, cfg.PushRemote(), cfg.CurrentRef(), nil)
32 lockClient := newLockClient()
33 lockClient.RemoteRef = refUpdate.RemoteRef()
34 defer lockClient.Close()
35
36 success := true
37 locks := make([]locking.Lock, 0, len(args))
38 for _, path := range args {
39 path, err := lockPath(lockData, path)
40 if err != nil {
41 Error(err.Error())
42 success = false
43 continue
44 }
45
46 lock, err := lockClient.LockFile(path)
47 if err != nil {
48 Error(tr.Tr.Get("Locking %s failed: %v", path, errors.Cause(err)))
49 success = false
50 continue
51 }
52
53 locks = append(locks, lock)
54
55 if locksCmdFlags.JSON {
56 continue
57 }
58
59 Print(tr.Tr.Get("Locked %s", path))
60 }
61
62 if locksCmdFlags.JSON {
63 if err := json.NewEncoder(os.Stdout).Encode(locks); err != nil {
64 Error(err.Error())
65 success = false
66 }
67 }
68
69 if !success {
70 lockClient.Close()
71 os.Exit(2)
72 }
73}
74
75type lockData struct {
76 rootDir string

Callers

nothing calls this directly

Calls 15

RemoteRefMethod · 0.95
NewRefUpdateFunction · 0.92
CauseFunction · 0.92
computeLockDataFunction · 0.85
ExitWithErrorFunction · 0.85
newLockClientFunction · 0.85
lockPathFunction · 0.85
ErrorFunction · 0.85
PrintFunction · 0.85
SetRemoteMethod · 0.80
PushRemoteMethod · 0.80
CurrentRefMethod · 0.80

Tested by

no test coverage detected