Skip to content

Commit

Permalink
Merge pull request golang#161 from sdboyer/export-other-vcs
Browse files Browse the repository at this point in the history
Export non-git VCS correctly
  • Loading branch information
sdboyer committed Jan 26, 2017
2 parents 4284958 + 6ea21bd commit de17adc
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 13 deletions.
8 changes: 1 addition & 7 deletions result.go
Expand Up @@ -3,7 +3,6 @@ package gps
import (
"fmt"
"os"
"path"
"path/filepath"
)

Expand Down Expand Up @@ -46,12 +45,7 @@ func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool) error {

// TODO(sdboyer) parallelize
for _, p := range l.Projects() {
to := path.Join(basedir, string(p.Ident().ProjectRoot))

err := os.MkdirAll(to, 0777)
if err != nil {
return err
}
to := filepath.FromSlash(filepath.Join(basedir, string(p.Ident().ProjectRoot)))

err = sm.ExportProject(p.Ident(), p.Version(), to)
if err != nil {
Expand Down
42 changes: 36 additions & 6 deletions result_test.go
@@ -1,8 +1,10 @@
package gps

import (
"io/ioutil"
"os"
"path"
"path/filepath"
"testing"
)

Expand Down Expand Up @@ -43,26 +45,54 @@ func TestWriteDepTree(t *testing.T) {
t.Skip("Skipping dep tree writing test in short mode")
}

r := basicResult
tmp, err := ioutil.TempDir("", "writetree")
if err != nil {
t.Errorf("Failed to create temp dir: %s", err)
t.FailNow()
}
defer os.RemoveAll(tmp)

tmp := path.Join(os.TempDir(), "vsolvtest")
os.RemoveAll(tmp)
r := solution{
att: 1,
p: []LockedProject{
pa2lp(atom{
id: pi("github.com/sdboyer/testrepo"),
v: NewBranch("master").Is(Revision("4d59fb584b15a94d7401e356d2875c472d76ef45")),
}, nil),
pa2lp(atom{
id: pi("launchpad.net/govcstestbzrrepo"),
v: NewVersion("1.0.0").Is(Revision("matt@mattfarina.com-20150731135137-pbphasfppmygpl68")),
}, nil),
pa2lp(atom{
id: pi("bitbucket.org/sdboyer/withbm"),
v: NewVersion("v1.0.0").Is(Revision("aa110802a0c64195d0a6c375c9f66668827c90b4")),
}, nil),
},
}

sm, clean := mkNaiveSM(t)
defer clean()

// nil lock/result should err immediately
err := WriteDepTree(path.Join(tmp, "export"), nil, sm, true)
err = WriteDepTree(tmp, nil, sm, true)
if err == nil {
t.Errorf("Should error if nil lock is passed to WriteDepTree")
}

err = WriteDepTree(path.Join(tmp, "export"), r, sm, true)
err = WriteDepTree(tmp, r, sm, true)
if err != nil {
t.Errorf("Unexpected error while creating vendor tree: %s", err)
}

// TODO(sdboyer) add more checks
if _, err = os.Stat(filepath.Join(tmp, "github.com", "sdboyer", "testrepo")); err != nil {
t.Errorf("Directory for github.com/sdboyer/testrepo does not exist")
}
if _, err = os.Stat(filepath.Join(tmp, "launchpad.net", "govcstestbzrrepo")); err != nil {
t.Errorf("Directory for launchpad.net/govcstestbzrrepo does not exist")
}
if _, err = os.Stat(filepath.Join(tmp, "bitbucket.org", "sdboyer", "withbm")); err != nil {
t.Errorf("Directory for bitbucket.org/sdboyer/withbm does not exist")
}
}

func BenchmarkCreateVendorTree(b *testing.B) {
Expand Down
12 changes: 12 additions & 0 deletions source.go
Expand Up @@ -2,6 +2,8 @@ package gps

import (
"fmt"
"os"
"path/filepath"
"sync"
)

Expand Down Expand Up @@ -432,5 +434,15 @@ func (bs *baseVCSSource) toRevOrErr(v Version) (r Revision, err error) {
}

func (bs *baseVCSSource) exportVersionTo(v Version, to string) error {
if err := bs.ensureCacheExistence(); err != nil {
return err
}

// Only make the parent dir, as the general implementation will balk on
// trying to write to an empty but existing dir.
if err := os.MkdirAll(filepath.Dir(to), 0777); err != nil {
return err
}

return bs.crepo.exportVersionTo(v, to)
}
4 changes: 4 additions & 0 deletions vcs_source.go
Expand Up @@ -40,6 +40,10 @@ func (s *gitSource) exportVersionTo(v Version, to string) error {
return err
}

if err := os.MkdirAll(to, 0777); err != nil {
return err
}

do := func() error {
s.crepo.mut.Lock()
defer s.crepo.mut.Unlock()
Expand Down

0 comments on commit de17adc

Please sign in to comment.