Page MenuHomePhabricator

`arc cleanup` to cleanup branches used by `arc patch`
Open, LowPublic

Description

arc patch loves to create branches, but unfortunately the only way to clean them up is manually. It'd be great if there was a simple workflow called arc cleanup that would go through and force delete any branches that start with arcpatch-D*.

(On a side note, I noticed that @epriestley is usually the one to land patches to Phabricator, but we tried doing that in arc land and it fails because the person landing is not the owner of the diff. Is there some other workflow that we're meant to use to make this work?)

Event Timeline

I use:

$ git checkout master
$ arc patch --nobranch Dnnn
$ git push

We should probably make arc land prompt instead of failing, though, since there's no technical reason not to let you land others' revisions if you intend to. However, we should also make it respect --author when we do that, so that patches make it to the upstream with the correct metadata.

To prune branches, you can use something like:

$ git branch | cut -c3- | grep arcpatch- | xargs -n1 git branch -D

(The match is arcpatch- instead of arcpatch-D because arc patch --patch some_file.diff generates arcpatch-1.) So you could build arc cleanup as:

$ arc alias cleanup -- '!git branch | cut -c3- | grep arcpatch- | xargs -n1 git branch -D'

You can also put this in a ".arcconfig" file, I believe:

"alias" : {
  "cleanup" : "!git branch | cut -c3- | grep arcpatch- | xargs -n1 git branch -D"
}

I'm not sure what arc cleanup would do beyond that. Git already prevents you from deleting the current branch. The only other thing I can think of is that we could maybe prompt you before deleting any changes not present in Phabricator (by comparing hashes), or provide a --dry-run flag or something, but these don't seem especially useful at first glance...

Those commands won't work under Windows since the command line sucks. Under Windows you have to manually delete all of the branches through the UI.

This use case would also be addressed with better arc land semantics, as discussed in IRC: https://secure.phabricator.com/chatlog/channel/6/?at=65077

epriestley added a project: Badge Awarded.

Although this is trivial to script and not the original report is better addressed in other ways, I don't think it causes too much damage to provide first class support. Users ask for it every so often and hate writing scripts.

I have written this script; it sits under
https://github.com/hach-que/Tychaia/tree/master/Build/Arcanist/workflow as
RedpointCleanupWorkflow.php. Feel free to take it and do whatever you want
with it (e.g. including it in upstream).

@epriestley FYI, I was following your example of defining aliases in arcconfig and I had to do like this.

"aliases" : {                                                                                                                                                                   
    "cleanup" : ["!git branch | cut -c3- | grep arcpatch- | xargs -n1 git branch -D"]
 }

After T182, web-landed changes tend to leave local branches around since we never run any code on the user's machine. These are handled reasonably by arc branch, but having arc cleanup clean them up (or have an option to clean them up) might be nice.

avivey changed the visibility from "All Users" to "Public (No Login Required)".Dec 12 2015, 7:43 PM
avivey added a subscriber: avivey.
avivey removed a subscriber: avivey.

+1 for this command. We have use a web-based UI for landing so our branches stick around locally. To fix this I'm currently using:

arc branches | grep ' Closed ' | sed 's/[^ ]* //' | sed 's/ .*//' | grep -v master | grep -v '^[0-9a-f.]*$' | xargs git br -D

grep -v master | grep -v '^[0-9a-f.]*$'

This part may prove slightly trickier to implement correctly in the general case.

grep -v master | grep -v '^[0-9a-f.]*$'

This part may prove slightly trickier to implement correctly in the general case.

Yeah, that was because my parsing of Closed is wrong. If I have branches with multiple commits on them, arc branch shows all the commits on different lines and puts the Closed on the line of the git SHA and not the branch name. I think if I had the internal data structures present, the hash filtering wouldn't be needed. Not deleting master could probably be done by checking some default upstream things in git but even if it deleted my master branch I wouldn't be super sad.