From 103e18cab548c7a9116a0bfe139f1285f0edfa49 Mon Sep 17 00:00:00 2001 From: Sam Coe Date: Thu, 1 Jul 2021 13:45:29 -0700 Subject: [PATCH] Disallow installing extensions with same name as gh command --- pkg/cmd/extensions/command.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/pkg/cmd/extensions/command.go b/pkg/cmd/extensions/command.go index f764e22e5..7abba2586 100644 --- a/pkg/cmd/extensions/command.go +++ b/pkg/cmd/extensions/command.go @@ -80,6 +80,17 @@ func NewCmdExtensions(f *cmdutil.Factory) *cobra.Command { if !strings.HasPrefix(repo.RepoName(), "gh-") { return errors.New("the repository name must start with `gh-`") } + + commandName := strings.TrimPrefix(repo.RepoName(), "gh-") + rootCmd := cmd.Root() + c, _, err := rootCmd.Traverse([]string{commandName}) + if err != nil { + return err + } + if c != rootCmd { + return fmt.Errorf("could not install %s: %s is already a gh command", args[0], commandName) + } + cfg, err := f.Config() if err != nil { return err