Skip to content

Commit

Permalink
git.py: Fail on different branches for same repo
Browse files Browse the repository at this point in the history
  doma:
    sources:
      - type: git
        url: https://github.com/xen-troops/meta-example.git
        rev: "ABCDEF"
  ...
  domu:
    sources:
      - type: git
        url: https://github.com/xen-troops/meta-example.git
        rev: "branch_A"

For doma and domu, the same GitHub repository is specified, but with
different branches.

In the case of such an erroneous YAML file, Moulin will not highlight
this error. Consequently, the user will also spend significant effort
to understand the reason for the incorrect functioning.

This patch adds an additional check to the git.py file. Now, if the
repository branches don't match, an error is displayed in the console,
and the generation of the build.ninja file is halted.

Co-Authored-By: Ihor Usyk <[email protected]>
Signed-off-by: Mykhailo Androsiuk <[email protected]>
Reviewed-by: Volodymyr Babchuk <[email protected]>
  • Loading branch information
2 people authored and lorc committed Oct 30, 2023
1 parent e4ce12e commit 19d2ec0
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions moulin/fetchers/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import os.path
from typing import List
import pygit2
from moulin.yaml_helpers import YAMLProcessingError
from moulin.yaml_wrapper import YamlValue
from moulin.utils import create_stamp_name
from moulin import ninja_syntax
Expand Down Expand Up @@ -44,7 +45,7 @@ def _guess_dirname(url: str):
return url.split("/")[-1]


_SEEN_REPOS = []
_SEEN_REPOS_REV = {}


class GitFetcher:
Expand All @@ -63,11 +64,17 @@ def gen_fetch(self):
clone_target = self.git_dir
checkout_stamp = create_stamp_name(self.build_dir, self.url, "checkout")

# Do not checkout repos for the second time
if checkout_stamp in _SEEN_REPOS:
return checkout_stamp
if checkout_stamp in _SEEN_REPOS_REV:
if self.git_rev != _SEEN_REPOS_REV[checkout_stamp]:
# Fail on occurrence of different revision for the already downloaded repository
raise YAMLProcessingError(f"ERROR: Repository {self.url} has two revisions '{self.git_rev}' "
f"and '{_SEEN_REPOS_REV[checkout_stamp]}'", self.conf["rev"].mark)
else:
# Do not checkout repos for the second time
return checkout_stamp

_SEEN_REPOS_REV[checkout_stamp] = self.git_rev

_SEEN_REPOS.append(checkout_stamp)
self.generator.build(clone_target,
"git_clone",
variables={
Expand Down

0 comments on commit 19d2ec0

Please sign in to comment.