Skip to content

Commit b80e60f

Browse files
reckless: helper function for accessing local clone of remote repo
1 parent f78cf32 commit b80e60f

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

tools/reckless

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,16 @@ def help_alias(targets: list):
11381138
sys.exit(1)
11391139

11401140

1141+
def _get_local_clone(source: str) -> Union[Path, None]:
1142+
"""Returns the path of a local repository clone of a github source. If one
1143+
already exists, prefer searching that to accessing the github API."""
1144+
user, repo = Source.get_github_user_repo(source)
1145+
local_clone_location = RECKLESS_DIR / '.remote_sources' / user / repo
1146+
if local_clone_location.exists():
1147+
return local_clone_location
1148+
return None
1149+
1150+
11411151
def _source_search(name: str, src: str) -> Union[InstInfo, None]:
11421152
"""Identify source type, retrieve contents, and populate InstInfo
11431153
if the relevant contents are found."""
@@ -1147,18 +1157,11 @@ def _source_search(name: str, src: str) -> Union[InstInfo, None]:
11471157
# If a local clone of a github source already exists, prefer searching
11481158
# that instead of accessing the github API.
11491159
if source.srctype == Source.GITHUB_REPO:
1150-
# Do we have a local copy already? Use that.
1151-
user, repo = Source.get_github_user_repo(src)
1152-
assert user
1153-
assert repo
1154-
local_clone_location = RECKLESS_DIR / '.remote_sources' / user / repo
1155-
if local_clone_location.exists():
1156-
# Make sure it's the correct remote source and fetch any updates.
1157-
if _git_update(source, local_clone_location):
1158-
log.debug(f"Using local clone of {src}: "
1159-
f"{local_clone_location}")
1160-
source.source_loc = str(local_clone_location)
1161-
source.srctype = Source.GIT_LOCAL_CLONE
1160+
local_clone = _get_local_clone(source)
1161+
if local_clone and _git_update(source, local_clone):
1162+
log.debug(f"Using local clone of {src}: {local_clone}")
1163+
source.source_loc = str(local_clone)
1164+
source.srctype = Source.GIT_LOCAL_CLONE
11621165

11631166
if source.get_inst_details():
11641167
return source

0 commit comments

Comments
 (0)