forked from git-lfs/git-lfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
command_install.go
89 lines (73 loc) · 2.7 KB
/
command_install.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
package commands
import (
"os"
"github.com/git-lfs/git-lfs/lfs"
"github.com/git-lfs/git-lfs/localstorage"
"github.com/spf13/cobra"
)
var (
forceInstall = false
localInstall = false
manualInstall = false
systemInstall = false
skipSmudgeInstall = false
skipRepoInstall = false
)
func installCommand(cmd *cobra.Command, args []string) {
opt := cmdInstallOptions()
if skipSmudgeInstall {
// assume the user is changing their smudge mode, so enable force implicitly
opt.Force = true
}
if err := lfs.InstallFilters(opt, skipSmudgeInstall); err != nil {
Print("WARNING: %s", err.Error())
Print("Run `git lfs install --force` to reset git config.")
return
}
if !skipRepoInstall && (localInstall || lfs.InRepo()) {
localstorage.InitStorageOrFail()
installHooksCommand(cmd, args)
}
Print("Git LFS initialized.")
}
func cmdInstallOptions() lfs.InstallOptions {
requireGitVersion()
if localInstall {
requireInRepo()
}
if localInstall && systemInstall {
Exit("Only one of --local and --system options can be specified.")
}
if systemInstall && os.Geteuid() != 0 {
Print("WARNING: current user is not root/admin, system install is likely to fail.")
}
return lfs.InstallOptions{
Force: forceInstall,
Local: localInstall,
System: systemInstall,
}
}
func installHooksCommand(cmd *cobra.Command, args []string) {
updateForce = forceInstall
// TODO(@ttaylorr): this is a hack since the `git-lfs-install(1)` calls
// into the function that implements `git-lfs-update(1)`. Given that,
// there is no way to pass flags into that function, other than
// hijacking the flags that `git-lfs-update(1)` already owns.
//
// At a later date, extract `git-lfs-update(1)`-related logic into its
// own function, and translate this flag as a boolean argument to it.
updateManual = manualInstall
updateCommand(cmd, args)
}
func init() {
RegisterCommand("install", installCommand, func(cmd *cobra.Command) {
cmd.Flags().BoolVarP(&forceInstall, "force", "f", false, "Set the Git LFS global config, overwriting previous values.")
cmd.Flags().BoolVarP(&localInstall, "local", "l", false, "Set the Git LFS config for the local Git repository only.")
cmd.Flags().BoolVarP(&systemInstall, "system", "", false, "Set the Git LFS config in system-wide scope.")
cmd.Flags().BoolVarP(&skipSmudgeInstall, "skip-smudge", "s", false, "Skip automatic downloading of objects on clone or pull.")
cmd.Flags().BoolVarP(&skipRepoInstall, "skip-repo", "", false, "Skip repo setup, just install global filters.")
cmd.Flags().BoolVarP(&manualInstall, "manual", "m", false, "Print instructions for manual install.")
cmd.AddCommand(NewCommand("hooks", installHooksCommand))
cmd.PreRun = setupLocalStorage
})
}