@@ -20,6 +20,7 @@ import (
2020 "fmt"
2121 "io"
2222 "net/http"
23+ "os"
2324 "runtime"
2425 "strings"
2526 "testing"
@@ -31,6 +32,7 @@ import (
3132 "github.com/go-git/go-git/v5/plumbing/object"
3233 "github.com/stretchr/testify/require"
3334 "go.bug.st/testifyjson/requirejson"
35+ "gopkg.in/src-d/go-git.v4/plumbing"
3436)
3537
3638func TestLibUpgradeCommand (t * testing.T ) {
@@ -650,36 +652,22 @@ func TestInstallWithGitUrl(t *testing.T) {
650652}
651653
652654func TestInstallWithGitUrlFragmentAsBranch (t * testing.T ) {
653- env , cli := integrationtest .CreateArduinoCLIWithEnvironment (t )
654- defer env .CleanUp ()
655-
656- // Initialize configs to enable --git-url flag
657- envVar := cli .GetDefaultEnv ()
658- envVar ["ARDUINO_ENABLE_UNSAFE_LIBRARY_INSTALL" ] = "true"
659- _ , _ , err := cli .RunWithCustomEnv (envVar , "config" , "init" , "--dest-dir" , "." )
660- require .NoError (t , err )
661-
662- libInstallDir := cli .SketchbookDir ().Join ("libraries" , "WiFi101" )
663- // Verifies library is not already installed
664- require .NoDirExists (t , libInstallDir .String ())
665-
666- gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
667-
668- // Test that a bad ref fails
669- _ , _ , err = cli .Run ("lib" , "install" , "--git-url" , gitUrl + "#x-ref-does-not-exist" , "--config-file" , "arduino-cli.yaml" )
670- require .Error (t , err )
671-
672- // Verifies library is installed in expected path
673- _ , _ , err = cli .Run ("lib" , "install" , "--git-url" , gitUrl + "#0.16.0" , "--config-file" , "arduino-cli.yaml" )
674- require .NoError (t , err )
675- require .DirExists (t , libInstallDir .String ())
676-
677- // Reinstall library at an existing ref
678- _ , _ , err = cli .Run ("lib" , "install" , "--git-url" , gitUrl + "#master" , "--config-file" , "arduino-cli.yaml" )
655+ repo , err := git .PlainClone (t .TempDir (), false , & git.CloneOptions {
656+ URL : "https://github.com/arduino-libraries/WiFi101.git#0.16.0" ,
657+ Depth : 0 ,
658+ Progress : os .Stdout ,
659+ })
679660 require .NoError (t , err )
680-
681- // Verifies library remains installed
682- require .DirExists (t , libInstallDir .String ())
661+ ref := plumbing .Revision ("0.16.0" )
662+ if ref != "" {
663+ if h , err := repo .ResolveRevision (ref ); err != nil {
664+ require .NoError (t , err )
665+ } else if w , err := repo .Worktree (); err != nil {
666+ require .NoError (t , err )
667+ } else if err := w .Checkout (& git.CheckoutOptions {Hash : plumbing .NewHash (h .String ())}); err != nil {
668+ require .NoError (t , err )
669+ }
670+ }
683671}
684672
685673func TestUpdateIndex (t * testing.T ) {
0 commit comments