Pkg.jl icon indicating copy to clipboard operation
Pkg.jl copied to clipboard

Make adding by branch or dev'ing use repo with latest version

Open ericphanson opened this issue 2 years ago • 7 comments

Fixes https://github.com/JuliaLang/Pkg.jl/issues/2525 by using @fredrikekre's suggestion https://github.com/JuliaLang/Pkg.jl/issues/2525#issuecomment-827492474. ~~It seems to work in some brief testing locally, but I should still figure out how to add the scenario to the tests here.~~ added some tests!

This gives a menu like this:

Repository for package with UUID `7876af07-990d-54b4-ab0e-23690620f79a` found in multiple registries, choose one:
 > General: https://github.com/JuliaLang/Example.jl.git
   RegistryFoo: https://github.com/JuliaLang/Example1.jl.git
   RegistryFoo: https://github.com/JuliaLang/Example2.jl.git:subdir

ericphanson avatar Oct 17 '21 01:10 ericphanson

I realized that we don't care which registry we get a repo from if two registries have the same repo; no need to prompt or error in that case (which would be a regression from the current behavior). So I rearranged things to use a Dict to collect the unique sets of (repo, subdir) and which registries they come from (which is just passed to the user so they understand better where the multiple repos are coming from).

Now, in the admittedly complicated scenario tested, we get this menu:

Multiple repositories found for package with UUID `7876af07-990d-54b4-ab0e-23690620f79a`, choose one:
 > General: https://github.com/JuliaLang/Example.jl.git
   RegistryFoo1, RegistryFoo2: https://github.com/JuliaLang/OtherExampleRepo.jl.git
   RegistryFoo3: https://github.com/JuliaLang/OtherExampleRepo.jl.git:subdir

Here there are 4 registries; 2 have the same (repo, subdir), namely RegistryFoo1 and RegistryFoo2. RegistryFoo3 has a subdir parameter, and of course General. In particular if we only have RegistryFoo1 and RegistryFoo2, then there's no prompt, since it's unambiguous which repo to use.

ericphanson avatar Oct 17 '21 19:10 ericphanson

To me it feels like if you know which registry you want (you know the correct URL) why not just add it via that URL?

Mixing in interactive stuff in deeply internal functions significantly complicates maintenance and they are hard to test. I'd rather have this error and print out the possible URLs and then you can just chose one of them instead of adding an interactive element to it.

KristofferC avatar Oct 18 '21 07:10 KristofferC

To me it feels like if you know which registry you want (you know the correct URL) why not just add it via that URL?

Isn’t that also true for name clashes, where a name is in multiple registries? There we could error and print the UUIDs but instead give an interactive menu (untested iiuc, unlike this code). And it seems like this feature is well-received and folks cite it to show how well Pkg handles multiple registries.

ericphanson avatar Oct 18 '21 09:10 ericphanson

Isn’t that also true for name clashes, where a name is in multiple registries?

Yes, I agree. That should probably be removed as well and be replaced with a nice error message instead.

And it seems like this feature is well-received and folks cite it to show how well Pkg handles multiple registries.

Not because of the interactive selector in the rare case of a name collision though?

KristofferC avatar Oct 18 '21 09:10 KristofferC

Not because of the interactive selector in the rare case of a name collision though?

Yeah, because of that.

That should probably be removed as well and be replaced with a nice error message instead.

That sounds super unfriendly to anyone who actually uses it currently.

ericphanson avatar Oct 18 '21 10:10 ericphanson

Ok, well I've pushed a commit to remove the interactive stuff and instead choose the repo based on where the latest version of the code lives-- since adding by branch and deving are both used for in-development code (not old code), I think this is the right choice.

If this is acceptable, please let me know how to do the tests so we don't need to test internals here. Pkg doesn't seem to have any kind of mocking set up and I don't really want to create more repos to access over the network during tests, so I'm not sure how to do that.

ericphanson avatar Oct 18 '21 10:10 ericphanson

That seems like a good idea to me at least.

KristofferC avatar Oct 18 '21 12:10 KristofferC