+44
-34
lines changedFilter options
+44
-34
lines changed Original file line number Diff line number Diff line change
@@ -219,25 +219,15 @@ func (lmi *Installer) InstallGitLib(argURL string, overwrite bool) error {
219
219
if ref != "" {
220
220
depth = 0
221
221
}
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 {
228
228
return err
229
229
}
230
230
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
-
241
231
// We don't want the installed library to be a git repository thus we delete this folder
242
232
tmpInstallPath.Join(".git").RemoveAll()
243
233
@@ -251,7 +241,7 @@ func (lmi *Installer) InstallGitLib(argURL string, overwrite bool) error {
251
241
252
242
// parseGitArgURL tries to recover a library name from a git URL.
253
243
// 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) {
255
245
// On Windows handle paths with backslashes in the form C:\Path\to\library
256
246
if path := paths.New(argURL); path != nil && path.Exist() {
257
247
return path.Base(), argURL, "", nil
@@ -289,7 +279,7 @@ func parseGitArgURL(argURL string) (string, string, plumbing.Revision, error) {
289
279
return "", "", "", errors.New(i18n.Tr("invalid git url"))
290
280
}
291
281
// fragment == "1.0.3"
292
-
rev := plumbing.Revision(parsedURL.Fragment)
282
+
rev := plumbing.ReferenceName(parsedURL.Fragment)
293
283
// gitURL == "https://github.com/arduino-libraries/SigFox.git"
294
284
parsedURL.Fragment = ""
295
285
gitURL := parsedURL.String()
Original file line number Diff line number Diff line change
@@ -659,27 +659,47 @@ func TestInstallWithGitUrlFragmentAsBranch(t *testing.T) {
659
659
_, _, err := cli.RunWithCustomEnv(envVar, "config", "init", "--dest-dir", ".")
660
660
require.NoError(t, err)
661
661
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
+
})
665
667
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()
667
671
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)
671
674
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)
676
679
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)
680
683
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
+
})
683
703
}
684
704
685
705
func TestUpdateIndex(t *testing.T) {
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4