Skip to content

Commit

Permalink
Try to clone 'main' first. (#13)
Browse files Browse the repository at this point in the history
The git-library doesn't support cloning repositories that use 'main' as
default branch: go-git/go-git#363

We therefore try 'main', 'master' and 'trunk'.

Until now we tried 'master' first, but since the Toit registry already
uses 'main' that leads to an unnecessary clone-attempt. It also allows a
race condition where another toit.pkg command could try to pull the
'master' branch.
  • Loading branch information
floitsch committed Jan 31, 2022
1 parent 234a7f8 commit 2b63ba5
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion pkg/tpkg/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,11 @@ func (gr *gitRegistry) Load(ctx context.Context, sync bool, cache Cache, ui UI)
url := gr.url

var err error
for _, branch := range []string{"master", "main", "trunk"} {
// The go-git library doesn't support cloning repositories that use 'main' as
// default branch: https://github.com/go-git/go-git/issues/363
// We therefore try different ones.
// It's advantageous to try the correct one first.
for _, branch := range []string{"main", "master", "trunk"} {
_, err = git.Clone(ctx, p, git.CloneOptions{
URL: url,
SingleBranch: true,
Expand Down

0 comments on commit 2b63ba5

Please sign in to comment.