Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit bb88dc2

Browse filesBrowse files
authored
Fixed library install from git-url when reference points to a git branch (#2833)
* Added integration test * Fixed library install from git when ref points to a branch * Praise linter
1 parent a2eebcd commit bb88dc2
Copy full SHA for bb88dc2

File tree

2 files changed

+44
-34
lines changed
Filter options

2 files changed

+44
-34
lines changed

‎internal/arduino/libraries/librariesmanager/install.go

Copy file name to clipboardExpand all lines: internal/arduino/libraries/librariesmanager/install.go
+8-18Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -219,25 +219,15 @@ func (lmi *Installer) InstallGitLib(argURL string, overwrite bool) error {
219219
if ref != "" {
220220
depth = 0
221221
}
222-
repo, err := git.PlainClone(tmpInstallPath.String(), false, &git.CloneOptions{
223-
URL: gitURL,
224-
Depth: depth,
225-
Progress: os.Stdout,
226-
})
227-
if err != nil {
222+
if _, err := git.PlainClone(tmpInstallPath.String(), false, &git.CloneOptions{
223+
URL: gitURL,
224+
Depth: depth,
225+
Progress: os.Stdout,
226+
ReferenceName: ref,
227+
}); err != nil {
228228
return err
229229
}
230230

231-
if ref != "" {
232-
if h, err := repo.ResolveRevision(ref); err != nil {
233-
return err
234-
} else if w, err := repo.Worktree(); err != nil {
235-
return err
236-
} else if err := w.Checkout(&git.CheckoutOptions{Hash: plumbing.NewHash(h.String())}); err != nil {
237-
return err
238-
}
239-
}
240-
241231
// We don't want the installed library to be a git repository thus we delete this folder
242232
tmpInstallPath.Join(".git").RemoveAll()
243233

@@ -251,7 +241,7 @@ func (lmi *Installer) InstallGitLib(argURL string, overwrite bool) error {
251241

252242
// parseGitArgURL tries to recover a library name from a git URL.
253243
// Returns an error in case the URL is not a valid git URL.
254-
func parseGitArgURL(argURL string) (string, string, plumbing.Revision, error) {
244+
func parseGitArgURL(argURL string) (string, string, plumbing.ReferenceName, error) {
255245
// On Windows handle paths with backslashes in the form C:\Path\to\library
256246
if path := paths.New(argURL); path != nil && path.Exist() {
257247
return path.Base(), argURL, "", nil
@@ -289,7 +279,7 @@ func parseGitArgURL(argURL string) (string, string, plumbing.Revision, error) {
289279
return "", "", "", errors.New(i18n.Tr("invalid git url"))
290280
}
291281
// fragment == "1.0.3"
292-
rev := plumbing.Revision(parsedURL.Fragment)
282+
rev := plumbing.ReferenceName(parsedURL.Fragment)
293283
// gitURL == "https://github.com/arduino-libraries/SigFox.git"
294284
parsedURL.Fragment = ""
295285
gitURL := parsedURL.String()

‎internal/integrationtest/lib/lib_test.go

Copy file name to clipboardExpand all lines: internal/integrationtest/lib/lib_test.go
+36-16Lines changed: 36 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -659,27 +659,47 @@ func TestInstallWithGitUrlFragmentAsBranch(t *testing.T) {
659659
_, _, err := cli.RunWithCustomEnv(envVar, "config", "init", "--dest-dir", ".")
660660
require.NoError(t, err)
661661

662-
libInstallDir := cli.SketchbookDir().Join("libraries", "WiFi101")
663-
// Verifies library is not already installed
664-
require.NoDirExists(t, libInstallDir.String())
662+
t.Run("InvalidRef", func(t *testing.T) {
663+
// Test that a bad ref fails
664+
_, _, err = cli.Run("lib", "install", "--git-url", "https://github.com/arduino-libraries/WiFi101.git#x-ref-does-not-exist", "--config-file", "arduino-cli.yaml")
665+
require.Error(t, err)
666+
})
665667

666-
gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
668+
t.Run("RefPointingToATag", func(t *testing.T) {
669+
gitUrl := "https://github.com/arduino-libraries/WiFi101.git"
670+
libInstallDir := cli.SketchbookDir().Join("libraries", "WiFi101").String()
667671

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)
672+
// Verifies library is not already installed
673+
require.NoDirExists(t, libInstallDir)
671674

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())
675+
// Verifies library is installed in expected path
676+
_, _, err = cli.Run("lib", "install", "--git-url", gitUrl+"#0.16.0", "--config-file", "arduino-cli.yaml")
677+
require.NoError(t, err)
678+
require.DirExists(t, libInstallDir)
676679

677-
// Reinstall library at an existing ref
678-
_, _, err = cli.Run("lib", "install", "--git-url", gitUrl+"#master", "--config-file", "arduino-cli.yaml")
679-
require.NoError(t, err)
680+
// Reinstall library at an existing ref
681+
_, _, err = cli.Run("lib", "install", "--git-url", gitUrl+"#master", "--config-file", "arduino-cli.yaml")
682+
require.NoError(t, err)
680683

681-
// Verifies library remains installed
682-
require.DirExists(t, libInstallDir.String())
684+
// Verifies library remains installed
685+
require.DirExists(t, libInstallDir)
686+
})
687+
688+
t.Run("RefPointingToBranch", func(t *testing.T) {
689+
libInstallDir := cli.SketchbookDir().Join("libraries", "ArduinoCloud")
690+
691+
// Verify install with ref pointing to a branch
692+
require.NoDirExists(t, libInstallDir.String())
693+
_, _, err = cli.Run("lib", "install", "--git-url", "https://github.com/arduino-libraries/ArduinoCloud.git#revert-2-typos", "--config-file", "arduino-cli.yaml")
694+
require.NoError(t, err)
695+
require.DirExists(t, libInstallDir.String())
696+
697+
// Verify that the correct branch is checked out
698+
// https://github.com/arduino-libraries/ArduinoCloud/commit/d098d4647967b3aeb4520e7baf279e4225254dd2
699+
fileToTest, err := libInstallDir.Join("src", "ArduinoCloudThingBase.h").ReadFile()
700+
require.NoError(t, err)
701+
require.Contains(t, string(fileToTest), `#define LENGHT_M "meters"`) // nolint:misspell
702+
})
683703
}
684704

685705
func TestUpdateIndex(t *testing.T) {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.