2015-11-16 20:31:26 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2016-08-17 22:13:36 +00:00
|
|
|
"os"
|
|
|
|
|
2016-11-15 17:01:18 +00:00
|
|
|
"github.com/git-lfs/git-lfs/lfs"
|
2016-05-23 18:02:27 +00:00
|
|
|
"github.com/spf13/cobra"
|
2015-11-16 20:31:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
forceInstall = false
|
|
|
|
localInstall = false
|
2017-07-11 16:40:01 +00:00
|
|
|
manualInstall = false
|
2016-04-26 06:26:02 +00:00
|
|
|
systemInstall = false
|
2015-11-16 20:31:26 +00:00
|
|
|
skipSmudgeInstall = false
|
2017-01-16 12:39:55 +00:00
|
|
|
skipRepoInstall = false
|
2015-11-16 20:31:26 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func installCommand(cmd *cobra.Command, args []string) {
|
2017-10-18 21:19:21 +00:00
|
|
|
if err := cmdInstallOptions().Install(); err != nil {
|
2017-10-17 16:24:29 +00:00
|
|
|
Print("WARNING: %s", err.Error())
|
|
|
|
Print("Run `git lfs install --force` to reset git config.")
|
|
|
|
return
|
2015-11-16 20:31:26 +00:00
|
|
|
}
|
|
|
|
|
2017-10-19 00:25:41 +00:00
|
|
|
if !skipRepoInstall && (localInstall || cfg.InRepo()) {
|
2015-11-16 20:31:26 +00:00
|
|
|
installHooksCommand(cmd, args)
|
|
|
|
}
|
|
|
|
|
|
|
|
Print("Git LFS initialized.")
|
|
|
|
}
|
|
|
|
|
2017-10-18 21:19:21 +00:00
|
|
|
func cmdInstallOptions() *lfs.FilterOptions {
|
2017-01-24 23:33:29 +00:00
|
|
|
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.")
|
|
|
|
}
|
2017-10-18 21:19:21 +00:00
|
|
|
|
|
|
|
return &lfs.FilterOptions{
|
2017-10-25 22:12:29 +00:00
|
|
|
GitConfig: cfg.GitConfig(),
|
2017-10-18 21:19:21 +00:00
|
|
|
Force: forceInstall,
|
|
|
|
Local: localInstall,
|
|
|
|
System: systemInstall,
|
|
|
|
SkipSmudge: skipSmudgeInstall,
|
2017-01-24 23:33:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-11-16 20:31:26 +00:00
|
|
|
func installHooksCommand(cmd *cobra.Command, args []string) {
|
|
|
|
updateForce = forceInstall
|
2017-07-11 16:40:01 +00:00
|
|
|
|
|
|
|
// 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
|
|
|
|
|
2015-11-16 20:31:26 +00:00
|
|
|
updateCommand(cmd, args)
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2016-09-01 16:09:38 +00:00
|
|
|
RegisterCommand("install", installCommand, func(cmd *cobra.Command) {
|
2016-08-10 15:33:25 +00:00
|
|
|
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.")
|
2016-08-17 21:16:10 +00:00
|
|
|
cmd.Flags().BoolVarP(&systemInstall, "system", "", false, "Set the Git LFS config in system-wide scope.")
|
2016-08-10 15:33:25 +00:00
|
|
|
cmd.Flags().BoolVarP(&skipSmudgeInstall, "skip-smudge", "s", false, "Skip automatic downloading of objects on clone or pull.")
|
2017-01-16 12:39:55 +00:00
|
|
|
cmd.Flags().BoolVarP(&skipRepoInstall, "skip-repo", "", false, "Skip repo setup, just install global filters.")
|
2017-07-11 16:40:01 +00:00
|
|
|
cmd.Flags().BoolVarP(&manualInstall, "manual", "m", false, "Print instructions for manual install.")
|
2016-09-01 14:46:26 +00:00
|
|
|
cmd.AddCommand(NewCommand("hooks", installHooksCommand))
|
2016-08-10 15:33:25 +00:00
|
|
|
})
|
2015-11-16 20:31:26 +00:00
|
|
|
}
|