Update builders to delete git/obj dirs when gc --auto breaks.

This allows builders to recover from git corruption.

BUG=chromium:552503
TEST=Unit tests. Trybot run.

Change-Id: I06b85c12a6ef4ac1a9193f6759d18b88d8d4724a
Reviewed-on: https://chromium-review.googlesource.com/311423
Reviewed-by: Richard Barnette <jrbarnette@chromium.org>
Reviewed-by: David James <davidjames@chromium.org>
Commit-Queue: David James <davidjames@chromium.org>
Trybot-Ready: David James <davidjames@chromium.org>
Tested-by: David James <davidjames@chromium.org>
diff --git a/cbuildbot/commands.py b/cbuildbot/commands.py
index 96f6b64..a2bc1c9 100644
--- a/cbuildbot/commands.py
+++ b/cbuildbot/commands.py
@@ -177,7 +177,9 @@
       try:
         if os.path.isdir(cwd):
           git.CleanAndDetachHead(cwd)
-          git.GarbageCollection(cwd)
+
+        if os.path.isdir(repo_git_store):
+          git.GarbageCollection(repo_git_store)
       except cros_build_lib.RunCommandError as e:
         result = e.result
         logging.PrintBuildbotStepWarnings()
diff --git a/lib/git.py b/lib/git.py
index 5f522ae..b2ed600 100644
--- a/lib/git.py
+++ b/lib/git.py
@@ -149,6 +149,7 @@
   """
   cmd = ['fsck', '--no-progress', '--no-dangling']
   try:
+    GarbageCollection(cwd)
     RunGit(cwd, cmd)
     return False
   except cros_build_lib.RunCommandError as ex: