sync: Refresh index before updating repo
If the repo index is stale, reset --keep will refuse to reset workspace.
An index can be stale if there are any modifications to file node,
including mtime, atime, ownership changes, etc.
Bug: b/375423099
Change-Id: Ibef03d9d8d2babbb107041707281687342ab7a77
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/460022
Commit-Queue: Josip Sokcevic <sokcevic@chromium.org>
Tested-by: Josip Sokcevic <sokcevic@chromium.org>
Reviewed-by: Scott Lee <ddoman@google.com>
diff --git a/subcmds/sync.py b/subcmds/sync.py
index 978b3be..49874c4 100644
--- a/subcmds/sync.py
+++ b/subcmds/sync.py
@@ -1999,6 +1999,8 @@
# We also have to make sure this will switch to an older commit if
# that's the latest tag in order to support release rollback.
try:
+ # Refresh index since reset --keep won't do it.
+ rp.work_git.update_index("-q", "--refresh")
rp.work_git.reset("--keep", new_rev)
except GitError as e:
raise RepoUnhandledExceptionError(e)