Skip to content

Commit f9c8b24

Browse files
unknownstefanotorneo
authored andcommitted
fix InstallGitLib
1 parent 623ad45 commit f9c8b24

File tree

1 file changed

+16
-25
lines changed

1 file changed

+16
-25
lines changed

‎arduino/libraries/librariesmanager/install.go‎

Lines changed: 16 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -235,37 +235,28 @@ func (lm *LibrariesManager) InstallGitLib(gitURL string, overwrite bool) error {
235235
WithField("git url", gitURL).
236236
Trace("Installing library")
237237

238-
depth := 1
239-
if ref != "" {
240-
depth = 0
241-
}
242-
repo, err := git.PlainClone(installPath.String(), false, &git.CloneOptions{
243-
URL: gitURL,
244-
Depth: depth,
245-
Progress: os.Stdout,
238+
_, err = git.PlainClone(installPath.String(), false, &git.CloneOptions{
239+
URL: gitURL,
240+
ReferenceName: plumbing.ReferenceName(ref),
246241
})
247242
if err != nil {
248-
logrus.
249-
WithError(err).
250-
Warn("Cloning git repository")
251-
return err
252-
}
243+
if err.Error() != "reference not found" {
244+
return err
245+
}
253246

254-
if ref != "" {
255-
if h, err := repo.ResolveRevision(plumbing.Revision(ref)); err != nil {
256-
logrus.
257-
WithError(err).
258-
Warnf("Resolving revision %s", ref)
247+
// We did not find the requested reference, let's do a PlainClone and use
248+
// "ResolveRevision" to find and checkout the requested revision
249+
if repo, err := git.PlainClone(installPath.String(), false, &git.CloneOptions{
250+
URL: gitURL,
251+
}); err != nil {
252+
return err
253+
} else if h, err := repo.ResolveRevision(plumbing.Revision(ref)); err != nil {
259254
return err
260255
} else if w, err := repo.Worktree(); err != nil {
261-
logrus.
262-
WithError(err).
263-
Warn("Finding worktree")
264256
return err
265-
} else if err := w.Checkout(&git.CheckoutOptions{Hash: plumbing.NewHash(h.String())}); err != nil {
266-
logrus.
267-
WithError(err).
268-
Warnf("Checking out %s", h)
257+
} else if err := w.Checkout(&git.CheckoutOptions{
258+
Force: true, // workaround for: https://github.com/go-git/go-git/issues/1411
259+
Hash: plumbing.NewHash(h.String())}); err != nil {
269260
return err
270261
}
271262
}

0 commit comments

Comments
 (0)