完 Safely clean up your local branches

Overview

gh poi

CI codecov

A gh extension for deleting merged local branches.

This extension checks the state of remote pull requests, so it works even when you "Squash and merge" pull requests.

demo

Installation

gh extension install seachicken/gh-poi

Usage

  • gh poi Delete the merged local branches
  • gh poi --check You can check the branch to be deleted without actually deleting it

Local branch to be deleted

  • Branches merged in the origin repository
  • Branches merged in the upstream repository
Issues
  • Does not work when merging PRs with

    Does not work when merging PRs with "Merge pull request"

    I have 18 local branches and 8 remote branches, every single one (except main) having been merged into main via a pull request.

    When I run gh poi in the repo, all branches show in Not deleted branches and nothing is deleted.

    It is a public organization repo for an organization including only me. I have confirmed all other gh commands and extensions work as designed.

    Your Environment

    • OS: macOS Monterey 12.3.1
    • gh (Check with gh --version): 2.7.0
    • gh-poi (For gh v2.6+ check with gh extension list): 0.4.0
    bug 
    opened by thehedgefrog 6
  • `panic: runtime error: index out of range [0] with length 0`

    `panic: runtime error: index out of range [0] with length 0`

    Describe the bug

    (synapse) [email protected]:~/dev/synapse$ gh poi
     Fetching pull requests...panic: runtime error: index out of range [0] with length 0
    
    goroutine 1 [running]:
    main.isFullyMerged({0x0, {0xc0000b631a, 0x7}, {0x62e8d0, 0x0, 0x0}, {0xc00021c480, 0x1, 0x1}, 0x0}, ...)
            /home/runner/work/gh-poi/gh-poi/poi.go:311 +0xe5
    main.getDeleteStatus({0x0, {0xc0000b631a, 0x7}, {0x62e8d0, 0x0, 0x0}, {0xc00021c480, 0x1, 0x1}, 0x0}, ...)
            /home/runner/work/gh-poi/gh-poi/poi.go:295 +0x158
    main.checkDeletion({0xc0000d5500, 0x53, 0xa}, {0xc000190030, 0x25})
            /home/runner/work/gh-poi/gh-poi/poi.go:275 +0x11e
    main.GetBranches({0x547f10, 0x62e8d0}, 0x0)
            /home/runner/work/gh-poi/gh-poi/poi.go:120 +0x24d
    main.runMain(0x0)
            /home/runner/work/gh-poi/gh-poi/main.go:42 +0x165
    main.main()
            /home/runner/work/gh-poi/gh-poi/main.go:26 +0xbb
    

    I'm not entirely sure how to fetch more information, please suggest me git commands to run to gain more info.

    Your Environment

    • OS: PopOS 21.10
    • gh --version: gh version 2.4.0 (2021-12-21)
    opened by ShadowJonathan 6
  • Avoid shadowing `exec.Command` errors

    Avoid shadowing `exec.Command` errors

    Before:

    • The underlying cmd.Start() error was not reported in the wrapped error message
    • The error from cmd.Wait() was swallowed
    • The presence of stderr output was interpreted as command failure
    • execabs package was used for security

    Now:

    • Start() + Wait() are replaced with cmd.Run()
    • The Run() error is wrapped but not swallowed
    • Process exit status is used as indicator of failure instead of the contents of stderr
    • safeexec package is used to allow relative PATH entries
    opened by mislav 3
  • Fails to delete checked out PR branch when PR HEAD branch is named same as default branch

    Fails to delete checked out PR branch when PR HEAD branch is named same as default branch

    Describe the bug

    Given a PR like this which is raised against the develop branch, from the develop branch of a fork, gh pr checkout 1781 creates the c-steindl/develop branch locally. Running gh poi after merging the PR does not delete this branch.

    Your Environment

    • OS: Linux Mint 20.3
    • gh --version: gh version 2.5.1 (1980-01-01)
    opened by msfjarvis 3
  • PRs in forked repository is not associated when local has multiple remotes

    PRs in forked repository is not associated when local has multiple remotes

    Describe the bug If the remotes looks like this: git remote -v

    origin  [email protected]:seachicken/a.git (fetch)
    origin  [email protected]:seachicken/a.git (push)
    upstream        [email protected]:upstream/a.git (fetch)
    upstream        [email protected]:upstream/a.git (push)
    

    PRs in origin are not shown in the results of gh poi.

    Your Environment

    • OS: macOS Monterey
    • gh --version: 2.5.0
    opened by seachicken 3
  • Delete checked out PR branches

    Delete checked out PR branches

    Description When a PR branch is currently checked out, gh-poi will not delete the branch. A way to fix this would be to checkout the default branch and then delete the branch.

    Additional context

    hub-sync implemented this same functionality and the way I described above is how this tool dealt with the problem.

    opened by msfjarvis 3
  • fails when directory has unreadable files

    fails when directory has unreadable files

    $ gh poi --dry-run
    == DRY RUN ==
     Fetching pull requests...
    failed to run external command: git, args: [status --short]
    warning: could not open directory '_many_modules/': Permission denied
    

    Where _many_modules is a directory I had removed permissions to, i.e. chmod a-rwx _many_modules

    git status returns with exit code 0 in this case, but it does print that warning to stderr.

    Your Environment

    • OS: Ubuntu 21.10
    • gh: 2.10.1
    • gh-poi: v0.5.2
    bug 
    opened by keturn 2
  • GH Poi does not work with multiple github account workaround

    GH Poi does not work with multiple github account workaround

    Description Bear with me, as this is half way between a bug report and a feature request. I am also willing to help 'fix' this, if given some pointers on where and how.

    I like the extension, and would love to use it more, however... If you have used the strategy to handle multiple github accounts (a version of which is here), you potentially have a non-resolving domain in your remotes somewhere, along the lines of [email protected]:me/blah.git. The hack in the .ssh/config file turns this back into github.com, and everything is good as far as git goes (and the correct identity/ssh key gets used)

    However, of course this doesn't work in gh-poi:

    == DRY RUN ==
     Fetching pull requests...
    failed to run external command: gh
    error connecting to github.com-work
    check your internet connection or https://githubstatus.com
    

    I'm not entirely sure what I am suggesting here. Something along the lines of: If its an ssh type remote, then check ~/.ssh/config for a remapping?

    I'm not entirely sure. I do know, however, that I am not the only person who uses this method, so thought I would open a conversation on it.

    Additional context

    None that I can think of.

    opened by UbiquitousPhoton 2
  • Fix regex to match HTTPS as well for getHostname

    Fix regex to match HTTPS as well for getHostname

    Currently, GitHub has two types of URLs: one is SSH, another is HTTPS. The getHostname function seems not to support HTTPS URL; therefore, gh-poi panics due to no matches in case of using HTTPS URL.

     Fetching pull requests... panic: runtime error: index out of range [1] with length 0
    
    goroutine 1 [running]:
    main.getHostname({0x1400017a000, 0x6f})
            /home/runner/work/gh-poi/gh-poi/poi.go:106 +0xc4
    main.GetBranches({0x100dc2d18, 0x100ea22f0})
            /home/runner/work/gh-poi/gh-poi/poi.go:67 +0x5c
    main.main()
            /home/runner/work/gh-poi/gh-poi/main.go:38 +0x278
    

    This PR brings a new regex that matches also HTTPS. You can check it out on regex101.com.

    • Previous implementation: https://regex101.com/r/7pJr9R/1
    • This change: https://regex101.com/r/PmJR16/1
    opened by ken-matsui 2
  • Support for newlines in Windows

    Support for newlines in Windows

    Does not run "gh poi" on Windows.

    PS C:\Users\seito\git\GitHub\can> gh poi --dry-run
    == DRY RUN ==
     Fetching pull requests...
    /seachicken/can --json owner --json name --json parent --json defaultBranchRef]
    parse "https://github.com\r/api/graphql": net/url: invalid control character in URL
    

    "\r\n" was not being parsed, so it was fixed.

    opened by seachicken 1
  • Fix

    Fix "Merge pull request" to delete merged PRs

    Fixes #40

    The PR was excluded from the deletion target due to a change in the process of linking PRs and branches, which has been corrected. Related PR: https://github.com/seachicken/gh-poi/pull/24

    opened by seachicken 1
Releases(v0.5.5)
Owner
Seito Tanaka
Seito Tanaka
Branch is a small CLI tool to automatically create git branches based on tickets

________ ________ ________ ________ ________ ___ ___ |\ __ \ |\ __ \ |\ __ \ |\ ___ \ |\ ___

Maikel Veen 3 Jan 14, 2022
Github-org-diff - Simple CLI tool to check a diff between 2 branches of all org repos

github-org-diff Simple CLI tool to list org repos that have diff between dev and

Alex Pliutau 1 Jan 25, 2022
F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely. Written in Go!

F2 is a cross-platform command-line tool for batch renaming files and directories quickly and safely.

Ayooluwa 473 Jun 26, 2022
The Keel CLI allows you to setup Keel on your local dev machine or on a Kubernetes cluster

keel-cli What is keel-cli The Keel CLI allows you to setup Keel on your local dev machine or on a Kubernetes cluster, launches and manages Keel instan

null 0 Oct 7, 2021
The Dapr CLI allows you to setup Dapr on your local dev machine or on a Kubernetes cluster

Dapr CLI The Dapr CLI allows you to setup Dapr on your local dev machine or on a

null 1 Dec 23, 2021
A CLI tool to find the absolute path of any folder in your local file system.

Table of Contents What is this? How to use this Examples of usage How to compile it What am I looking at It's a CLI tool that I made for finding the a

Benyakir Horowitz 0 Jan 15, 2022
go-editor is the clean go module that refractors from Kubernetes to help you edit resources in a command-line way.

go-editor The source code of go-editor comes from Kubernetes and refractor as the clean Go module. You can embed go-editor in your command-line tool l

Yong 0 Dec 5, 2021
Onion-Layer-Golang - A web application boilerplate built with go and clean architecture

go-clean-architecture-web-application-boilerplate A web application boilerplate

Endy Gigih Pratama 1 May 4, 2022
Are you programming and suddenly your stomach is rumbling? No problem, order your Ifood without leaving your favorite text editor 歹

vim-ifood Voc礙 ta programando e de repente bateu aquela fome? Sem problemas, pe癟a seu Ifood sem sair do seu editor de texto favorito 歹 Are you progra

Felipe Volpone 4 Jun 2, 2022
A small CLI tool to check connection from a local machine to a remote target in various protocols.

CHK chk is a small CLI tool to check connection from a local machine to a remote target in various protocols.

null 25 Mar 30, 2022
A flexible commandline tool for template rendering. Supports lots of local and remote datasources.

Read the docs at docs.gomplate.ca, chat with developers and community in the #gomplate channel on Gophers Slack gomplate is a template renderer which

Dave Henderson 1.8k Jun 20, 2022
a command line tool for syncing a local directory to wnfs

wnfs-sync demo demo CLI application to syncronize a local filesystem directory to a public web-native file system directory. # get this binary, assume

Brendan O'Brien 7 Mar 28, 2022
A Go library and common interface for running local and remote commands

go-runcmd go-runcmd is a Go library and common interface for running local and remote commands providing the Runner interface which helps to abstract

AUCloud 1 Nov 25, 2021
Testing local and remote shell commands in Go

Testing local and remote shell commands in Go. This is an (intentionally simplified) example of how unix shell commands can be unit-tested in Go. The

Anton 5 Nov 30, 2021
K8s local storage sync for stateful set's using microk8s-hostpath storage classe

Local Storage Sync for microk8s-hostpath The goal is to be able to sync stateful sets between the different nodes of a cluster to allow the data to be

Paulo Ferreira 0 Jan 7, 2022
Sync local file/directory to pod volume

Sync local file/directory to pod volume

null 0 Mar 19, 2022
Godbolt console wrapper for easily execute local file without any security risk and compiler.

Godbolt CLI Godbolt console wrapper for easily execute local file without any security risk and compiler. Install Compile the source code and add to y

aiocat 1 May 22, 2022
Display a message in morse code on your capslock LED, keyboard backlight or using your screen brightness!

halp halp is a command line utility that lets you display messages in morse code on your capslock LED, keyboard backlight (if you have it) or using yo

Madhav Jivrajani 25 Jan 26, 2022
Lightweight CLI tool to programmatically rescale your Hetzner virtual server daily to optimize your budget spending

Lightweight CLI tool to programmatically rescale your Hetzner virtual server daily to optimize your budget spending

Jonathan Mataloni 43 Jun 1, 2022