cbuildbot: Ensure incremental builders do not clear chroot midrun.

BUG=chromium:584035
TEST=sync_stages_unittest still passes

Change-Id: I66e0ff3b6363d9e93ed03fe7d58d2b2ea89175a0
Reviewed-on: https://chromium-review.googlesource.com/325824
Commit-Ready: Kevin Cheng <kevcheng@chromium.org>
Tested-by: Kevin Cheng <kevcheng@chromium.org>
Reviewed-by: Kevin Cheng <kevcheng@chromium.org>
diff --git a/cbuildbot/stages/sync_stages.py b/cbuildbot/stages/sync_stages.py
index 9b59224..28eda66 100644
--- a/cbuildbot/stages/sync_stages.py
+++ b/cbuildbot/stages/sync_stages.py
@@ -1016,10 +1016,14 @@
       if not pre_build_passed:
         logging.PrintBuildbotStepText('Pre-patch build failed.')
 
-    # Make sure the chroot version is valid.
     lkgm_version = self._GetLGKMVersionFromManifest(next_manifest)
     chroot_manager = chroot_lib.ChrootManager(self._build_root)
-    chroot_manager.EnsureChrootAtVersion(lkgm_version)
+    # Make sure the chroot version is valid only on non-incremental builders.
+    # What was happening was by ensuring the chroot was at a specific version,
+    # on incremental builders it was actually clearing the chroot, hence we
+    # check for that now.
+    if not self._run.config.build_before_patching:
+      chroot_manager.EnsureChrootAtVersion(lkgm_version)
 
     # Clear the chroot version as we are in the middle of building it.
     chroot_manager.ClearChrootVersion()