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

Gopkg.toml in subdirectory of git project should not try to vendor other directories in same git project #2116

Closed
@coriolinus

Description

@coriolinus

Given a repository which contains a cmd folder which builds some number of executables, and an arbitrarily large number of other folders outside of cmd intended to be imported by other packages as libraries. In order to follow the principle that binaries handle vendoring, and libraries do not, it is desirable to always run dep ensure within the cmd folder. This ensures that Gopkg.* and vendor all appear there, so that external applications may depend on the libraries without encountering the constraints of the binaries.

dep handles this case poorly: the library portions of the repo, because they are not subfolders of the CWD in which dep is being run, are treated as external libraries and vendored. This is not desirable: a single repository should be considered to always be up-to-date with itself.

Example

$ tree -L 1
Mon Mar  4 12:09:11 CET 2019
.
├── cmd
├── crypto
├── libs
└── version

cmd contains a number of commands. crypto, libs, and version contain libraries we desire to export to other packages. When Gopkg.toml exists within cmd/, everything in those libraries is considered an external package, and must have a version specified. This is not desirable: by default, the most recent tagged version will be vendored. This does not allow for continued development on a dev branch.

Putting Gopkg.toml at the repo root fixes the problem for this package, but it makes things worse for packages downstream, using these libraries: whatever their constraints are must now also coexist with the constraints of this project. If this project has a command which has a constraint incompatible with the downstream project's constraint set, then they cannot solve their dependency graph, even if that constraint doesn't apply to the library portion of the code at all.

Desired fix

dep currently assumes that everything in the directory containing Gopkg.toml and its subfolders is a single project, always up-to-date with itself. These folders are therefore not vendored. This assumption should be broadened: everything within a single repository should be considered a single project, always up-to-date with itself, and excluded from vendoring. The repository root can be found very simply in the most common repositories:

  • git rev-parse --show-toplevel
  • hg root
  • etc

What version of dep are you using (dep version)?

$ dep version
Mon Mar  4 11:57:30 CET 2019
dep:
 version     : v0.5.0
 build date  : 2018-08-16
 git hash    : 224a564
 go version  : go1.10.3
 go compiler : gc
 platform    : darwin/amd64
 features    : ImportDuringSolve=false

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions