Skip to content

Fixed library install from git-url when reference points to a git branch #2833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 11, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fixed library install from git when ref points to a branch
  • Loading branch information
cmaglie committed Feb 7, 2025
commit f73e3f132682aab762419ef49d1482fdf6e3021d
26 changes: 8 additions & 18 deletions internal/arduino/libraries/librariesmanager/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,25 +219,15 @@ func (lmi *Installer) InstallGitLib(argURL string, overwrite bool) error {
if ref != "" {
depth = 0
}
repo, err := git.PlainClone(tmpInstallPath.String(), false, &git.CloneOptions{
URL: gitURL,
Depth: depth,
Progress: os.Stdout,
})
if err != nil {
if _, err := git.PlainClone(tmpInstallPath.String(), false, &git.CloneOptions{
URL: gitURL,
Depth: depth,
Progress: os.Stdout,
ReferenceName: ref,
}); err != nil {
return err
}

if ref != "" {
if h, err := repo.ResolveRevision(ref); err != nil {
return err
} else if w, err := repo.Worktree(); err != nil {
return err
} else if err := w.Checkout(&git.CheckoutOptions{Hash: plumbing.NewHash(h.String())}); err != nil {
return err
}
}

// We don't want the installed library to be a git repository thus we delete this folder
tmpInstallPath.Join(".git").RemoveAll()

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

// parseGitArgURL tries to recover a library name from a git URL.
// Returns an error in case the URL is not a valid git URL.
func parseGitArgURL(argURL string) (string, string, plumbing.Revision, error) {
func parseGitArgURL(argURL string) (string, string, plumbing.ReferenceName, error) {
// On Windows handle paths with backslashes in the form C:\Path\to\library
if path := paths.New(argURL); path != nil && path.Exist() {
return path.Base(), argURL, "", nil
Expand Down Expand Up @@ -289,7 +279,7 @@ func parseGitArgURL(argURL string) (string, string, plumbing.Revision, error) {
return "", "", "", errors.New(i18n.Tr("invalid git url"))
}
// fragment == "1.0.3"
rev := plumbing.Revision(parsedURL.Fragment)
rev := plumbing.ReferenceName(parsedURL.Fragment)
// gitURL == "https://github.com/arduino-libraries/SigFox.git"
parsedURL.Fragment = ""
gitURL := parsedURL.String()
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy