Add a `GIT_PREVIOUS_SUCCESSFUL_COMMIT` environment variable

Add a `GIT_PREVIOUS_SUCCESSFUL_COMMIT` environment variable which is similar to `GIT_PREVIOUS_COMMIT` but refers to the most-recent successful build.

I'm happy to write tests for this but couldn't quite follow how the current tests are structured.