From 1699e6e99dce0ad1332fdbeb7e51be6917e6a037 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 9 May 2021 14:12:17 -0700 Subject: [PATCH 1/2] Use arduino-libraries/ArduinoCloud for Git integration tests In order to be effective for testing, the repository should have the following properties: - Must not contain any non-compliant releases, which would cause a spurious test failure. For this reason, an archived repository was chosed to avoid test breakage from future releases. - Should contain both lightweight and annotated tags. --- libraries/git_integration_test.go | 2 +- libraries/testdata/git_only_servo.txt | 1 - libraries/testdata/git_test_repo.txt | 3 +++ 3 files changed, 4 insertions(+), 2 deletions(-) delete mode 100644 libraries/testdata/git_only_servo.txt create mode 100644 libraries/testdata/git_test_repo.txt diff --git a/libraries/git_integration_test.go b/libraries/git_integration_test.go index 6b9df961..a0f1ea34 100644 --- a/libraries/git_integration_test.go +++ b/libraries/git_integration_test.go @@ -12,7 +12,7 @@ import ( ) 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) 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 From 5970dc169716fdb7f7bc24acb0d2ba8bb41a3ad2 Mon Sep 17 00:00:00 2001 From: per1234 Date: Sun, 9 May 2021 14:16:00 -0700 Subject: [PATCH 2/2] Support releases from annotated tags Annotated tags have their own hash, different from the commit hash, so the tag must be resolved before checkout. --- libraries/git_integration_test.go | 6 +++++- sync_libraries.go | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/libraries/git_integration_test.go b/libraries/git_integration_test.go index a0f1ea34..c6134c17 100644 --- a/libraries/git_integration_test.go +++ b/libraries/git_integration_test.go @@ -8,6 +8,7 @@ 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" ) @@ -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/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) }