Skip to content
This repository was archived by the owner on Sep 9, 2020. It is now read-only.

dep: Permit no Go source for ensure -add #1325

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions cmd/dep/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ func (cmd *ensureCommand) Run(ctx *dep.Ctx, args []string) error {
return err
}

if fatal, err := checkErrors(params.RootPackageTree.Packages, p.Manifest.IgnoredPackages()); err != nil {
if fatal, err := checkErrors(params.RootPackageTree.Packages, p.Manifest.IgnoredPackages(), cmd.add); err != nil {
if fatal {
return err
} else if ctx.Verbose {
Expand Down Expand Up @@ -769,7 +769,7 @@ func getProjectConstraint(arg string, sm gps.SourceManager) (gps.ProjectConstrai
return gps.ProjectConstraint{Ident: pi, Constraint: c}, arg, nil
}

func checkErrors(m map[string]pkgtree.PackageOrErr, ignore *pkgtree.IgnoredRuleset) (fatal bool, err error) {
func checkErrors(m map[string]pkgtree.PackageOrErr, ignore *pkgtree.IgnoredRuleset, allowNoGo bool) (fatal bool, err error) {
var (
noGoErrors int
pkgtreeErrors = make(pkgtreeErrs, 0, len(m))
Expand All @@ -790,8 +790,8 @@ func checkErrors(m map[string]pkgtree.PackageOrErr, ignore *pkgtree.IgnoredRules
}
}

// If pkgtree was empty or all dirs lacked any Go code, return an error.
if len(m) == 0 || len(m) == noGoErrors {
// If we don't allow no Go code and pkgtree was empty or all dirs lacked any Go code, return an error.
if !allowNoGo && (len(m) == 0 || len(m) == noGoErrors) {
return true, errors.New("no dirs contained any Go code")
}

Expand Down
2 changes: 1 addition & 1 deletion cmd/dep/ensure_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ func TestCheckErrors(t *testing.T) {

for _, tc := range tt {
t.Run(tc.name, func(t *testing.T) {
fatal, err := checkErrors(tc.pkgOrErrMap, nil)
fatal, err := checkErrors(tc.pkgOrErrMap, nil, false)
if tc.fatal != fatal {
t.Fatalf("expected fatal flag to be %T, got %T", tc.fatal, fatal)
}
Expand Down