-
Notifications
You must be signed in to change notification settings - Fork 43
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add --delete-deleted option to delete branches which have been deleted from the remote #41
Comments
Closed by mistake. |
If I remember correctly, this is what the
Could you check if it does what you want? |
@johnddx Have you tried using the setting |
I'm concerned that it would delete branches that are not contained by another branch. (the remote deletion could have been a de-publishing act, rather than an indication that the branch is no longer needed). I might have to try it. |
Okay yes, there are actually several problems with "git fetch --prune":
Basically, I think git fetch --prune is itself an incomplete feature, so I wouldn't use it for this problem as-is. |
I struck through most of my previous comment, because it was misguided. The real problem with "git fetch --prune" is that it will only delete remote refs. It will never delete the local branch associated with the remote ref. As such, git-up.fetch.prune should not even be an option, it should just be the only behavior. And the feature requested in this issue can really only be implemented at the layer of git-up. |
Ah, I see. So the locak tracking branch is kept while removing
Unfortunately we can't change this without breaking compatibiltiy with the original
I'm still undecided whether this should be a command line flag or rather a |
Also I think we only should remove the branch if it already has been merged, right? |
It doesn't hurt to have prune as an option, although I imagine the newly requested behavior would depend on it being enabled. Maybe that means the new option would imply the old option.
I didn't actually know about --prune when I made the original request. I'm wondering if we can build on that term here, e.g. "prune local" or "prune merged". --help can clarify that it would prune local merged branches and that it's safe to use all the time. I think having an option like git-up.prune-local is fine, but it's the kind of thing someone might be paranoid about and prefer to add to the command-line. That's not me, though, so if you made it config-only I'd be happy. Well, presuming all the deleted branches were logged so that I would have something to audit. In fact, it seems that the reflog for deleted branches is removed along with the branch. I.e. it won't be possible to do 'git reflog ' after the branch is deleted, so it might be a good idea to do this to force a recent reflog entry for HEAD:
This guarantees that any deleted branch has a recent entry in the reflog for HEAD. Except that is not a transactional sequence, so it would be better to:
Definitely only delete a merged branch, that is one of the three conditions I listed in the original request. |
Re config vs. arg: Actually we have some kind of inconsistency here: Except for Re logging: We could use the same mechanism that's used for the other status output:
Interesting, how did you come to this conclusion? According to the internet (http://blag.ahax.de/post/421939327/recovering-a-deleted-branch-using-git-reflog) and my own (admittedly quick) test git actually should keep the reflog for deleted branches. Also, would you like to draw up a PR with that feature? |
What we're seeing, both in our experiments and on that web page, is that the reflog for HEAD is always around. If you were to run that same experiment in the blog, but then type 'git reflog gamelan', it would complain that 'gamelan' does not exist, because it was deleted. 'gamelan' happens to exist in the HEAD reflog because it was recently checked out. If it had been a year since anyone had checked out the 'gamelan' branch, and then the branch was deleted, then there would likely be no reflog pointing at that branch anymore, and no way to get it back. So the two reset commands I offered above were specifically geared toward guaranteeing that there is a recent reflog entry in HEAD for the soon-to-be-deleted branch. We're only supposed to delete branches which are merged into other branches, but in the unlikely event we do the wrong thing, or that the user panics and realizes they really needed to know what merged commit the deleted branch was pointing to, they'll always be able to recover that information... for a time.
I haven't worked with python before, but I suppose I can give it a try. |
Ah, okay. I guess being more user-friendly than git definitely won't hurt :)
Sounds great! Feel free to comment here (or create a WIP pull request and comment there) if you run into problems, I'd be glad to help. |
Whenever this error occurs running git-up:
There is an opportunity to clean up the local branches to reflect similar clean-up performed on the remote. --delete-deleted as an option name seems somewhat reflective of the intent. -d is probably suitable for short.
If -d is specified, a local branch should be deleted if all of the following are true:
If any of the above are false, the deletion should not occur.
Note: This is a heuristic. It is possible to assign an uplink to a branch without ever actually using it. This would mean the remote branch wasn't actually deleted, it was never created to begin with. However, as long as the branch is contained in another branch, it should still be safe to delete the local reference.
The text was updated successfully, but these errors were encountered: