Remove .git/config.lock in build directory
In git fetch mode, a build might get fail before the git init step
fails if the .git/config.lock file happens to exist for some reason.
We now prune this file just in case.
Refactor writeGitCleanup() to run before git init. We should be able to remove the lock files before the git init runs, since git init should not affect them. However, .git/config.lock needs to be removed for git init to succeed.
Encountered in #26618 (comment 452182599)
Edited by Stan Hu