Arc land fails with detached HEAD

When in a detached HEAD state, arc land pushes the code upstream without issue but fails when it tries to clean up the branch, exiting with a nonzero exit code. This breaks certain workflows, i.e. stacked diffs with an interactive rebase to land one or more of the deeper diffs.

arc land --keep-branch is a workaround but it seems it would be sensible for arc to check that we’re on a branch before trying to be helpful in deleting what it assumes is a branch.

Reproduction Instructions

$ git checkout -b my-branch
$ echo burek > sarma.txt
$ git add sarma.txt
$ git commit -m 'Add sarma.txt'
$ arc diff
...
$ git checkout $(git rev-parse HEAD)
$ arc land

... successful push then ...

Cleaning up branch "0550804fa452568c8cf20f623dc3fcfb058704da"...
(Use `git checkout -b 0550804fa452568c8cf20f623dc3fcfb058704da 0550804fa452568c8cf20f623dc3fcfb058704da` if you want it back.)
 Exception
Command failed with error #1!
COMMAND
git branch -D -- '0550804fa452568c8cf20f623dc3fcfb058704da'

STDOUT
(empty)

STDERR
error: branch '0550804fa452568c8cf20f623dc3fcfb058704da' not found.

(Run with `--trace` for a full exception trace.)

Phabricator/Arcanist Version

$ arc version
arcanist feb5f4d42c4fe0001e76428e80d5e88262308802 (22 Jun 2019)
libphutil 794ded9857110cdc7b0fb7bedb4a64438d2d873e (31 Aug 2019)

I think this is approximately the same as https://secure.phabricator.com/T10321.

I agree that this operation should be supported. This is slightly messy because you’re free to actually name a branch 0550804fa452568c8cf20f623dc3fcfb058704da, but we can test for “branchiness” with git show-ref --verify refs/heads/... or some similar invocation.

arc workflow changes often get entangled in https://secure.phabricator.com/T13098 these days, but I believe this one is a straightforward fix.

This should be fixed by https://secure.phabricator.com/D20786.

Superb, thank you :pray: