github.com/psexton/git-lfs@v2.1.1-0.20170517224304-289a18b2bc53+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/git-lfs/git-lfs/localstorage"
     8  	"github.com/spf13/cobra"
     9  )
    10  
    11  var (
    12  	forceInstall      = false
    13  	localInstall      = false
    14  	systemInstall     = false
    15  	skipSmudgeInstall = false
    16  	skipRepoInstall   = false
    17  )
    18  
    19  func installCommand(cmd *cobra.Command, args []string) {
    20  	opt := cmdInstallOptions()
    21  	if skipSmudgeInstall {
    22  		// assume the user is changing their smudge mode, so enable force implicitly
    23  		opt.Force = true
    24  	}
    25  
    26  	if err := lfs.InstallFilters(opt, skipSmudgeInstall); err != nil {
    27  		Error(err.Error())
    28  		Exit("Run `git lfs install --force` to reset git config.")
    29  	}
    30  
    31  	if !skipRepoInstall && (localInstall || lfs.InRepo()) {
    32  		localstorage.InitStorageOrFail()
    33  		installHooksCommand(cmd, args)
    34  	}
    35  
    36  	Print("Git LFS initialized.")
    37  }
    38  
    39  func cmdInstallOptions() lfs.InstallOptions {
    40  	requireGitVersion()
    41  
    42  	if localInstall {
    43  		requireInRepo()
    44  	}
    45  
    46  	if localInstall && systemInstall {
    47  		Exit("Only one of --local and --system options can be specified.")
    48  	}
    49  
    50  	if systemInstall && os.Geteuid() != 0 {
    51  		Print("WARNING: current user is not root/admin, system install is likely to fail.")
    52  	}
    53  	return lfs.InstallOptions{
    54  		Force:  forceInstall,
    55  		Local:  localInstall,
    56  		System: systemInstall,
    57  	}
    58  }
    59  
    60  func installHooksCommand(cmd *cobra.Command, args []string) {
    61  	updateForce = forceInstall
    62  	updateCommand(cmd, args)
    63  }
    64  
    65  func init() {
    66  	RegisterCommand("install", installCommand, func(cmd *cobra.Command) {
    67  		cmd.Flags().BoolVarP(&forceInstall, "force", "f", false, "Set the Git LFS global config, overwriting previous values.")
    68  		cmd.Flags().BoolVarP(&localInstall, "local", "l", false, "Set the Git LFS config for the local Git repository only.")
    69  		cmd.Flags().BoolVarP(&systemInstall, "system", "", false, "Set the Git LFS config in system-wide scope.")
    70  		cmd.Flags().BoolVarP(&skipSmudgeInstall, "skip-smudge", "s", false, "Skip automatic downloading of objects on clone or pull.")
    71  		cmd.Flags().BoolVarP(&skipRepoInstall, "skip-repo", "", false, "Skip repo setup, just install global filters.")
    72  		cmd.AddCommand(NewCommand("hooks", installHooksCommand))
    73  		cmd.PreRun = setupLocalStorage
    74  	})
    75  }