Skip to content
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