lister: Make excluding directories work on Windows.

This commit is contained in:
derAnfaenger 2017-09-27 11:11:52 +02:00
parent 9ddb5518f4
commit 174d11ec36

View file

@ -3,7 +3,6 @@ from __future__ import print_function
from __future__ import absolute_import from __future__ import absolute_import
import os import os
from os.path import abspath
import sys import sys
import subprocess import subprocess
import re import re
@ -54,7 +53,7 @@ def list_files(targets=[], ftypes=[], use_shebang=True, modified_only=False,
If ftypes is [], all files are included. If ftypes is [], all files are included.
use_shebang - Determine file type of extensionless files from their shebang. use_shebang - Determine file type of extensionless files from their shebang.
modified_only - Only include files which have been modified. modified_only - Only include files which have been modified.
exclude - List of paths to be excluded, relative to repository root. exclude - List of files or directories to be excluded, relative to repository root.
group_by_ftype - If True, returns a dict of lists keyed by file type. group_by_ftype - If True, returns a dict of lists keyed by file type.
If False, returns a flat list of files. If False, returns a flat list of files.
extless_only - Only include extensionless files in output. extless_only - Only include extensionless files in output.
@ -66,7 +65,7 @@ def list_files(targets=[], ftypes=[], use_shebang=True, modified_only=False,
# sys.argv as str, so that battle is already lost. Settle for hoping # sys.argv as str, so that battle is already lost. Settle for hoping
# everything is UTF-8. # everything is UTF-8.
repository_root = subprocess.check_output(['git', 'rev-parse', '--show-toplevel']).strip().decode('utf-8') repository_root = subprocess.check_output(['git', 'rev-parse', '--show-toplevel']).strip().decode('utf-8')
exclude_abspaths = [os.path.normpath(os.path.join(repository_root, fpath)) for fpath in exclude] exclude_abspaths = [os.path.abspath(os.path.join(repository_root, fpath)) for fpath in exclude]
cmdline = ['git', 'ls-files'] + targets cmdline = ['git', 'ls-files'] + targets
if modified_only: if modified_only:
@ -84,8 +83,8 @@ def list_files(targets=[], ftypes=[], use_shebang=True, modified_only=False,
ext = os.path.splitext(fpath)[1] ext = os.path.splitext(fpath)[1]
if extless_only and ext: if extless_only and ext:
continue continue
absfpath = abspath(fpath) absfpath = os.path.abspath(fpath)
if any(absfpath == expath or absfpath.startswith(expath + '/') if any(absfpath == expath or absfpath.startswith(os.path.abspath(expath) + os.sep)
for expath in exclude_abspaths): for expath in exclude_abspaths):
continue continue