Commit 8ae334d6 authored by Pierre Smeyers's avatar Pierre Smeyers
Browse files

fix: don't fail when Git repo has no commit

parent 3f212489
Loading
Loading
Loading
Loading
+19 −11
Original line number Diff line number Diff line
@@ -361,7 +361,7 @@ class Synchronizer:
                self.handle_error(ge)

        print(
            f"    - git repository: {AnsiColors.HYELLOW}updated{AnsiColors.RESET} ({src_default_branch} on #{src_latest_commit.get_id()})"
            f"    - git repository: {AnsiColors.HYELLOW}updated{AnsiColors.RESET} ({src_default_branch} on #{src_latest_commit.get_id() if src_latest_commit else 'n/a'})"
        )

    # Synchronizes a GitLab project
@@ -441,7 +441,7 @@ class Synchronizer:
                            "visibility": dest_visibility,
                            "description": src_project.description,
                            # ??? "default_branch": src_default_branch,
                            "namespace_id": dest_parent_group.get_id() if dest_parent_group else None,
                            "namespace_id": dest_parent_group.get_id(),
                            "issues_access_level": "disabled",
                            "merge_requests_access_level": "disabled",
                        }
@@ -462,9 +462,10 @@ class Synchronizer:
        src_web_url = src_project.web_url
        dest_avatar_url = dest_project.avatar_url
        dest_web_url = dest_project.web_url
        if (
            (src_avatar_url is None or src_avatar_url == f"{src_web_url}/-/avatar")
            or (dest_avatar_url is not None and dest_avatar_url != f"{dest_web_url}/-/avatar" and not self.force_update_avatar)
        if (src_avatar_url is None or src_avatar_url == f"{src_web_url}/-/avatar") or (
            dest_avatar_url is not None
            and dest_avatar_url != f"{dest_web_url}/-/avatar"
            and not self.force_update_avatar
        ):
            # image up-to-date
            print(
@@ -474,7 +475,10 @@ class Synchronizer:
            print(
                f"    - avatar image: {AnsiColors.HYELLOW}update needed{AnsiColors.RESET} ({src_avatar_url} / {dest_avatar_url})"
            )
        elif src_project.attributes.get("visibility", GlVisibility.public) != GlVisibility.public:
        elif (
            src_project.attributes.get("visibility", GlVisibility.public)
            != GlVisibility.public
        ):
            # no way to download the avatar image of a non-public project
            print(
                f"- avatar image: {AnsiColors.HGRAY}update needed{AnsiColors.HRED} skipped due to src project not public ({src_avatar_url} / {dest_avatar_url})"
@@ -625,8 +629,8 @@ class Synchronizer:
        # set/update avatar url
        src_avatar_url = src_group.avatar_url
        dest_avatar_url = dest_group.avatar_url
        if (
            src_avatar_url is None or (dest_avatar_url is not None and not self.force_update_avatar)
        if src_avatar_url is None or (
            dest_avatar_url is not None and not self.force_update_avatar
        ):
            # image up-to-date
            print(
@@ -902,7 +906,11 @@ def run() -> None:
    # retrieve dest parent group
    try:
        dest_parent_group_path = dirname(dest_sync_path)
        dest_parent_group = client.dest_client.groups.get(dest_parent_group_path) if dest_parent_group_path else None
        dest_parent_group = (
            client.dest_client.groups.get(dest_parent_group_path)
            if dest_parent_group_path
            else None
        )
    except GitlabGetError as ge:
        print(
            f"Dest parent group {AnsiColors.BLUE}{dirname(dest_sync_path)}{AnsiColors.RESET}: get {AnsiColors.HRED}failed{AnsiColors.RESET}",