Skip to content

Commit edc75dc

Browse files
authored
Pull updates for refs in cached repos in ecosystem checks (astral-sh#8420)
Otherwise, the cache can end up not testing the latest changes to the ref.
1 parent ebad36d commit edc75dc

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

‎python/ruff-ecosystem/ruff_ecosystem/projects.py‎

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ async def clone(self: Self, checkout_dir: Path) -> ClonedRepository:
138138
Shallow clone this repository
139139
"""
140140
if checkout_dir.exists():
141-
logger.debug(f"Reusing {self.owner}:{self.name}")
141+
logger.debug(f"Reusing cached {self.fullname}")
142142

143143
if self.ref:
144144
logger.debug(f"Checking out {self.fullname} @ {self.ref}")
@@ -158,6 +158,10 @@ async def clone(self: Self, checkout_dir: Path) -> ClonedRepository:
158158

159159
cloned_repo = await ClonedRepository.from_path(checkout_dir, self)
160160
await cloned_repo.reset()
161+
162+
logger.debug(f"Pulling latest changes for {self.fullname} @ {self.ref}")
163+
await cloned_repo.pull()
164+
161165
return cloned_repo
162166

163167
logger.debug(f"Cloning {self.owner}:{self.name} to {checkout_dir}")
@@ -285,6 +289,23 @@ async def reset(self: Self) -> None:
285289
if await process.wait() != 0:
286290
raise RuntimeError(f"Failed to reset: {stderr.decode()}")
287291

292+
async def pull(self: Self) -> None:
293+
"""
294+
Pull the latest changes.
295+
296+
Typically `reset` should be run first.
297+
"""
298+
process = await create_subprocess_exec(
299+
*["git", "pull"],
300+
cwd=self.path,
301+
env={"GIT_TERMINAL_PROMPT": "0"},
302+
stdout=PIPE,
303+
stderr=PIPE,
304+
)
305+
_, stderr = await process.communicate()
306+
if await process.wait() != 0:
307+
raise RuntimeError(f"Failed to pull: {stderr.decode()}")
308+
288309
async def commit(self: Self, message: str) -> str:
289310
"""
290311
Commit all current changes.

0 commit comments

Comments
 (0)