2014-09-23 21:42:47 +00:00
package commands
import (
2015-09-02 19:25:34 +00:00
"regexp"
2016-05-23 18:02:27 +00:00
"github.com/spf13/cobra"
2014-09-23 21:42:47 +00:00
)
var (
2016-04-26 11:04:55 +00:00
updateForce = false
updateManual = false
2014-09-23 21:42:47 +00:00
)
2015-03-19 19:30:55 +00:00
// updateCommand is used for updating parts of Git LFS that reside under
// .git/lfs.
2014-09-23 21:42:47 +00:00
func updateCommand ( cmd * cobra . Command , args [ ] string ) {
2016-08-17 22:13:36 +00:00
requireGitVersion ( )
2015-10-19 20:47:18 +00:00
requireInRepo ( )
2015-09-02 19:25:34 +00:00
lfsAccessRE := regexp . MustCompile ( ` \Alfs\.(.*)\.access\z ` )
2017-04-12 21:29:11 +00:00
for key , _ := range cfg . Git . All ( ) {
2015-09-02 19:25:34 +00:00
matches := lfsAccessRE . FindStringSubmatch ( key )
if len ( matches ) < 2 {
continue
}
2017-04-12 21:29:11 +00:00
value , _ := cfg . Git . Get ( key )
2015-09-02 19:25:34 +00:00
switch value {
case "basic" :
case "private" :
2017-10-26 01:20:35 +00:00
cfg . SetGitLocalKey ( key , "basic" )
2015-09-02 19:25:34 +00:00
Print ( "Updated %s access from %s to %s." , matches [ 1 ] , value , "basic" )
default :
2017-10-26 01:20:35 +00:00
cfg . UnsetGitLocalKey ( key )
2015-09-02 19:25:34 +00:00
Print ( "Removed invalid %s access of %s." , matches [ 1 ] , value )
}
}
2016-04-25 09:58:36 +00:00
2016-04-26 11:04:55 +00:00
if updateForce && updateManual {
Exit ( "You cannot use --force and --manual options together" )
}
if updateManual {
2017-10-18 21:42:00 +00:00
Print ( getHookInstallSteps ( ) )
2016-04-25 09:58:36 +00:00
} else {
2017-10-18 21:42:00 +00:00
if err := installHooks ( updateForce ) ; err != nil {
2016-04-26 11:04:55 +00:00
Error ( err . Error ( ) )
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." )
} else {
2017-01-02 13:07:53 +00:00
Print ( "Updated git hooks." )
2016-04-26 11:04:55 +00:00
}
2016-04-25 09:58:36 +00:00
}
2014-09-23 21:42:47 +00:00
}
func init ( ) {
2016-09-01 16:09:38 +00:00
RegisterCommand ( "update" , updateCommand , func ( cmd * cobra . Command ) {
2016-08-10 15:33:25 +00:00
cmd . Flags ( ) . BoolVarP ( & updateForce , "force" , "f" , false , "Overwrite existing hooks." )
cmd . Flags ( ) . BoolVarP ( & updateManual , "manual" , "m" , false , "Print instructions for manual install." )
} )
2014-09-23 21:42:47 +00:00
}