diff --git a/libraries/git_integration_test.go b/libraries/git_integration_test.go index 6b9df961..c6134c17 100644 --- a/libraries/git_integration_test.go +++ b/libraries/git_integration_test.go @@ -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) @@ -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) diff --git a/libraries/testdata/git_only_servo.txt b/libraries/testdata/git_only_servo.txt deleted file mode 100644 index 08394ea9..00000000 --- a/libraries/testdata/git_only_servo.txt +++ /dev/null @@ -1 +0,0 @@ -https://github.com/arduino-libraries/Servo.git|Arduino|Servo diff --git a/libraries/testdata/git_test_repo.txt b/libraries/testdata/git_test_repo.txt new file mode 100644 index 00000000..220b7198 --- /dev/null +++ b/libraries/testdata/git_test_repo.txt @@ -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 diff --git a/sync_libraries.go b/sync_libraries.go index dd6fa25d..184fbcfa 100644 --- a/sync_libraries.go +++ b/sync_libraries.go @@ -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) }