foriequal0 / git-trim

Automatically trims your branches whose tracking remote refs are merged or stray
MIT License
481 stars 13 forks source link

`git-trim` fails to work correctly when trying to delete branches that are contributor PRs #178

Open kdheepak opened 3 years ago

kdheepak commented 3 years ago

Check your version before submitting the bug

$ git-trim --version
git-trim 0.4.2

Describe the bug

Sometimes when a contributor submits a PR, I run hub pr checkout $PrNumber in the repository, where hub is a binary install from https://github.com/github/hub. This allows me to make commits directly to the contributor's branch before merging the PR.

However, when I try to delete those local branches using git-trim it doesn't work. git-trim --delete local suggests adding the --delete 'merged:*' flag.

$ git-trim --delete local
Fetching origin

Branches that will remain:
  local branches:
    brightpuddle-master *1
    delete-prompt-and-change-delete-keybinding *1
    history *1
    improve-cpu-usage *1
    interpolate-variables *1
    master *1
    multiple-selection *1
    update-help-menu *1
  remote references:
    origin/delete-prompt-and-change-delete-keybinding *1
    origin/gh-pages *3
    origin/history *1
    origin/master *1
    origin/multiple-selection *1
    origin/update-help-menu *1
  Some branches are skipped. Consider following to scan them:
    *1: Add `--delete 'merged:*' flag.
    *3: Make it upstream of a tracking branch or add `--delete 'remote:origin' flag.

When I add that flag I get the following error

$ git-trim --delete local --delete 'merged:*'
Fetching origin

Branches that will remain:
  local branches:
    delete-prompt-and-change-delete-keybinding
    history
    interpolate-variables [stray, but: delete range `stray` was not given]
    master [base]
    multiple-selection
    update-help-menu
  remote references:
    origin/delete-prompt-and-change-delete-keybinding
    origin/gh-pages *3
    origin/history
    origin/master [base]
    origin/multiple-selection
    origin/update-help-menu
  Some branches are skipped. Consider following to scan them:
    *3: Make it upstream of a tracking branch or add `--delete 'remote:origin' flag.

Delete merged local branches:
  - brightpuddle-master
  - improve-cpu-usage
Delete diverged remote refs:
  - git@github.com:brightpuddle/taskwarrior-tui.git, refs/heads/master
  - git@github.com:desbma/taskwarrior-tui.git, refs/heads/improve-cpu-usage
Confirm? yes
To github.com:brightpuddle/taskwarrior-tui.git
 ! [remote rejected] master (permission denied)
error: failed to push some refs to 'github.com:brightpuddle/taskwarrior-tui.git'
Error: Operation not permitted (os error 1)

Obviously, I can't and shouldn't be able to delete a remote branch on someone else's repo. Ideally git-trim will just delete the local branches in my repo. I'm not a git expert, so I'm not sure if the diverged remote refs are stored locally somewhere, but if it is, I would like git-trim to delete those as well.

Additional context and logs & dumps if necessary You should remove sensitive informations before put them here.

I can provide additional information dumps if required. The repo in question is here: https://github.com/kdheepak/taskwarrior-tui/. Happy to answer more questions.

Thanks for making git-trim, I use it all the time!

foriequal0 commented 3 years ago

Hi @kdheepak . It is confusing behavior to me too. I'll investigate this as I have time.

kdheepak commented 3 years ago

Thank you! And thanks again for making git-trim!