Skip to content

Commit

Permalink
Refactor the untracked files check
Browse files Browse the repository at this point in the history
  • Loading branch information
webknjaz committed Jan 28, 2020
1 parent 2d98cb1 commit ad71526
Showing 1 changed file with 20 additions and 12 deletions.
32 changes: 20 additions & 12 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,19 +259,27 @@ 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(
True for l in get_git_untracked_files()
if not l.startswith('.nox/build-release/') # current nox env is useful
)
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",
Expand Down

0 comments on commit ad71526

Please sign in to comment.