Text file src/cmd/go/testdata/script/mod_get_ambiguous_pkg.txt

     1  # Both example.net/ambiguous v0.1.0 and example.net/ambiguous/pkg v0.1.0 exist.
     2  # 'go mod tidy' would arbitrarily choose the one with the longer path,
     3  # but 'go mod tidy' also arbitrarily chooses the latest version.
     4  
     5  cp go.mod go.mod.orig
     6  
     7  
     8  # From a clean slate, 'go get' currently does the same thing as 'go mod tidy':
     9  # it resolves the package from the module with the longest matching prefix.
    10  
    11  go get example.net/ambiguous/nested/pkg@v0.1.0
    12  go list -m all
    13  stdout '^example.net/ambiguous/nested v0.1.0$'
    14  ! stdout '^example.net/ambiguous '
    15  
    16  
    17  # From an initial state that already depends on the shorter path,
    18  # the same 'go get' command should (somewhat arbitrarily) keep the
    19  # existing path, since it is a valid interpretation of the command.
    20  
    21  cp go.mod.orig go.mod
    22  go mod edit -require=example.net/ambiguous@v0.1.0
    23  
    24  go get example.net/ambiguous/nested/pkg@v0.1.0
    25  go list -m all
    26  stdout '^example.net/ambiguous v0.1.0$'
    27  ! stdout '^example.net/ambiguous/nested '
    28  
    29  
    30  # The user should be able to make the command unambiguous by explicitly
    31  # upgrading the conflicting module...
    32  
    33  go get example.net/ambiguous@v0.2.0 example.net/ambiguous/nested/pkg@v0.1.0
    34  go list -m all
    35  stdout '^example.net/ambiguous/nested v0.1.0$'
    36  stdout '^example.net/ambiguous v0.2.0$'
    37  
    38  
    39  # ...or by explicitly NOT adding the conflicting module.
    40  
    41  cp go.mod.orig go.mod
    42  go mod edit -require=example.net/ambiguous@v0.1.0
    43  
    44  go get example.net/ambiguous/nested/pkg@v0.1.0 example.net/ambiguous/nested@none
    45  go list -m all
    46  ! stdout '^example.net/ambiguous/nested '
    47  stdout '^example.net/ambiguous v0.1.0$'
    48  
    49  
    50  # The user should also be able to fix it by *downgrading* the conflicting module
    51  # away.
    52  
    53  cp go.mod.orig go.mod
    54  go mod edit -require=example.net/ambiguous@v0.1.0
    55  
    56  go get example.net/ambiguous@none example.net/ambiguous/nested/pkg@v0.1.0
    57  go list -m all
    58  stdout '^example.net/ambiguous/nested v0.1.0$'
    59  ! stdout '^example.net/ambiguous '
    60  
    61  
    62  # In contrast, if we do the same thing tacking a wildcard pattern ('/...') on
    63  # the end of the package path, we get different behaviors depending on the
    64  # initial state, and no error. (This seems to contradict the “same meaning
    65  # regardless of the initial state” point above, but maybe that's ok?)
    66  
    67  cp go.mod.orig go.mod
    68  
    69  go get example.net/ambiguous/nested/pkg/...@v0.1.0
    70  go list -m all
    71  stdout '^example.net/ambiguous/nested v0.1.0$'
    72  ! stdout '^example.net/ambiguous '
    73  
    74  
    75  cp go.mod.orig go.mod
    76  go mod edit -require=example.net/ambiguous@v0.1.0
    77  
    78  go get example.net/ambiguous/nested/pkg/...@v0.1.0
    79  go list -m all
    80  ! stdout '^example.net/ambiguous/nested '
    81  stdout '^example.net/ambiguous v0.1.0$'
    82  
    83  
    84  -- go.mod --
    85  module test
    86  
    87  go 1.16
    88  

View as plain text