MCPcopy
hub / github.com/cli/cli / installGit

Method installGit

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

Source from the content-addressed store, hash-verified

405}
406
407func (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
449var pinnedExtensionUpgradeError = errors.New("pinned extensions can not be upgraded")
450var 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