github.com/git-lfs/git-lfs@v2.5.2+incompatible/commands/command_update.go (about)

     1  package commands
     2  
     3  import (
     4  	"regexp"
     5  
     6  	"github.com/spf13/cobra"
     7  )
     8  
     9  var (
    10  	updateForce  = false
    11  	updateManual = false
    12  )
    13  
    14  // updateCommand is used for updating parts of Git LFS that reside under
    15  // .git/lfs.
    16  func updateCommand(cmd *cobra.Command, args []string) {
    17  	requireGitVersion()
    18  	requireInRepo()
    19  
    20  	lfsAccessRE := regexp.MustCompile(`\Alfs\.(.*)\.access\z`)
    21  	for key, _ := range cfg.Git.All() {
    22  		matches := lfsAccessRE.FindStringSubmatch(key)
    23  		if len(matches) < 2 {
    24  			continue
    25  		}
    26  
    27  		value, _ := cfg.Git.Get(key)
    28  
    29  		switch value {
    30  		case "basic":
    31  		case "private":
    32  			cfg.SetGitLocalKey(key, "basic")
    33  			Print("Updated %s access from %s to %s.", matches[1], value, "basic")
    34  		default:
    35  			cfg.UnsetGitLocalKey(key)
    36  			Print("Removed invalid %s access of %s.", matches[1], value)
    37  		}
    38  	}
    39  
    40  	if updateForce && updateManual {
    41  		Exit("You cannot use --force and --manual options together")
    42  	}
    43  
    44  	if updateManual {
    45  		Print(getHookInstallSteps())
    46  	} else {
    47  		if err := installHooks(updateForce); err != nil {
    48  			Error(err.Error())
    49  			Exit("To resolve this, either:\n  1: run `git lfs update --manual` for instructions on how to merge hooks.\n  2: run `git lfs update --force` to overwrite your hook.")
    50  		} else {
    51  			Print("Updated git hooks.")
    52  		}
    53  	}
    54  
    55  }
    56  
    57  func init() {
    58  	RegisterCommand("update", updateCommand, func(cmd *cobra.Command) {
    59  		cmd.Flags().BoolVarP(&updateForce, "force", "f", false, "Overwrite existing hooks.")
    60  		cmd.Flags().BoolVarP(&updateManual, "manual", "m", false, "Print instructions for manual install.")
    61  	})
    62  }