Skip to content

Support releases from annotated tags #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions libraries/git_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ import (

"arduino.cc/repository/libraries/db"
"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/stretchr/testify/require"
)

func TestUpdateLibraryJson(t *testing.T) {
repos, err := ListRepos("./testdata/git_only_servo.txt")
repos, err := ListRepos("./testdata/git_test_repo.txt")

require.NoError(t, err)
require.NotNil(t, repos)
Expand Down Expand Up @@ -41,7 +42,10 @@ func TestUpdateLibraryJson(t *testing.T) {

repoTree, err := r.Repository.Worktree()
require.NoError(t, err)
err = repoTree.Checkout(&git.CheckoutOptions{Hash: tag.Hash()})
// Annotated tags have their own hash, different from the commit hash, so the tag must be resolved before checkout
resolvedTag, err := r.Repository.ResolveRevision(plumbing.Revision(tag.Hash().String()))
require.NoError(t, err)
err = repoTree.Checkout(&git.CheckoutOptions{Hash: *resolvedTag})
require.NoError(t, err)

library, err := GenerateLibraryFromRepo(r)
Expand Down
1 change: 0 additions & 1 deletion libraries/testdata/git_only_servo.txt

This file was deleted.

3 changes: 3 additions & 0 deletions libraries/testdata/git_test_repo.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Must not contain any non-compliant releases (so use an archived repo to avoid breakage).
# Should contain both lightweight and annotated tags.
https://github.com/arduino-libraries/ArduinoCloud.git|Arduino|ArduinoCloud
8 changes: 7 additions & 1 deletion sync_libraries.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,13 @@ func syncLibraryTaggedRelease(logger *log.Logger, repo *libraries.Repository, ta
return err
}

if err = repoTree.Checkout(&git.CheckoutOptions{Hash: tag.Hash()}); err != nil {
// Annotated tags have their own hash, different from the commit hash, so the tag must be resolved before checkout
resolvedTag, err := repo.Repository.ResolveRevision(plumbing.Revision(tag.Hash().String()))
if err != nil {
panic(err)
}

if err = repoTree.Checkout(&git.CheckoutOptions{Hash: *resolvedTag}); err != nil {
return fmt.Errorf("Error checking out repo: %s", err)
}

Expand Down