From b8c46a4a6d54352b743bdbc47d7247dc2e50cb99 Mon Sep 17 00:00:00 2001 From: Buck Assistant Date: Wed, 13 May 2026 01:48:05 +0200 Subject: [PATCH] fix(repo-edit): return error when changing visibility of a fork --- pkg/cmd/repo/edit/edit.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/pkg/cmd/repo/edit/edit.go b/pkg/cmd/repo/edit/edit.go index aff7a5fe188..a023f5068f1 100644 --- a/pkg/cmd/repo/edit/edit.go +++ b/pkg/cmd/repo/edit/edit.go @@ -181,6 +181,17 @@ func NewCmdEdit(f *cmdutil.Factory, runF func(options *EditOptions) error) *cobr return cmdutil.FlagErrorf("use of --visibility flag requires --accept-visibility-change-consequences flag") } + if opts.Edits.Visibility != nil && !opts.InteractiveMode { + apiClient := api.NewClientFromHTTP(opts.HTTPClient) + repo, err := api.FetchRepository(apiClient, opts.Repository, []string{"isFork"}) + if err != nil { + return err + } + if repo.IsFork { + return fmt.Errorf("changing visibility of a forked repository is not supported") + } + } + if opts.Edits.squashMergeCommitMsg != nil { if opts.Edits.EnableSquashMerge == nil { return cmdutil.FlagErrorf("--squash-merge-commit-message requires --enable-squash-merge") @@ -257,6 +268,7 @@ func editRun(ctx context.Context, opts *EditOptions) error { // TODO: GitHub Enterprise Server does not support has_discussions yet // "hasDiscussionsEnabled", "homepageUrl", + "isFork", "isInOrganization", "isTemplate", "mergeCommitAllowed", @@ -453,6 +465,9 @@ func interactiveRepoEdit(opts *EditOptions, r *api.Repository) error { } opts.Edits.EnableProjects = &a case optionVisibility: + if r.IsFork { + return fmt.Errorf("changing visibility of a forked repository is not supported") + } cs := opts.IO.ColorScheme() fmt.Fprintf(opts.IO.ErrOut, "%s Danger zone: changing repository visibility can have unexpected consequences; consult https://gh.io/setting-repository-visibility before continuing.\n", cs.WarningIcon())