Fix how we resolve current branch according to http://stackoverflow.com/a/1593487