Tesla has agreed to buy SolarCity for $2.6 billion in an all-stock deal