diff --git a/cmd/dep/init.go b/cmd/dep/init.go index 180f6d5d45..e8c255c87d 100644 --- a/cmd/dep/init.go +++ b/cmd/dep/init.go @@ -88,6 +88,9 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error { } p, err := cmd.establishProjectAt(root, ctx) + if err != nil { + return err + } sm, err := ctx.SourceManager() if err != nil { @@ -100,9 +103,7 @@ func (cmd *initCommand) Run(ctx *dep.Ctx, args []string) error { ctx.Out.Println("Getting direct dependencies...") } - // If this errors, the next call will too; don't bother handling it twice. - ptree, _ := p.ParseRootPackageTree() - directDeps, err := p.GetDirectDependencyNames(sm) + ptree, directDeps, err := p.GetDirectDependencyNames(sm) if err != nil { return errors.Wrap(err, "init failed: unable to determine direct dependencies") } diff --git a/cmd/dep/status.go b/cmd/dep/status.go index de09497c26..c342b20f29 100644 --- a/cmd/dep/status.go +++ b/cmd/dep/status.go @@ -766,7 +766,7 @@ func collectConstraints(ctx *dep.Ctx, p *dep.Project, sm gps.SourceManager) (con // Collect the complete set of direct project dependencies, incorporating // requireds and ignores appropriately. - directDeps, err := p.GetDirectDependencyNames(sm) + _, directDeps, err := p.GetDirectDependencyNames(sm) if err != nil { // Return empty collection, not nil, if we fail here. return constraintCollection, []error{errors.Wrap(err, "failed to get direct dependencies")} diff --git a/project.go b/project.go index 5f25c48e66..d2677e8866 100644 --- a/project.go +++ b/project.go @@ -143,7 +143,7 @@ func (p *Project) MakeParams() gps.SolveParameters { // // The resulting tree is cached internally at p.RootPackageTree. func (p *Project) ParseRootPackageTree() (pkgtree.PackageTree, error) { - if len(p.RootPackageTree.Packages) == 0 { + if p.RootPackageTree.Packages == nil { ptree, err := pkgtree.ListPackages(p.ResolvedAbsRoot, string(p.ImportRoot)) if err != nil { return pkgtree.PackageTree{}, errors.Wrap(err, "analysis of current project's packages failed") @@ -174,10 +174,10 @@ func (p *Project) ParseRootPackageTree() (pkgtree.PackageTree, error) { // This function will correctly utilize ignores and requireds from an existing // manifest, if one is present, but will also do the right thing without a // manifest. -func (p *Project) GetDirectDependencyNames(sm gps.SourceManager) (map[gps.ProjectRoot]bool, error) { +func (p *Project) GetDirectDependencyNames(sm gps.SourceManager) (pkgtree.PackageTree, map[gps.ProjectRoot]bool, error) { ptree, err := p.ParseRootPackageTree() if err != nil { - return nil, err + return pkgtree.PackageTree{}, nil, err } var ig *pkgtree.IgnoredRuleset @@ -211,26 +211,26 @@ func (p *Project) GetDirectDependencyNames(sm gps.SourceManager) (map[gps.Projec for _, ip := range reach { pr, err := sm.DeduceProjectRoot(ip) if err != nil { - return nil, err + return pkgtree.PackageTree{}, nil, err } directDeps[pr] = true } - return directDeps, nil + return ptree, directDeps, nil } // FindIneffectualConstraints looks for constraint rules expressed in the // manifest that will have no effect during solving, as they are specified for // projects that are not direct dependencies of the Project. // -// "Direct dependency" here is as implemented by GetDirectDependencyNames() - -// after all "ignored" and "required" rules have been considered. +// "Direct dependency" here is as implemented by GetDirectDependencyNames(); +// it correctly incorporates all "ignored" and "required" rules. func (p *Project) FindIneffectualConstraints(sm gps.SourceManager) []gps.ProjectRoot { if p.Manifest == nil { return nil } - dd, err := p.GetDirectDependencyNames(sm) + _, dd, err := p.GetDirectDependencyNames(sm) if err != nil { return nil }