Skip to content
This repository has been archived by the owner on Feb 26, 2019. It is now read-only.

Commit

Permalink
v67: Handle missing deps a little better
Browse files Browse the repository at this point in the history
  • Loading branch information
Edward Muller committed May 13, 2016
2 parents 731d8b3 + cdb5ef1 commit 2d182df
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 10 deletions.
4 changes: 4 additions & 0 deletions Changelog.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
#v67 (2016/06/13)

* Attempt to handle missing deps a little better.

#v66 (2016/06/10)

* Use `git remote show origin` to find the default branch when restoring a git based package repository that is in detached head state
Expand Down
1 change: 1 addition & 0 deletions dep.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ type Dependency struct {
// used by command update
matched bool // selected for update by command line
pkg *Package
missing bool // packages is missing

// used by command go
vcs *VCS
Expand Down
17 changes: 17 additions & 0 deletions godepfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,20 @@ func (g *Godeps) addOrUpdateDeps(deps []Dependency) {
g.Deps = append(g.Deps, d)
}
}

func (g *Godeps) removeDeps(deps []Dependency) {
var f []Dependency
for i := range g.Deps {
var found bool
for _, d := range deps {
if g.Deps[i].ImportPath == d.ImportPath {
found = true
break
}
}
if !found {
f = append(f, g.Deps[i])
}
}
g.Deps = f
}
2 changes: 2 additions & 0 deletions save_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1602,6 +1602,8 @@ func makeTree(t *testing.T, tree *node, altpath string) (gopath string) {
os.Symlink(target, path)
case n.entries == nil && body == "(absent)":
panic("is this gonna be forever")
case n.entries == nil && body == "(rm)":
os.RemoveAll(path)
case n.entries == nil:
os.MkdirAll(filepath.Dir(path), 0770)
err := ioutil.WriteFile(path, []byte(body), 0660)
Expand Down
29 changes: 21 additions & 8 deletions update.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,19 +94,23 @@ func update(args []string) error {
log.Println("not in manifest:", arg)
}
}
deps, err := LoadVCSAndUpdate(g.Deps)
deps, rdeps, err := LoadVCSAndUpdate(g.Deps)
if err != nil {
return err
}
if len(deps) == 0 {
return errorNoPackagesUpdatable
}
g.addOrUpdateDeps(deps)
g.removeDeps(rdeps)
if _, err = g.save(); err != nil {
return err
}

srcdir := relativeVendorTarget(VendorExperiment)
if err := removeSrc(filepath.FromSlash(strings.Trim(sep, "/")), rdeps); err != nil {
return err
}
copySrc(srcdir, deps)

ok, err := needRewrite(g.Packages)
Expand Down Expand Up @@ -180,6 +184,10 @@ func fillDeps(deps []Dependency) ([]Dependency, error) {
}
ps, err := LoadPackages(deps[i].ImportPath)
if err != nil {
if _, ok := err.(errPackageNotFound); ok {
deps[i].missing = true
continue
}
return nil, err
}
if len(ps) > 1 {
Expand All @@ -202,12 +210,12 @@ func fillDeps(deps []Dependency) ([]Dependency, error) {
}

// LoadVCSAndUpdate loads and updates a set of dependencies.
func LoadVCSAndUpdate(deps []Dependency) ([]Dependency, error) {
func LoadVCSAndUpdate(deps []Dependency) ([]Dependency, []Dependency, error) {
var err1 error

deps, err := fillDeps(deps)
if err != nil {
return nil, err
return nil, nil, err
}

repoMask := make(map[string]bool)
Expand All @@ -219,7 +227,7 @@ func LoadVCSAndUpdate(deps []Dependency) ([]Dependency, error) {

// Determine if we need any new packages because of new transitive imports
for _, dep := range deps {
if !dep.matched {
if !dep.matched || dep.missing {
continue
}
for _, dp := range dep.pkg.Dependencies {
Expand All @@ -241,16 +249,21 @@ func LoadVCSAndUpdate(deps []Dependency) ([]Dependency, error) {

deps, err = fillDeps(deps)
if err != nil {
return nil, err
return nil, nil, err
}

var toUpdate []Dependency
var toUpdate, toRemove []Dependency
for _, d := range deps {
if !d.matched || repoMask[d.root] {
continue
}
if d.missing {
toRemove = append(toRemove, d)
continue
}
toUpdate = append(toUpdate, d)
}

debugln("toUpdate")
ppln(toUpdate)

Expand All @@ -273,7 +286,7 @@ func LoadVCSAndUpdate(deps []Dependency) ([]Dependency, error) {
ppln(toCopy)

if err1 != nil {
return nil, err1
return nil, nil, err1
}
return toCopy, nil
return toCopy, toRemove, nil
}
102 changes: 101 additions & 1 deletion update_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ func TestUpdate(t *testing.T) {
},
},
},
{ // 11 - package/..., new transitive package, different repo
{ // 12 - package/..., new transitive package, different repo
vendor: true,
cwd: "C",
args: []string{"D/..."},
Expand Down Expand Up @@ -579,6 +579,106 @@ func TestUpdate(t *testing.T) {
},
},
},
{ // 13 - package/..., missing packages
vendor: true,
cwd: "C",
args: []string{"D/..."},
start: []*node{
{
"D",
"",
[]*node{
{"A/main.go", pkg("A") + decl("D1"), nil},
{"B/main.go", pkg("B") + decl("D1"), nil},
{"+git", "D1", nil},
},
},
{
"C",
"",
[]*node{
{"main.go", pkg("main", "D/A"), nil},
{"Godeps/Godeps.json", godeps("C", "D/A", "D1", "D/B", "D1"), nil},
{"vendor/D/A/main.go", pkg("A") + decl("D1"), nil},
{"vendor/D/B/main.go", pkg("B") + decl("D1"), nil},
{"+git", "", nil},
},
},
{"D",
"",
[]*node{
{"A/main.go", pkg("A") + decl("D2"), nil},
{"B", "(rm)", nil},
{"+git", "D2", nil},
},
},
},
want: []*node{
{"C/vendor/D/A/main.go", pkg("A") + decl("D2"), nil},
{"C/vendor/D/B/main.go", "(absent)", nil},
{"C/vendor/D/E/main.go", "(absent)", nil},
},
wdep: Godeps{
ImportPath: "C",
Deps: []Dependency{
{ImportPath: "D/A", Comment: "D2"},
},
},
},
{ // 14 - Update package A, but not package B, which is missing from $GOPATH
vendor: true,
cwd: "C",
args: []string{"A"},
start: []*node{
{
"A",
"",
[]*node{
{"main.go", pkg("A") + decl("A1"), nil},
{"+git", "A1", nil},
{"main.go", pkg("A") + decl("A2"), nil},
{"+git", "A2", nil},
},
},
{ // Create B so makeTree can resolve the rev for Godeps.json
"B",
"",
[]*node{
{"main.go", pkg("B") + decl("B1"), nil},
{"+git", "B1", nil},
},
},
{
"C",
"",
[]*node{
{"main.go", pkg("main", "A", "B"), nil},
{"Godeps/Godeps.json", godeps("C", "A", "A1", "B", "B1"), nil},
{"vendor/A/main.go", pkg("A") + decl("A1"), nil},
{"vendor/B/main.go", pkg("B") + decl("B1"), nil},
{"+git", "", nil},
},
},
{ // Remove B so it's not in the $GOPATH
"",
"",
[]*node{
{"B", "(rm)", nil},
},
},
},
want: []*node{
{"C/vendor/A/main.go", pkg("A") + decl("A2"), nil},
{"C/vendor/B/main.go", pkg("B") + decl("B1"), nil},
},
wdep: Godeps{
ImportPath: "C",
Deps: []Dependency{
{ImportPath: "A", Comment: "A2"},
{ImportPath: "B", Comment: "B1"},
},
},
},
}

wd, err := os.Getwd()
Expand Down
2 changes: 1 addition & 1 deletion version.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"strings"
)

const version = 66
const version = 67

var cmdVersion = &Command{
Name: "version",
Expand Down

0 comments on commit 2d182df

Please sign in to comment.