2014-09-23 21:42:47 +00:00
package commands
import (
2015-09-02 19:25:34 +00:00
"regexp"
"github.com/github/git-lfs/git"
2015-03-19 19:30:55 +00:00
"github.com/github/git-lfs/lfs"
2015-05-25 18:20:50 +00:00
"github.com/github/git-lfs/vendor/_nuts/github.com/spf13/cobra"
2014-09-23 21:42:47 +00:00
)
var (
updateCmd = & cobra . Command {
2015-09-17 22:08:28 +00:00
Use : "update" ,
Run : updateCommand ,
2014-09-23 21:42:47 +00:00
}
2015-04-24 17:33:22 +00:00
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 ) {
2015-10-19 20:47:18 +00:00
requireInRepo ( )
2015-09-02 19:25:34 +00:00
lfsAccessRE := regexp . MustCompile ( ` \Alfs\.(.*)\.access\z ` )
for key , value := range lfs . Config . AllGitConfig ( ) {
matches := lfsAccessRE . FindStringSubmatch ( key )
if len ( matches ) < 2 {
continue
}
switch value {
case "basic" :
case "private" :
git . Config . SetLocal ( "" , key , "basic" )
Print ( "Updated %s access from %s to %s." , matches [ 1 ] , value , "basic" )
default :
git . Config . UnsetLocalKey ( "" , key )
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 {
Print ( lfs . GetHookInstallSteps ( ) )
2016-04-25 09:58:36 +00:00
} else {
2016-04-26 11:04:55 +00:00
if err := lfs . InstallHooks ( updateForce ) ; err != nil {
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 {
Print ( "Updated pre-push hook." )
}
2016-04-25 09:58:36 +00:00
}
2014-09-23 21:42:47 +00:00
}
func init ( ) {
2016-04-26 11:04:55 +00:00
updateCmd . Flags ( ) . BoolVarP ( & updateForce , "force" , "f" , false , "Overwrite existing hooks." )
updateCmd . Flags ( ) . BoolVarP ( & updateManual , "manual" , "m" , false , "Print instructions for manual install." )
2014-09-23 21:42:47 +00:00
RootCmd . AddCommand ( updateCmd )
}