Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh pr merge --auto -d does not delete the branch after merge #9073

Open
arcivanov opened this issue May 12, 2024 · 3 comments
Open

gh pr merge --auto -d does not delete the branch after merge #9073

arcivanov opened this issue May 12, 2024 · 3 comments
Labels
bug Something isn't working gh-pr relating to the gh pr command p3 Affects a small number of users or is largely cosmetic

Comments

@arcivanov
Copy link

Describe the bug

A successful gh pr merge --auto -d does not delete the branch after a successful merge. It's unclear whether it's GH CLI problem or GH API.

Steps to reproduce the behavior

The PR in question that didn't have a branch auto-deleted is here: karellen/karellen-llvm#40
The branch was marked for auto-merge and auto-delete here: https://github.com/karellen/karellen-llvm/actions/runs/9048046223/job/24860694266#step:4:62 (line 61)

If this is not something that can be fixed in GH CLI and GH API the documentation update is necessary to note that it's not an expected behavior.

Expected vs actual behavior

Expected: PR auto-merge will be followed by auto-delete if delete is requested.
Actual: The PR is automatically merged but the branch remains.

Logs

Above in the action items.

@arcivanov arcivanov added the bug Something isn't working label May 12, 2024
@cliAutomation cliAutomation added the needs-triage needs to be reviewed label May 12, 2024
@williammartin
Copy link
Member

williammartin commented May 12, 2024

Reading the code this is intentional behaviour when you provide --auto because as far as I know there is no way to tell the API to remember to delete the branch when the PR is automatically merged.

if !m.deleteBranch || m.crossRepoPR || m.autoMerge {
return nil
}

However, it's not clear to me why we allow both of these flags to be provided at the same time if this is the behaviour, instead of erroring and saying "you can't do that". This seems to have been the behaviour since the --auto flag was introduced. I agree with you that it is confusing.

@andyfeller andyfeller added the gh-pr relating to the gh pr command label May 16, 2024
@andyfeller
Copy link
Contributor

Is the suggestion that we need to fail early if these confliction options are specified?

Reviewing the code, I see we have other places we're checking for mutually exclusive options:

if err := cmdutil.MutuallyExclusive(
"specify only one of `--auto`, `--disable-auto`, or `--admin`",
opts.AutoMergeEnable,
opts.AutoMergeDisable,
opts.UseAdmin,
); err != nil {
return err
}

Reading through the rest of the code, m.deleteBranch is not derived directly from options:

func deleteBranchSurvey(opts *MergeOptions, crossRepoPR, localBranchExists bool) (bool, error) {
if !opts.IsDeleteBranchIndicated {
var message string
if opts.CanDeleteLocalBranch && localBranchExists {
if crossRepoPR {
message = "Delete the branch locally?"
} else {
message = "Delete the branch locally and on GitHub?"
}
} else if !crossRepoPR {
message = "Delete the branch on GitHub?"
}
return opts.Prompter.Confirm(message, false)
}
return opts.DeleteBranch, nil
}

@andyfeller andyfeller added p3 Affects a small number of users or is largely cosmetic and removed needs-triage needs to be reviewed labels May 16, 2024
@williammartin
Copy link
Member

Is the suggestion that we need to fail early if these confliction options are specified?

Yes, I can't see any reason that we would want to proceed in this case. I can't see any code path that would allow for the branch to be deleted if --auto is provided.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working gh-pr relating to the gh pr command p3 Affects a small number of users or is largely cosmetic
Projects
None yet
Development

No branches or pull requests

5 participants
@williammartin @andyfeller @arcivanov @cliAutomation and others