bisect-kit: allow add git repo on existing empty directory
git doesn't support empty directory, so this should not happen in usual
case.
This change is to workaround the issue introduced by
https://chromium-review.googlesource.com/c/chromium/src/+/1455037
which added git subrepository accidentally. gclient ignore this issue
silently. We have to allow it in order to bisect changes after the
accident.
BUG=b:126633034
TEST=switch_cros_cr_localbuild_internal.py to revision after 1455037
Change-Id: I9064405a900310de9dd0511a76f06ecc378a4074
Reviewed-on: https://chromium-review.googlesource.com/1525365
Commit-Ready: Kuang-che Wu <kcwu@chromium.org>
Tested-by: Kuang-che Wu <kcwu@chromium.org>
Reviewed-by: Chi-Ngai Wan <cnwan@google.com>
diff --git a/bisect_kit/codechange.py b/bisect_kit/codechange.py
index 3864693..132415a 100644
--- a/bisect_kit/codechange.py
+++ b/bisect_kit/codechange.py
@@ -384,7 +384,14 @@
def apply(self, code_storage, root_dir):
git_repo = os.path.join(root_dir, self.path)
- assert not os.path.exists(git_repo)
+ if os.path.exists(git_repo):
+ if os.path.isdir(git_repo) and not os.listdir(git_repo):
+ # mimic gclient's behavior; don't panic
+ logger.warning(
+ 'adding repo %s; there is already an empty directory; '
+ 'assume it is okay', git_repo)
+ else:
+ assert not os.path.exists(git_repo), '%s already exists' % git_repo
reference = code_storage.cached_git_root(self.repo_url)
git_util.clone(git_repo, self.repo_url, reference=reference)