예제 #1
0
def update_bundle(bundle_path):
    working_directory = os.path.abspath(os.getcwd())
    os.chdir(bundle_path)
    git.submodule("foreach", "git", "fetch")
    # sh fails to find the subcommand so we use subprocess.
    subprocess.run(shlex.split(
        "git submodule foreach 'git checkout -q `git rev-list --tags --max-count=1`'"
    ),
                   stdout=subprocess.DEVNULL)

    status = StringIO()
    result = git.status("--short", _out=status)
    updates = []
    status = status.getvalue().strip()
    if status:
        for status_line in status.split("\n"):
            action, directory = status_line.split()
            if action != "M" or not directory.startswith("libraries"):
                raise RuntimeError("Unsupported updates")

            # Compute the tag difference.
            diff = StringIO()
            result = git.diff("--submodule=log", directory, _out=diff)
            diff_lines = diff.getvalue().split("\n")
            commit_range = diff_lines[0].split()[2]
            commit_range = commit_range.strip(":").split(".")
            old_commit = commit_to_tag(directory, commit_range[0])
            new_commit = commit_to_tag(directory, commit_range[-1])
            url = repo_remote_url(directory)
            summary = "\n".join(diff_lines[1:-1])
            updates.append((url[:-4], old_commit, new_commit, summary))
    os.chdir(working_directory)
    return updates
예제 #2
0
    def get_dirty_paths_by_status(self) -> Dict[str, List[Path]]:
        """
        Returns all paths that have a git status, grouped by change type.

        These can be staged, unstaged, or untracked.
        """
        output = zsplit(git.status("--porcelain", "-z").stdout.decode())
        return bucketize(
            output,
            key=lambda line: line[0],
            value_transform=lambda line: Path(line[3:]),
        )
예제 #3
0
    def _abort_if_dirty(self) -> None:
        """
            Raises RuntimeError if paths are untracked or staged.

            :param removed (list): Removed paths
            :raises RuntimeError: If the git repo is not in a clean state
        """
        output = git.status("--porcelain").stdout.decode().strip()
        if output:
            raise RuntimeError(  # TODO we can probably be more lenient
                "Found untracked or staged files. Diff-aware runs require a clean git state."
            )
예제 #4
0
def update_bundle(bundle_path):
    working_directory = os.path.abspath(os.getcwd())
    os.chdir(bundle_path)
    git.submodule("foreach", "git", "fetch")
    # Regular release tags are 'x.x.x'. Exclude tags that are alpha or beta releases.
    # They will contain a '-' in the tag, such as '3.0.0-beta.5'.
    # --exclude must be before --tags.
    # sh fails to find the subcommand so we use subprocess.
    subprocess.run(shlex.split(
        "git submodule foreach 'git checkout -q `git rev-list --exclude='*-*' --tags --max-count=1`'"
    ),
                   stdout=subprocess.DEVNULL)
    status = StringIO()
    result = git.status("--short", _out=status)
    updates = []
    status = status.getvalue().strip()
    if status:
        for status_line in status.split("\n"):
            action, directory = status_line.split()
            if directory.endswith("library_list.md"):
                continue
            if action != "M" or not directory.startswith("libraries"):
                raise RuntimeError("Unsupported updates")

            # Compute the tag difference.
            diff = StringIO()
            result = git.diff("--submodule=log", directory, _out=diff)
            diff_lines = diff.getvalue().split("\n")
            commit_range = diff_lines[0].split()[2]
            commit_range = commit_range.strip(":").split(".")
            old_commit = commit_to_tag(directory, commit_range[0])
            new_commit = commit_to_tag(directory, commit_range[-1])
            url = repo_remote_url(directory)
            summary = "\n".join(diff_lines[1:-1])
            updates.append((url[:-4], old_commit, new_commit, summary))
    os.chdir(working_directory)
    lib_list_updates = check_lib_links_md(bundle_path)
    if lib_list_updates:
        updates.append((
            "https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md",
            "NA", "NA", "  > Added the following libraries: {}".format(
                ", ".join(lib_list_updates))))

    return updates