Disallow installing extensions with same name as gh command

This commit is contained in:
Sam Coe 2021-07-01 13:45:29 -07:00
parent a6710ec506
commit 103e18cab5
No known key found for this signature in database
GPG key ID: 8E322C20F811D086

View file

@ -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