Update git fetch refspecs on git migrate
User may have set fetch only on the old default branch. This ensures
that fetch works with new default branch.
R=gavinmak@google.com
Bug: 1268775
Change-Id: I971cdd041e8e8a7f06a20f4de348c1395c7b6e06
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3274108
Auto-Submit: Josip Sokcevic <sokcevic@google.com>
Commit-Queue: Gavin Mak <gavinmak@google.com>
Reviewed-by: Gavin Mak <gavinmak@google.com>
diff --git a/git_migrate_default_branch.py b/git_migrate_default_branch.py
index 71be696..4e00d3d 100644
--- a/git_migrate_default_branch.py
+++ b/git_migrate_default_branch.py
@@ -54,6 +54,12 @@
if project_head != 'refs/heads/main':
raise RuntimeError("The repository is not migrated yet.")
+ # User may have set to fetch only old default branch. Ensure fetch is tracking
+ # main too.
+ git_common.run('config', '--unset-all',
+ 'remote.origin.fetch', 'refs/heads/*')
+ git_common.run('config', '--add',
+ 'remote.origin.fetch', '+refs/heads/*:refs/remotes/origin/*')
logging.info("Running fetch...")
git_common.run('fetch', remote)
logging.info("Updating remote HEAD...")