yonaskolb / Mint

A package manager that installs and runs executable Swift packages
MIT License
2.26k stars 122 forks source link

Add support for `main` as the default branch #204

Open rastersize opened 3 years ago

rastersize commented 3 years ago

GitHub and others are moving to use main as the default branch name. In fact newly created repositories use it by default now. The most recent version/commit of Mint fails to clone tools that don’t have any tags and uses main:

$ mint run rastersize/apollo-codegen
🌱 Finding latest version of apollo-codegen
🌱 Cloning apollo-codegen master
Cloning into 'github.com_rastersize_apollo-codegen'...
warning: Could not find remote branch master to clone.
fatal: Remote branch master not found in upstream origin
🌱 Encountered error during "git clone --depth 1 -b master https://github.com/rastersize/apollo-codegen.git github.com_rastersize_apollo-codegen". Use --verbose to see full output
🌱  Couldn't clone https://github.com/rastersize/apollo-codegen.git master

This PR aims to resolve that by adding support for both main and master. It should in theory support any name for the default branch as it uses git to look up the name of the branch.

With this patch the invocation above succeeds:

$ .build/debug/mint run rastersize/apollo-codegen apollo-codegen --help
🌱 Finding latest version of apollo-codegen
🌱 Cloning apollo-codegen main
🌱 Resolving package
🌱 Building package
🌱 Installed apollo-codegen main
🌱 Running apollo-codegen main...
OVERVIEW: A utility for performing Apollo GraphQL related tasks.

[...]
rastersize commented 3 years ago

Heya @yonaskolb! Just wanted to check if you had time to look at this, or had any comments/questions about it. Thank you πŸ™‚