mislav / hub

A command-line tool that makes git easier to use with GitHub.
https://hub.github.com/
MIT License
22.81k stars 2.2k forks source link

hub sync isn't very effective when squashing and merging commits #1359

Open seanabraham opened 7 years ago

seanabraham commented 7 years ago

I want to use hub sync to update local branches but more importantly delete branches that have been merged already via the Github UI. The problem is, when running hub sync I get many warnings like the following: warning: 'sean/branch_name' was deleted on origin, but appears not merged into master.

I'm assuming this is because the PR opened for this branch was merged using the "Squash and Merge" option so the SHA no longer matches. Is there a way to force hub sync to still delete branches in this case?

mislav commented 7 years ago

Sorry, hub sync still doesn't recognize squash-merged branches! I'm not sure what would be the best way to support this, since it's not trivial to detect just by looking at git objects.

If anyone has any ideas, I'm all ears.

chufucious commented 5 years ago

Is there a command I can run to get rid of that issue?

kevinkjt2000 commented 5 years ago

I copied a complicated git alias from somewhere that helps clean up squashed branches. It may or may not work for your use case:

[alias]
  cleanup = "!git remote prune origin && git checkout -q master && git for-each-ref refs/heads/ '--format=%(refname:short)' | while read branch; do mergeBase=$(git merge-base master $branch) && [[ $(git cherry master $(git commit-tree $(git rev-parse $branch^{tree}) -p $mergeBase -m _)) == '-'* ]] && git branch -D $branch; done"

In my case, I run hub sync followed by git cleanup.

I am not familiar at all with hub's code, but perhaps this logic of looping over refs and comparing merges could be integrated into the sync command?