Skip to content

Commit

Permalink
Fix parameter handling in repo_resolver and update logging configurat…
Browse files Browse the repository at this point in the history
…ion. (#838)

* Fix an issue with parameter handling in repo_resolver that prevented "branch", "shallow", and "reference" parameters from being passed to git clone operations.
* Updated logging configuration to allow better tracing of repo_resolver operations for future debugging of similar issues.
  • Loading branch information
joschock authored Jul 1, 2024
1 parent bb2bfec commit d5c1649
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion edk2toolext/edk2_logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ def output_compiler_error(match: re.Match, line: str, start_txt:str="Compiler")

class Edk2LogFilter(logging.Filter):
"""Subclass of logging.Filter."""
_allowedLoggers = ["root"]
_allowedLoggers = ["root", "git.cmd", "edk2toolext.environment.repo_resolver"]

def __init__(self) -> None:
"""Inits a filter."""
Expand Down
12 changes: 8 additions & 4 deletions edk2toolext/environment/repo_resolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,7 @@ def clone_repo(abs_file_system_path: os.PathLike, DepObj: dict) -> tuple:
shallow = True
branch = DepObj["Branch"]
if "ReferencePath" in DepObj and os.path.exists(DepObj["ReferencePath"]):
reference = os.path.abspath(DepObj["ReferencePath"])
reference = Path(DepObj["ReferencePath"])

# Used to generate clone params from flags
def _build_params_list(branch: str=None, shallow: str=None, reference: str=None) -> None:
Expand All @@ -336,9 +336,10 @@ def _build_params_list(branch: str=None, shallow: str=None, reference: str=None)
params.append('--depth=5')
if reference:
params.append('--reference')
params.append('reference')
params.append(reference.as_posix())
else:
params.append("--recurse-submodules") # if we don't have a reference we can just recurse the submodules
return params

# Run the command
try:
Expand Down Expand Up @@ -421,8 +422,11 @@ def checkout(
except GitCommandError:
# try to fetch it and try to checkout again
logger.info("We failed to checkout this branch, we'll try to fetch")
repo.git.fetch(branch=branch)
repo.git.checkout(branch=branch)
# since the repo may have been cloned with --single-branch, add a refspec for the target branch.
refspec = "refs/heads/{0}:refs/remotes/origin/{0}".format(branch)
repo.remotes.origin.config_writer.set_value("fetch", refspec).release()
repo.git.fetch()
repo.git.checkout(branch)
repo.git.submodule("update", "--init", "--recursive")
else:
if details["Branch"] == dep["Branch"]:
Expand Down

0 comments on commit d5c1649

Please sign in to comment.