Merge pull request #1461 from github/check-git-version
check the git version is ok in some key commands
This commit is contained in:
commit
ac5a532665
@ -19,6 +19,7 @@ var (
|
||||
)
|
||||
|
||||
func cloneCommand(cmd *cobra.Command, args []string) {
|
||||
requireGitVersion()
|
||||
|
||||
// We pass all args to git clone
|
||||
err := git.CloneWithoutFilters(cloneFlags, args)
|
||||
|
@ -1,9 +1,10 @@
|
||||
package commands
|
||||
|
||||
import (
|
||||
"os"
|
||||
|
||||
"github.com/github/git-lfs/lfs"
|
||||
"github.com/spf13/cobra"
|
||||
"os"
|
||||
)
|
||||
|
||||
var (
|
||||
@ -14,6 +15,8 @@ var (
|
||||
)
|
||||
|
||||
func installCommand(cmd *cobra.Command, args []string) {
|
||||
requireGitVersion()
|
||||
|
||||
if localInstall {
|
||||
requireInRepo()
|
||||
}
|
||||
|
@ -43,6 +43,8 @@ func prePushCommand(cmd *cobra.Command, args []string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
requireGitVersion()
|
||||
|
||||
// Remote is first arg
|
||||
if err := git.ValidateRemote(args[0]); err != nil {
|
||||
Exit("Invalid remote name %q", args[0])
|
||||
|
@ -8,6 +8,7 @@ import (
|
||||
)
|
||||
|
||||
func pullCommand(cmd *cobra.Command, args []string) {
|
||||
requireGitVersion()
|
||||
requireInRepo()
|
||||
|
||||
if len(args) > 0 {
|
||||
|
@ -113,6 +113,8 @@ func pushCommand(cmd *cobra.Command, args []string) {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
requireGitVersion()
|
||||
|
||||
// Remote is first arg
|
||||
if err := git.ValidateRemote(args[0]); err != nil {
|
||||
Exit("Invalid remote name %q", args[0])
|
||||
|
@ -26,6 +26,8 @@ var (
|
||||
)
|
||||
|
||||
func trackCommand(cmd *cobra.Command, args []string) {
|
||||
requireGitVersion()
|
||||
|
||||
if config.LocalGitDir == "" {
|
||||
Print("Not a git repository.")
|
||||
os.Exit(128)
|
||||
|
@ -16,6 +16,7 @@ var (
|
||||
// updateCommand is used for updating parts of Git LFS that reside under
|
||||
// .git/lfs.
|
||||
func updateCommand(cmd *cobra.Command, args []string) {
|
||||
requireGitVersion()
|
||||
requireInRepo()
|
||||
|
||||
lfsAccessRE := regexp.MustCompile(`\Alfs\.(.*)\.access\z`)
|
||||
|
@ -118,23 +118,23 @@ func FullError(err error) {
|
||||
}
|
||||
|
||||
func errorWith(err error, fatalErrFn func(error, string, ...interface{}), errFn func(string, ...interface{})) {
|
||||
var innermsg string
|
||||
if inner := errutil.GetInnerError(err); inner != nil {
|
||||
innermsg = inner.Error()
|
||||
}
|
||||
|
||||
errmsg := err.Error()
|
||||
if errmsg != innermsg {
|
||||
Error(innermsg)
|
||||
}
|
||||
|
||||
if Debugging || errutil.IsFatalError(err) {
|
||||
fatalErrFn(err, errmsg)
|
||||
} else {
|
||||
errFn(errmsg)
|
||||
}
|
||||
var innermsg string
|
||||
if inner := errutil.GetInnerError(err); inner != nil {
|
||||
innermsg = inner.Error()
|
||||
}
|
||||
|
||||
errmsg := err.Error()
|
||||
if errmsg != innermsg {
|
||||
Error(innermsg)
|
||||
}
|
||||
|
||||
if Debugging || errutil.IsFatalError(err) {
|
||||
fatalErrFn(err, errmsg)
|
||||
} else {
|
||||
errFn(errmsg)
|
||||
}
|
||||
}
|
||||
|
||||
// Debug prints a formatted message if debugging is enabled. The formatted
|
||||
// message also shows up in the panic log, if created.
|
||||
func Debug(format string, args ...interface{}) {
|
||||
@ -334,6 +334,18 @@ func isCommandEnabled(cfg *config.Configuration, cmd string) bool {
|
||||
return cfg.Os.Bool(fmt.Sprintf("GITLFS%sENABLED", strings.ToUpper(cmd)), false)
|
||||
}
|
||||
|
||||
func requireGitVersion() {
|
||||
minimumGit := "1.8.2"
|
||||
|
||||
if !git.Config.IsGitVersionAtLeast(minimumGit) {
|
||||
gitver, err := git.Config.Version()
|
||||
if err != nil {
|
||||
Exit("Error getting git version: %s", err)
|
||||
}
|
||||
Exit("git version >= %s is required for Git LFS, your version: %s", minimumGit, gitver)
|
||||
}
|
||||
}
|
||||
|
||||
func init() {
|
||||
log.SetOutput(ErrorWriter)
|
||||
}
|
||||
|
16
git/git.go
16
git/git.go
@ -14,6 +14,7 @@ import (
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/github/git-lfs/subprocess"
|
||||
@ -306,6 +307,8 @@ func UpdateIndex(file string) error {
|
||||
}
|
||||
|
||||
type gitConfig struct {
|
||||
gitVersion string
|
||||
mu sync.Mutex
|
||||
}
|
||||
|
||||
var Config = &gitConfig{}
|
||||
@ -398,7 +401,18 @@ func (c *gitConfig) ListFromFile(f string) (string, error) {
|
||||
|
||||
// Version returns the git version
|
||||
func (c *gitConfig) Version() (string, error) {
|
||||
return subprocess.SimpleExec("git", "version")
|
||||
c.mu.Lock()
|
||||
defer c.mu.Unlock()
|
||||
|
||||
if len(c.gitVersion) == 0 {
|
||||
v, err := subprocess.SimpleExec("git", "version")
|
||||
if err != nil {
|
||||
return v, err
|
||||
}
|
||||
c.gitVersion = v
|
||||
}
|
||||
|
||||
return c.gitVersion, nil
|
||||
}
|
||||
|
||||
// IsVersionAtLeast returns whether the git version is the one specified or higher
|
||||
|
Loading…
Reference in New Issue
Block a user