seachicken / gh-poi

✨ Safely clean up your local branches
https://dev.to/seachicken/safely-clean-up-your-local-branches-9i3
MIT License
685 stars 19 forks source link

Protected Branches #92

Closed KyleKing closed 1 year ago

KyleKing commented 1 year ago

Description

We use a git branching strategy to have our branches mirror deployment environments (Stage and Prod). Because we merge code between the branches, poi deletes these protected branches locally and checks out main, but I don't want to switch to main if Prod is currently checked out.

Could there be a command line option to ignore certain branches following a regex or string? Something like one of:

gh poi -keep stage -keep prod
# or
gh poi -keep "stage|prod"
seachicken commented 1 year ago

Thanks for the suggestion! If the branch you don't want to delete is always local, it seems easy to make a mistake typing a long command each time.

How about persisting the branch locally to protect once you run the command, like gh poi protect stage prod, and not deleting the branch until you run gh poi unprotect stage prod? (persist in .git/config like gh https://github.com/cli/cli/blob/ba27e5bfb88bab29021ae0eace03348e41f0b24f/git/client.go#L118)

KyleKing commented 1 year ago

That's a good idea and works for me!

Should there be a command to list all protected branches? Maybe "gh poi protect" with no arguments?

seachicken commented 1 year ago

I am thinking of displaying the reasons for non-deletion in the gh poi results (could be used to display reasons for non-deletion other than protect)

gh poi --dry-run

Deleted branches
  issue2
    └─ #2  https://github.com/owner/repo/pull/2 seachicken

Branches not deleted
  prod [protected] <- here
    └─ #1  https://github.com/owner/repo/pull/1 seachicken
seachicken commented 1 year ago

I just released v0.9.0! You can try gh ext upgrade poi, then gh poi protect stage prod.

KyleKing commented 1 year ago

I updated, and the feature works, thanks!