1 Star 0 Fork 0

iamRegina / govendor

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
git.go 1.07 KB
一键复制 编辑 原始数据 按行查看 历史
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package vcs
import (
"os/exec"
"path/filepath"
"strings"
"time"
os "github.com/kardianos/govendor/internal/vos"
)
type VcsGit struct{}
func (VcsGit) Find(dir string) (*VcsInfo, error) {
fi, err := os.Stat(filepath.Join(dir, ".git"))
if err != nil {
if os.IsNotExist(err) {
return nil, nil
}
return nil, err
}
if fi.IsDir() == false {
return nil, nil
}
// Get info.
info := &VcsInfo{}
cmd := exec.Command("git", "status", "--short")
cmd.Dir = dir
err = cmd.Run()
if err != nil {
info.Dirty = true
}
cmd = exec.Command("git", "show", "--pretty=format:%H@%ai", "-s")
cmd.Dir = dir
output, err := cmd.CombinedOutput()
if err != nil {
return nil, err
}
line := strings.TrimSpace(string(output))
ss := strings.Split(line, "@")
info.Revision = ss[0]
tm, err := time.Parse("2006-01-02 15:04:05 -0700", ss[1])
if err != nil {
return nil, err
}
info.RevisionTime = &tm
return info, nil
}
1
https://gitee.com/iamReginaaaa/govendor.git
git@gitee.com:iamReginaaaa/govendor.git
iamReginaaaa
govendor
govendor
v1.0.9

搜索帮助

53164aa7 5694891 3bd8fe86 5694891