Example #1
0
    def __init__(self, path: str = ".", config={}):

        self.fallback_enabled = False

        try:
            git_repo = Repo(path, search_parent_directories=True)
            self.repo = git_repo.git
        except:
            if config.get("fallback_to_build_date"):
                self.fallback_enabled = True
                logging.warning(
                    "[git-revision-date-localized-plugin] Unable to find a git directory and/or git is not installed."
                    " Option 'fallback_to_build_date' set to 'true': Falling back to build date"
                )
                return None
            else:
                logging.error(
                    "[git-revision-date-localized-plugin] Unable to find a git directory and/or git is not installed."
                    " To ignore this error, set option 'fallback_to_build_date: true'"
                )
                raise

        # Checks if user is running builds on CI
        # and raise appropriate warnings
        raise_ci_warnings(self.repo)
    def _get_repo(self, path: str) -> Git:
        if not os.path.isdir(path):
            path = os.path.dirname(path)

        if path not in self.repo_cache:
            self.repo_cache[path] = Repo(path,
                                         search_parent_directories=True).git
            # Checks if user is running builds on CI
            # and raise appropriate warnings
            raise_ci_warnings(self.repo_cache[path])

        return self.repo_cache[path]