🧹 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
Comments
  • Failed to run external command: git, args: [branch --merged origin/]

    Failed to run external command: git, args: [branch --merged origin/]

    Describe the bug When I install this extension and try to run it with gh poi --dry-run, I receive the following output:

    » gh poi --dry-run
    == DRY RUN ==
    ✕ Fetching pull requests...
    failed to run external command: git, args: [branch --merged origin/]
    exit status 128
    

    Your Environment

    • OS: macOS 12.6
    • gh (Check with gh --version): 2.18.0
    • gh-poi (Check with gh ext ls): v0.6.3
    • git: 2.37.0 (Apple Git-136)

    This seems to be the case regardless of which repo I run it in.

    If I run git branch --merged origin or git branch --merged origin/, I get this output:

    fatal: malformed object name origin
    

    I'm not sure how to further debug this, but I'm happy to help however I can!

    opened by tnorthcutt 17
  • Fix/comma containg branch name

    Fix/comma containg branch name

    close #70

    • #70

    In getting branch, here: https://github.com/seachicken/gh-poi/blob/b9f2295afad1e175d8cb5fffa20d1d17f083f94f/conn/command.go#L54-L60 The data was obtained in comma-separated format, as in the following: HEAD,refName,objectName

    However, when obtaining the refNames, it was assumed to be "the second element of split by a comma", so the error occured with comma-contained branch name.

    Therefore, I have modified it to use the comma-joined string of "excluding the first and last elements" as the refName. ( f373c6e4573423be4ec42bd240937fe96935c248 )

    In addition,

    head := false
    if headValue == "*" {
      head = true
    }
    

    I found this writing style a bit redundant,

    head := headValue == "*"
    

    I have made this modification. ( 9965e37c74868a5536c55969a9822bb24c4c87da )

    I am beginner of Go, so apologies if there are any problems.

    opened by AsPulse 6
  • 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
  • Improve performance for very large repositories

    Improve performance for very large repositories

    When running gh poi --dry-run on a really big repository like https://github.com/NixOS/nixpkgs/ with a grant total of 170k+ pull requests it takes a really long time. Could this be speed up?

    opened by SuperSandro2000 3
  • 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
  • Support keyboard interrupt

    Support keyboard interrupt

    What

    • Handle os.Interrupt signal and propagate cancellation using context
    • Add defer spinner.Stop() to ensure that the spinner is stopped and cleaned up

    Why

    Current implementation does not handle keyboard interrupt, which causes unexpected side effect to the shell: When I input ctrl-c while a spinner is running (with the message Fetching pull requests... for example), the cursor is still hidden even after the command finished.

    opened by hiroebe 2
  • Branch not deleted when checked out

    Branch not deleted when checked out

    Describe the bug To Reproduce:

    1. Create any PR
    2. Squash and merge PR
    3. gh poi
    4. Can't delete PR branch in local

    Your Environment

    • OS: macOS Monterey
    • gh (Check with gh --version): 2.14.4
    • gh-poi (For gh v2.6+ check with gh extension list): v0.6.2
    bug 
    opened by seachicken 2
Releases(v0.8.2)
Owner
Seito Tanaka
Seito Tanaka
Branch is a small CLI tool to automatically create git branches based on tickets

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

Maikel Veen 5 Nov 15, 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 588 Dec 31, 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
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
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
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 26 Oct 10, 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 2k Jan 5, 2023
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 2 Nov 1, 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 45 Nov 28, 2022