Exemplo n.º 1
0
def _fix_inner(
    repo: str,
    apply_fix: Callable[[], None],
    check_fix: Callable[[], None],
    config: Config,
    commit: Commit,
    autofix_settings: AutofixSettings,
) -> None:
    with repo_context(repo, use_color=autofix_settings.color):
        branch_name = f'all-repos_autofix_{commit.branch_name}'
        run('git', 'checkout', '--quiet', 'origin/master', '-b', branch_name)

        apply_fix()

        diff = run('git', 'diff', 'origin/master', '--exit-code', check=False)
        if not diff.returncode:
            return

        check_fix()

        if (autofix_settings.interactive
                and not _interactive_check(use_color=autofix_settings.color)):
            return

        commit_message = (
            f'{commit.msg}\n\n'
            f'Committed via https://github.com/asottile/all-repos')
        commit_cmd: Tuple[str, ...] = (
            'git',
            'commit',
            '--quiet',
            '-a',
            '-m',
            commit_message,
        )
        if commit.author:
            commit_cmd += ('--author', commit.author)

        run(*commit_cmd)

        if autofix_settings.dry_run:
            return

        config.push(config.push_settings, branch_name)
Exemplo n.º 2
0
def grep(config: Config, grep_args: Sequence[str]) -> dict[str, bytes]:
    repos = config.get_cloned_repos()
    ret = {}
    for repo in repos:
        repo, returncode, stdout = grep_result(config, repo, grep_args)
        if returncode == 0:
            ret[repo] = stdout
        elif returncode != 1:
            raise GrepError(returncode)
    return ret
Exemplo n.º 3
0
def find_files(config: Config, pattern: str) -> Dict[str, List[bytes]]:
    regex = re.compile(pattern.encode())
    repos = config.get_cloned_repos()
    ret = {}
    for repo in repos:
        repo, filenames = ls_files(config, repo)
        matched = [f for f in filenames if regex.search(f)]
        if matched:
            ret[repo] = matched
    return ret
Exemplo n.º 4
0
def find_repos(
    config: Config,
    *,
    ls_files_cmd: Sequence[str],
) -> Generator[str, None, None]:
    for repo in config.get_cloned_repos():
        repo_dir = os.path.join(config.output_dir, repo)
        if subprocess.run(
            ('git', '-C', repo_dir, *ls_files_cmd[1:]),
                check=True,
                stdout=subprocess.PIPE,
        ).stdout:
            yield repo_dir
Exemplo n.º 5
0
def find_repos(config: Config) -> Set[str]:
    return {
        str(Path(config.output_dir) / repo)
        for repo in config.get_cloned_repos()
    }