fix: address verified review findings (terminal-forms-1)

Signed-off-by: bircni <bircni@icloud.com>
This commit is contained in:
bircni committed 2026-10-18 17:42:24 +02:00
1 parent caeed59bc6
commit 0910cf307a
21 files changed
+329 -53

No files matched your search

+17
View File
@@ -119,6 +119,11 @@ is not on the remote yet is pushed first, with its upstream set.`, Args: argsExa
if web {
return a.openBrowser(cmd, repositoryURL(t)+"/compare/"+compareRef(options.Base)+"..."+compareRef(options.Head))
}
if !agit {
if err := refuseSameBranch(options.Head, options.Base); err != nil {
return err
}
}
var commitBody string
if options.Title == "" {
if subject, body, ok := a.singleCommitMessage(cmd.Context(), options.Base, options.Head); ok {
@@ -307,6 +312,15 @@ func (a *application) singleCommitMessage(ctx context.Context, base, head string
return subject, body, subject != ""
}
// refuseSameBranch rejects a head that is the base branch of the same repository, before anything
// is pushed: such a pull request has no commits, and pushing would publish the base branch itself.
func refuseSameBranch(head, base string) error {
if head != "" && head == base {
return clierr.Wrap(clierr.Usage, fmt.Errorf("must be on a branch named differently than %q; create a branch or pass --head", base))
}
return nil
}
func (a *application) createPullInteractively(cmd *cobra.Command, snapshot settings.Snapshot) (runErr error) {
target, err := a.resolve(cmd.Context(), true)
if err != nil {
@@ -359,6 +373,9 @@ func (a *application) createPullInteractively(cmd *cobra.Command, snapshot setti
Labels: values.Labels, Deadline: values.Deadline, Base: values.Base, Head: values.Head,
AllowMaintainerEdit: &values.AllowMaintainerEdits,
}
if err := refuseSameBranch(options.Head, options.Base); err != nil {
return err
}
if err := a.ensureHeadPublished(cmd, target, snapshot, options.Head); err != nil {
return err
}