(cmd *cobra.Command, args []string)
| 19 | ) |
| 20 | |
| 21 | func 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 | |
| 75 | type lockData struct { |
| 76 | rootDir string |
nothing calls this directly
no test coverage detected