MCPcopy Create free account
hub / github.com/cli/cli / installGit

Method installGit

pkg/cmd/extension/manager.go:413–453  ·  view source on GitHub ↗
(repo ghrepo.Interface, target string)

Source from the content-addressed store, hash-verified

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

Callers 1

InstallMethod · 0.95

Calls 13

installDirMethod · 0.95
FormatRemoteURLFunction · 0.92
fetchCommitSHAFunction · 0.85
BaseMethod · 0.80
JoinMethod · 0.80
GitProtocolMethod · 0.65
RepoHostMethod · 0.65
CloneMethod · 0.65
ForRepoMethod · 0.65
CheckoutBranchMethod · 0.65
ErrorfMethod · 0.65

Tested by

no test coverage detected