Skip to content

Commit 5948ee7

Browse files
authored
Merge pull request #10 from per1234/annotated-tags
Support releases from annotated tags
2 parents 5be452c + 5970dc1 commit 5948ee7

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

libraries/git_integration_test.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,12 @@ import (
88

99
"arduino.cc/repository/libraries/db"
1010
"github.com/go-git/go-git/v5"
11+
"github.com/go-git/go-git/v5/plumbing"
1112
"github.com/stretchr/testify/require"
1213
)
1314

1415
func TestUpdateLibraryJson(t *testing.T) {
15-
repos, err := ListRepos("./testdata/git_only_servo.txt")
16+
repos, err := ListRepos("./testdata/git_test_repo.txt")
1617

1718
require.NoError(t, err)
1819
require.NotNil(t, repos)
@@ -41,7 +42,10 @@ func TestUpdateLibraryJson(t *testing.T) {
4142

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

4751
library, err := GenerateLibraryFromRepo(r)

libraries/testdata/git_only_servo.txt

-1
This file was deleted.

libraries/testdata/git_test_repo.txt

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Must not contain any non-compliant releases (so use an archived repo to avoid breakage).
2+
# Should contain both lightweight and annotated tags.
3+
https://github.com/arduino-libraries/ArduinoCloud.git|Arduino|ArduinoCloud

sync_libraries.go

+7-1
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,13 @@ func syncLibraryTaggedRelease(logger *log.Logger, repo *libraries.Repository, ta
234234
return err
235235
}
236236

237-
if err = repoTree.Checkout(&git.CheckoutOptions{Hash: tag.Hash()}); err != nil {
237+
// Annotated tags have their own hash, different from the commit hash, so the tag must be resolved before checkout
238+
resolvedTag, err := repo.Repository.ResolveRevision(plumbing.Revision(tag.Hash().String()))
239+
if err != nil {
240+
panic(err)
241+
}
242+
243+
if err = repoTree.Checkout(&git.CheckoutOptions{Hash: *resolvedTag}); err != nil {
238244
return fmt.Errorf("Error checking out repo: %s", err)
239245
}
240246

0 commit comments

Comments
 (0)