Skip to content

Commit ab0bb16

Browse files
committed
Implement --override-repo for branch/ref override for cloning
Used when a specific environment needs to run builds with a specific ref/branch override for any of the cloned repos
1 parent fd7be72 commit ab0bb16

1 file changed

Lines changed: 47 additions & 0 deletions

File tree

flutter_workspace.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,20 @@
8888
# `configs/globals.json` values
8989
globals_ = {}
9090

91+
# Dictionary to store repo overrides from CLI
92+
# e.g., { 'https://github.com/user/repo': { 'ref': None, 'branch': 'main' } }
93+
REPO_OVERRIDES = {}
94+
95+
96+
def normalize_git_uri(uri):
97+
"""Normalize a Git URI by removing trailing slashes and .git suffix."""
98+
if not uri:
99+
return uri
100+
uri = uri.rstrip('/')
101+
if uri.endswith('.git'):
102+
uri = uri[:-4]
103+
return uri
104+
91105

92106
def handle_exception(exc_type, exc_value, exc_traceback):
93107
if issubclass(exc_type, KeyboardInterrupt):
@@ -120,6 +134,10 @@ def main():
120134
parser.add_argument('--enable', default='', type=str, help='Platform Load Enable Override')
121135
parser.add_argument('--disable', default='', type=str, help='Platform Load Disable Override')
122136
parser.add_argument('--remote', default='', type=str, help='Remote Platform Load Git Repo')
137+
parser.add_argument('--override-repo', default='', type=str,
138+
help='Override repo branch/ref. Format: `uri#<ref>` or `uri#heads/<branch>`. '
139+
'Multiple entries supported (comma-separated). '
140+
'Example: https://github.com/user/repo.git#main,https://github.com/user/repo2#heads/feature')
123141
parser.add_argument('--enable-plugin', default='', type=str, help='Plugin Enable')
124142
parser.add_argument('--disable-plugin', default='', type=str, help='Plugin Disable')
125143
parser.add_argument('--fastboot', default='', type=str, help='Update the selected platform using fastboot')
@@ -141,6 +159,24 @@ def main():
141159

142160
print(f'Arguments {args}')
143161

162+
#
163+
# Parse --override-repo
164+
#
165+
global REPO_OVERRIDES
166+
if args.override_repo:
167+
for entry in args.override_repo.split(','):
168+
if '#' in entry:
169+
uri, ref = entry.split('#', 1)
170+
uri = normalize_git_uri(uri)
171+
branch = None
172+
if ref.startswith('heads/'):
173+
branch = ref.split('heads/', 1)[1]
174+
ref = None
175+
REPO_OVERRIDES[uri] = {'ref': ref, 'branch': branch}
176+
else:
177+
print(f"WARNING: Invalid --override-repo entry '{entry}' (missing '#'), skipping")
178+
print(f'Loaded repo overrides: {REPO_OVERRIDES}')
179+
144180
# Check if running in CI
145181
is_ci = os.environ.get('CI') == 'true'
146182

@@ -900,6 +936,17 @@ def get_repo(base_folder, uri, ref, branch=None, dest_name=None):
900936
print("repo entry needs a 'uri' key. Skipping")
901937
return
902938

939+
# Check for overrides from --override-repo
940+
normalized_uri = normalize_uri(uri)
941+
if normalized_uri in REPO_OVERRIDES:
942+
override = REPO_OVERRIDES[normalized_uri]
943+
old_ref, old_branch = ref, branch
944+
ref = override.get('ref')
945+
branch = override.get('branch')
946+
print_banner(f'Applying override for {normalized_uri}: branch={branch}, ref={ref}')
947+
if old_ref != ref or old_branch != branch:
948+
print(f' (was: branch={old_branch}, ref={old_ref})')
949+
903950
# get repo folder name
904951
repo_name = uri.rsplit('/', 1)[-1]
905952
repo_name = repo_name.split(".")

0 commit comments

Comments
 (0)