2015-11-16 20:31:26 +00:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
2016-08-17 22:13:36 +00:00
|
|
|
"os"
|
|
|
|
|
2015-11-16 20:31:26 +00:00
|
|
|
"github.com/github/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
|
2016-04-26 06:26:02 +00:00
|
|
|
systemInstall = false
|
2015-11-16 20:31:26 +00:00
|
|
|
skipSmudgeInstall = false
|
|
|
|
)
|
|
|
|
|
|
|
|
func installCommand(cmd *cobra.Command, args []string) {
|
2016-08-17 22:13:36 +00:00
|
|
|
requireGitVersion()
|
|
|
|
|
2015-11-16 20:31:26 +00:00
|
|
|
if localInstall {
|
|
|
|
requireInRepo()
|
|
|
|
}
|
|
|
|
|
2016-04-26 06:26:02 +00:00
|
|
|
if systemInstall && os.Geteuid() != 0 {
|
|
|
|
Print("WARNING: current user is not root/admin, system install is likely to fail.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if localInstall && systemInstall {
|
|
|
|
Exit("Only one of --local and --system options can be specified.")
|
|
|
|
}
|
|
|
|
|
|
|
|
opt := lfs.InstallOptions{Force: forceInstall, Local: localInstall, System: systemInstall}
|
2015-11-16 20:31:26 +00:00
|
|
|
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 {
|
|
|
|
Error(err.Error())
|
|
|
|
Exit("Run `git lfs install --force` to reset git config.")
|
|
|
|
}
|
|
|
|
|
|
|
|
if localInstall || lfs.InRepo() {
|
|
|
|
installHooksCommand(cmd, args)
|
|
|
|
}
|
|
|
|
|
|
|
|
Print("Git LFS initialized.")
|
|
|
|
}
|
|
|
|
|
|
|
|
func installHooksCommand(cmd *cobra.Command, args []string) {
|
|
|
|
updateForce = forceInstall
|
|
|
|
updateCommand(cmd, args)
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
2016-08-10 15:33:25 +00:00
|
|
|
RegisterSubcommand(func() *cobra.Command {
|
|
|
|
cmd := &cobra.Command{
|
|
|
|
Use: "install",
|
|
|
|
Run: installCommand,
|
|
|
|
}
|
|
|
|
|
|
|
|
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.")
|
|
|
|
cmd.AddCommand(&cobra.Command{
|
|
|
|
Use: "hooks",
|
|
|
|
Run: installHooksCommand,
|
|
|
|
})
|
|
|
|
return cmd
|
|
|
|
})
|
2015-11-16 20:31:26 +00:00
|
|
|
}
|