Skip to content

Commit 1b8211f

Browse files
sokcevicGLUCI CQ
authored andcommitted
Restore git files that may be deleted by CIPD
When CIPD removes a package, it removes the files. However, it's possible that those files were checked in beforehand (for example, https://crrev.com/c/3858186). bot_update/gclient sync will first run git operations followed by cipd ensure. This patch restores any files that may have been deleted after cipd ensure. Bug: 1369452 Change-Id: I43ff9553118a20ed250bddc15153f02828847ed3 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/tools/depot_tools/+/3928237 Reviewed-by: Aravind Vasudevan <[email protected]> Commit-Queue: Josip Sokcevic <[email protected]>
1 parent e3ed6a8 commit 1b8211f

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

gclient.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1832,6 +1832,8 @@ def _RemoveUnversionedGitDirs(self):
18321832
Notify the user if there is an orphaned entry in their working copy.
18331833
Only delete the directory if there are no changes in it, and
18341834
delete_unversioned_trees is set to true.
1835+
1836+
Returns CIPD packages that are no longer versioned.
18351837
"""
18361838

18371839
entry_names_and_sync = [(i.name, i._should_sync)
@@ -1845,6 +1847,7 @@ def _RemoveUnversionedGitDirs(self):
18451847
name for name, should_sync in entry_names_and_sync if not should_sync
18461848
]
18471849

1850+
removed_cipd_entries = []
18481851
for entry, prev_url in self._ReadEntries().items():
18491852
if not prev_url:
18501853
# entry must have been overridden via .gclient custom_deps
@@ -1853,6 +1856,11 @@ def _RemoveUnversionedGitDirs(self):
18531856
# Dependencies of solutions that skipped syncing would not
18541857
# show up in `entries`.
18551858
continue
1859+
if (':' in entry):
1860+
# This is a cipd package. Don't clean it up, but prepare for return
1861+
if entry not in entries:
1862+
removed_cipd_entries.append(entry)
1863+
continue
18561864
# Fix path separator on Windows.
18571865
entry_fixed = entry.replace('/', os.path.sep)
18581866
e_dir = os.path.join(self.root_dir, entry_fixed)
@@ -1955,6 +1963,7 @@ def _RemoveUnversionedGitDirs(self):
19551963
gclient_utils.rmtree(e_dir)
19561964
# record the current list of entries for next time
19571965
self._SaveEntries()
1966+
return removed_cipd_entries
19581967

19591968
def RunOnDeps(self, command, args, ignore_requirements=False, progress=True):
19601969
"""Runs a command on each dependency in a client and its dependencies.
@@ -2029,6 +2038,7 @@ def RunOnDeps(self, command, args, ignore_requirements=False, progress=True):
20292038

20302039
# Once all the dependencies have been processed, it's now safe to write
20312040
# out the gn_args_file and run the hooks.
2041+
removed_cipd_entries = []
20322042
if command == 'update':
20332043
for dependency in self.dependencies:
20342044
gn_args_dep = dependency
@@ -2038,13 +2048,24 @@ def RunOnDeps(self, command, args, ignore_requirements=False, progress=True):
20382048
if gn_args_dep and gn_args_dep.HasGNArgsFile():
20392049
gn_args_dep.WriteGNArgsFile()
20402050

2041-
self._RemoveUnversionedGitDirs()
2051+
removed_cipd_entries = self._RemoveUnversionedGitDirs()
20422052

20432053
# Sync CIPD dependencies once removed deps are deleted. In case a git
20442054
# dependency was moved to CIPD, we want to remove the old git directory
20452055
# first and then sync the CIPD dep.
20462056
if self._cipd_root:
20472057
self._cipd_root.run(command)
2058+
# It's possible that CIPD removed some entries that are now part of git
2059+
# worktree. Try to checkout those directories
2060+
if removed_cipd_entries:
2061+
for cipd_entry in removed_cipd_entries:
2062+
cwd = os.path.join(self._root_dir, cipd_entry.split(':')[0])
2063+
cwd, tail = os.path.split(cwd)
2064+
if cwd:
2065+
try:
2066+
gclient_scm.scm.GIT.Capture(['checkout', tail], cwd=cwd)
2067+
except subprocess2.CalledProcessError:
2068+
pass
20482069

20492070
if not self._options.nohooks:
20502071
if should_show_progress:

0 commit comments

Comments
 (0)