[REV] support clone code by tag,but do not pull.(#86)

This commit is contained in:
barnettZQG 2018-07-27 15:35:11 +08:00
parent cba307c7ae
commit b8a222798a
3 changed files with 21 additions and 2 deletions

View File

@ -155,7 +155,11 @@ Loop:
Depth: 1,
}
if csi.Branch != "" {
opts.ReferenceName = plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", csi.Branch))
if strings.HasPrefix(csi.Branch, "tag:") {
opts.ReferenceName = plumbing.ReferenceName(fmt.Sprintf("refs/tags/%s", csi.Branch[4:]))
} else {
opts.ReferenceName = plumbing.ReferenceName(fmt.Sprintf("refs/heads/%s", csi.Branch))
}
}
var rs *git.Repository
if ep.Protocol == "ssh" {

View File

@ -46,6 +46,21 @@ func TestGitClone(t *testing.T) {
commit, err := GetLastCommit(res)
t.Logf("%+v %+v", commit, err)
}
func TestGitCloneByTag(t *testing.T) {
start := time.Now()
csi := CodeSourceInfo{
RepositoryURL: "https://github.com/goodrain/rainbond-install.git",
Branch: "tag:v3.5.1",
}
//logger := event.GetManager().GetLogger("system")
res, err := GitClone(csi, "/tmp/rainbonddoc4", nil, 1)
if err != nil {
t.Fatal(err)
}
t.Logf("Take %d ms", time.Now().Unix()-start.Unix())
commit, err := GetLastCommit(res)
t.Logf("%+v %+v", commit, err)
}
func TestGitPull(t *testing.T) {
csi := CodeSourceInfo{

View File

@ -24,7 +24,7 @@ import (
)
func TestCreateRepostoryBuildInfo(t *testing.T) {
info, err := CreateRepostoryBuildInfo("ssh://git@gr5042d6.7804f67d.ali-sh-s1.goodrain.net:20905/root/private2018.git?dir=abc", "master", "ADSASDADAD", "")
info, err := CreateRepostoryBuildInfo("ssh://git@gr5042d6.7804f67d.ali-sh-s1.goodrain.net:20905/root/private2018.git?dir=abc", "master", "ADSASDADAD", "", "")
if err != nil {
t.Fatal(err)
}