Refactor the untracked files check

Co-Authored-By: Pradyun Gedam <pradyunsg@gmail.com>
This commit is contained in:
Sviatoslav Sydorenko 2020-01-28 17:21:02 +01:00
parent 75f8c6d6ff
commit 6a0b1f2675
No known key found for this signature in database
GPG Key ID: 9345E8FEA89CA455
1 changed files with 21 additions and 12 deletions

View File

@ -262,19 +262,28 @@ def build_dists(session):
session.log(
"# Check if there's any Git-untracked files before building the wheel",
)
has_git_untracked_files = any(
bool(l) for l in
# session.run doesn't seem to return any output
subprocess.check_output(
(
"git", "ls-files", "--ignored", "--exclude-standard",
"--others", "--", ".",
),
text=True,
).split('\n')
if not l.startswith('.nox/build-release/') # exclude nox env file
def get_git_untracked_files():
"""List all local file paths that aren't tracked by Git."""
git_ls_files_cmd = (
"git", "ls-files", "--ignored", "--exclude-standard",
"--others", "--", ".",
)
# session.run doesn't seem to return any output:
ls_files_out = subprocess.check_output(git_ls_files_cmd, text=True)
ls_files_out_lines = ls_files_out.splitlines()
for file_name in ls_files_out_lines:
if file_name.strip(): # it's useless if empty
continue
yield file_name
has_forbidden_git_untracked_files = any(
# Don't report the environment this session is running in
not untracked_file.startswith('.nox/build-release/')
for untracked_file in get_git_untracked_files()
)
if has_git_untracked_files:
if has_forbidden_git_untracked_files:
session.error(
"There are untracked files in the working directory. "
"Remove them and try again",