Properly handle duplicate commits when pushes are in the equation.

Also, use a temporary directory rather than one based on the commit sha
to allow for overlap if it occurs.