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