Skip to content

Commit

Permalink
fix: re-fetch the git dependency if its target_dir is occupied
Browse files Browse the repository at this point in the history
If a git dependency's target_dir is occupied by another git
repository, the checkout will fail very likely.

To fix the issue above, when a checkout failed, delete the occupied
target_dir for a clean re-fetch.
  • Loading branch information
jianliang00 committed Jan 15, 2025
1 parent 68a2596 commit 2d51d49
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion core/fetchers/git_fetcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,16 @@ async def fetch(self, root_dir, options, *args, **kwargs):
cmd = f'git --work-tree={target_dir} checkout FETCH_HEAD -- .'
else:
cmd = f'git checkout {checkout_args}'
await run_git_command(cmd, shell=True, cwd=source_dir, stderr=subprocess.STDOUT)
try:
await run_git_command(cmd, shell=True, cwd=source_dir, stderr=subprocess.STDOUT)
except subprocess.CalledProcessError:
logging.warning(
f'A checkout for {target_dir} has failed. This might caused by that '
f'the target directory for {url} is occupied by another git repository. A clean'
' fetch is on the run.'
)
rmtree(source_dir)
await self.fetch(root_dir, options, *args, **kwargs)

if getattr(self.component, 'enable_lfs', False):
try:
Expand Down

0 comments on commit 2d51d49

Please sign in to comment.