Exemple #1
0
def find_conflicting_filenames(filenames: Sequence[str]) -> int:
    repo_files = set(cmd_output('git', 'ls-files').splitlines())
    repo_files |= directories_for(repo_files)
    relevant_files = set(filenames) | added_files()
    relevant_files |= directories_for(relevant_files)
    repo_files -= relevant_files
    retv = 0

    # new file conflicts with existing file
    conflicts = lower_set(repo_files) & lower_set(relevant_files)

    # new file conflicts with other new file
    lowercase_relevant_files = lower_set(relevant_files)
    for filename in set(relevant_files):
        if filename.lower() in lowercase_relevant_files:
            lowercase_relevant_files.remove(filename.lower())
        else:
            conflicts.add(filename.lower())

    if conflicts:
        conflicting_files = [
            x for x in repo_files | relevant_files if x.lower() in conflicts
        ]
        for filename in sorted(conflicting_files):
            print(f'Case-insensitivity conflict found: {filename}')
        retv = 1

    return retv
def find_conflicting_filenames(filenames):
    repo_files = set(cmd_output("git", "ls-files").splitlines())
    relevant_files = set(filenames) | added_files()
    repo_files -= relevant_files
    retv = 0

    # new file conflicts with existing file
    conflicts = lower_set(repo_files) & lower_set(relevant_files)

    # new file conflicts with other new file
    lowercase_relevant_files = lower_set(relevant_files)
    for filename in set(relevant_files):
        if filename.lower() in lowercase_relevant_files:
            lowercase_relevant_files.remove(filename.lower())
        else:
            conflicts.add(filename.lower())

    if conflicts:
        conflicting_files = [
            x for x in repo_files | relevant_files if x.lower() in conflicts
        ]
        for filename in sorted(conflicting_files):
            print("Case-insensitivity conflict found: {}".format(filename))
        retv = 1

    return retv
def find_conflicting_filenames(filenames):
    repo_files = set(cmd_output('git', 'ls-files').splitlines())
    relevant_files = set(filenames) | added_files()
    repo_files -= relevant_files
    retv = 0

    # new file conflicts with existing file
    conflicts = lower_set(repo_files) & lower_set(relevant_files)

    # new file conflicts with other new file
    lowercase_relevant_files = lower_set(relevant_files)
    for filename in set(relevant_files):
        if filename.lower() in lowercase_relevant_files:
            lowercase_relevant_files.remove(filename.lower())
        else:
            conflicts.add(filename.lower())

    if conflicts:
        conflicting_files = [
            x for x in repo_files | relevant_files
            if x.lower() in conflicts
        ]
        for filename in sorted(conflicting_files):
            print('Case-insensitivity conflict found: {0}'.format(filename))
        retv = 1

    return retv
def find_large_added_files(filenames: Sequence[str], maxkb: int) -> int:
    # Find all added files that are also in the list of files pre-commit tells
    # us about
    retv = 0
    for filename in (added_files() & set(filenames)) - lfs_files():
        kb = int(math.ceil(os.stat(filename).st_size / 1024))
        if kb > maxkb:
            print(f'{filename} ({kb} KB) exceeds {maxkb} KB.')
            retv = 1

    return retv
Exemple #5
0
def find_large_added_files(filenames, maxkb):
    # Find all added files that are also in the list of files pre-commit tells
    # us about
    filenames = (added_files() & set(filenames)) - lfs_files()

    retv = 0
    for filename in filenames:
        kb = int(math.ceil(os.stat(filename).st_size / 1024))
        if kb > maxkb:
            print('{0} ({1} KB) exceeds {2} KB.'.format(filename, kb, maxkb))
            retv = 1

    return retv
def find_large_added_files(filenames, maxkb):
    # Find all added files that are also in the list of files pre-commit tells
    # us about
    filenames = (added_files() & set(filenames)) - lfs_files()

    retv = 0
    for filename in filenames:
        kb = int(math.ceil(os.stat(filename).st_size / 1024))
        if kb > maxkb:
            print('{} ({} KB) exceeds {} KB.'.format(filename, kb, maxkb))
            retv = 1

    return retv
def find_large_added_files(
    filenames: Sequence[str],
    maxkb: int,
    *,
    enforce_all: bool = False,
) -> int:
    # Find all added files that are also in the list of files pre-commit tells
    # us about
    retv = 0
    filenames_filtered = set(filenames) - lfs_files()
    if not enforce_all:
        filenames_filtered &= added_files()

    for filename in filenames_filtered:
        kb = int(math.ceil(os.stat(filename).st_size / 1024))
        if kb > maxkb:
            print(f'{filename} ({kb} KB) exceeds {maxkb} KB.')
            retv = 1

    return retv