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

Method installGit

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

Source from the content-addressed store, hash-verified

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