Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ Optional:

git clone https://github.com/baba-dev/M5Tab5-UserDemo.git
cd M5Tab5-UserDemo
python fetch_repos.py # fetch M5 & LVGL components
python fetch_repos.py # fetch or update M5 & LVGL components

2. **Set ESP32-P4 target**

Expand Down
2 changes: 1 addition & 1 deletion docs/DEV_SETUP.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
`release-v5.4` toolchain to ensure the project uses the NG I²C driver stack
exclusively.
- Run `python3 fetch_repos.py` before building so that managed components are
pulled into the workspace.
pulled into the workspace or refreshed to the pinned revisions.

## Build checklist

Expand Down
52 changes: 42 additions & 10 deletions fetch_repos.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,53 @@
"""Fetch dependent repositories defined in repos.json."""

import json
import os
import subprocess
import json
from pathlib import Path


def _run_git(args):
subprocess.run(['git', *args], check=True)


def _maybe_update_submodules(repo_path: Path) -> None:
if (repo_path / '.gitmodules').is_file():
_run_git(['-C', str(repo_path), 'submodule', 'update', '--init', '--recursive'])


def clone_or_update_repo(repo_url, path, branch):
command = []
command.append('git')
command.append('clone')

repo_path = Path(path)

if repo_path.is_dir():
_run_git(['-C', str(repo_path), 'fetch', '--prune'])

if branch:
_run_git(['-C', str(repo_path), 'checkout', branch])

Comment on lines +21 to +26
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P1] Fetch tags before checking out tag revisions

The refresh path only runs git fetch --prune before attempting git checkout <branch> when a dependency already exists. If the "branch" field in repos.json references a tag (all current entries do), git fetch --prune does not download new or updated tags. When the pinned tag changes (for example updating from v2.1.0 to v2.1.1) or a tag is re-pointed upstream, the checkout will fail with pathspec '<tag>' did not match any files and the dependencies cannot be refreshed in place. Consider fetching tags explicitly (e.g. git fetch --tags or git fetch origin tagname) before attempting the checkout so tag-based revisions can be updated.

Useful? React with 👍 / 👎.

remote_ref = subprocess.run(
['git', '-C', str(repo_path), 'show-ref', '--verify', f'refs/remotes/origin/{branch}'],
stdout=subprocess.DEVNULL,
stderr=subprocess.DEVNULL,
check=False,
)

if remote_ref.returncode == 0:
_run_git(['-C', str(repo_path), 'reset', '--hard', f'origin/{branch}'])
else:
_run_git(['-C', str(repo_path), 'pull', '--ff-only'])

_maybe_update_submodules(repo_path)
return

command = ['clone']

if branch:
command.append('-b')
command.append(branch)
command.extend(['-b', branch])

command.append(repo_url)
command.append(path)
command.extend([repo_url, str(repo_path)])

subprocess.run(command)
_run_git(command)
_maybe_update_submodules(repo_path)

def main():
script_dir = os.path.dirname(os.path.abspath(__file__))
Expand Down
Loading