(repo ghrepo.Interface, target string)
| 405 | } |
| 406 | |
| 407 | func (m *Manager) installGit(repo ghrepo.Interface, target string) error { |
| 408 | protocol := m.config.GitProtocol(repo.RepoHost()).Value |
| 409 | cloneURL := ghrepo.FormatRemoteURL(repo, protocol) |
| 410 | |
| 411 | var commitSHA string |
| 412 | if target != "" { |
| 413 | var err error |
| 414 | commitSHA, err = fetchCommitSHA(m.client, repo, target) |
| 415 | if err != nil { |
| 416 | return err |
| 417 | } |
| 418 | } |
| 419 | |
| 420 | name := strings.TrimSuffix(path.Base(cloneURL), ".git") |
| 421 | targetDir := filepath.Join(m.installDir(), name) |
| 422 | |
| 423 | if err := m.cleanExtensionUpdateDir(name); err != nil { |
| 424 | return err |
| 425 | } |
| 426 | |
| 427 | _, err := m.gitClient.Clone(cloneURL, []string{targetDir}) |
| 428 | if err != nil { |
| 429 | return err |
| 430 | } |
| 431 | if commitSHA == "" { |
| 432 | return nil |
| 433 | } |
| 434 | |
| 435 | scopedClient := m.gitClient.ForRepo(targetDir) |
| 436 | err = scopedClient.CheckoutBranch(commitSHA) |
| 437 | if err != nil { |
| 438 | return err |
| 439 | } |
| 440 | |
| 441 | pinPath := filepath.Join(targetDir, fmt.Sprintf(".pin-%s", commitSHA)) |
| 442 | f, err := os.OpenFile(pinPath, os.O_WRONLY|os.O_CREATE, 0600) |
| 443 | if err != nil { |
| 444 | return fmt.Errorf("failed to create pin file in directory: %w", err) |
| 445 | } |
| 446 | return f.Close() |
| 447 | } |
| 448 | |
| 449 | var pinnedExtensionUpgradeError = errors.New("pinned extensions can not be upgraded") |
| 450 | var localExtensionUpgradeError = errors.New("local extensions can not be upgraded") |
no test coverage detected