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

Method installGit

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

Source from the content-addressed store, hash-verified

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