Skip to content
This repository was archived by the owner on Feb 3, 2018. It is now read-only.

Commit f0bed51

Browse files
committed
Ensure writing deptree works for bzr, hg
The main fix here is avoiding creating an empty directory for the destination, as copyDir() doesn't like that. Instead, we create only up to the parent dir. The other bit is ensuring the source repos exist in the cache before attempting to export them, for both bzr and hg. Addresses golang/dep#144
1 parent 4284958 commit f0bed51

File tree

3 files changed

+42
-7
lines changed

3 files changed

+42
-7
lines changed

result.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ func WriteDepTree(basedir string, l Lock, sm SourceManager, sv bool) error {
4848
for _, p := range l.Projects() {
4949
to := path.Join(basedir, string(p.Ident().ProjectRoot))
5050

51-
err := os.MkdirAll(to, 0777)
51+
// Only make the parent dir, as some source implementations will balk on
52+
// trying to write to an empty but existing dir.
53+
err := os.MkdirAll(filepath.Dir(to), 0777)
5254
if err != nil {
5355
return err
5456
}

result_test.go

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package gps
22

33
import (
4+
"io/ioutil"
45
"os"
56
"path"
7+
"path/filepath"
68
"testing"
79
)
810

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

46-
r := basicResult
48+
tmp, err := ioutil.TempDir("", "writetree")
49+
if err != nil {
50+
t.Errorf("Failed to create temp dir: %s", err)
51+
t.FailNow()
52+
}
53+
defer os.RemoveAll(tmp)
4754

48-
tmp := path.Join(os.TempDir(), "vsolvtest")
49-
os.RemoveAll(tmp)
55+
r := solution{
56+
att: 1,
57+
p: []LockedProject{
58+
pa2lp(atom{
59+
id: pi("github.com/sdboyer/testrepo"),
60+
v: NewBranch("master").Is(Revision("4d59fb584b15a94d7401e356d2875c472d76ef45")),
61+
}, nil),
62+
pa2lp(atom{
63+
id: pi("launchpad.net/govcstestbzrrepo"),
64+
v: NewVersion("1.0.0").Is(Revision("[email protected]")),
65+
}, nil),
66+
pa2lp(atom{
67+
id: pi("bitbucket.org/sdboyer/withbm"),
68+
v: NewVersion("v1.0.0").Is(Revision("aa110802a0c64195d0a6c375c9f66668827c90b4")),
69+
}, nil),
70+
},
71+
}
5072

5173
sm, clean := mkNaiveSM(t)
5274
defer clean()
5375

5476
// nil lock/result should err immediately
55-
err := WriteDepTree(path.Join(tmp, "export"), nil, sm, true)
77+
err = WriteDepTree(tmp, nil, sm, true)
5678
if err == nil {
5779
t.Errorf("Should error if nil lock is passed to WriteDepTree")
5880
}
5981

60-
err = WriteDepTree(path.Join(tmp, "export"), r, sm, true)
82+
err = WriteDepTree(tmp, r, sm, true)
6183
if err != nil {
6284
t.Errorf("Unexpected error while creating vendor tree: %s", err)
6385
}
6486

65-
// TODO(sdboyer) add more checks
87+
if _, err = os.Stat(filepath.Join(tmp, "github.com", "sdboyer", "testrepo")); err != nil {
88+
t.Errorf("Directory for github.com/sdboyer/testrepo does not exist")
89+
}
90+
if _, err = os.Stat(filepath.Join(tmp, "launchpad.net", "govcstestbzrrepo")); err != nil {
91+
t.Errorf("Directory for launchpad.net/govcstestbzrrepo does not exist")
92+
}
93+
if _, err = os.Stat(filepath.Join(tmp, "bitbucket.org", "sdboyer", "withbm")); err != nil {
94+
t.Errorf("Directory for bitbucket.org/sdboyer/withbm does not exist")
95+
}
6696
}
6797

6898
func BenchmarkCreateVendorTree(b *testing.B) {

source.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -432,5 +432,8 @@ func (bs *baseVCSSource) toRevOrErr(v Version) (r Revision, err error) {
432432
}
433433

434434
func (bs *baseVCSSource) exportVersionTo(v Version, to string) error {
435+
if err := bs.ensureCacheExistence(); err != nil {
436+
return err
437+
}
435438
return bs.crepo.exportVersionTo(v, to)
436439
}

0 commit comments

Comments
 (0)