Skip to content

Commit

Permalink
Fix no / safety
Browse files Browse the repository at this point in the history
  • Loading branch information
timothycrosley committed Mar 1, 2021
1 parent 3df2ed4 commit f6b3fef
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions isort/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,12 @@ def _build_arg_parser() -> argparse.ArgumentParser:
dest="filename",
help="Provide the filename associated with a stream.",
)
target_group.add_argument(
"--no-preserve-root",
action="store_true",
default=False,
help="Tells isort not to treat / specially, allowing it to be ran on the root dir.",
)

output_group.add_argument(
"-a",
Expand Down Expand Up @@ -1000,6 +1006,7 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
remapped_deprecated_args = config_dict.pop("remapped_deprecated_args", False)
stream_filename = config_dict.pop("filename", None)
ext_format = config_dict.pop("ext_format", None)
no_preserve_root = config_dict.pop("no_preserve_root", None)
wrong_sorted_files = False
all_attempt_broken = False
no_valid_encodings = False
Expand Down Expand Up @@ -1037,11 +1044,18 @@ def main(argv: Optional[Sequence[str]] = None, stdin: Optional[TextIOWrapper] =
file_path=file_path,
extension=ext_format,
)
elif "/" in file_names and not no_preserve_root:
printer = create_terminal_printer(color=config.color_output)
printer.error("it is dangerous to operate recursively on '/'")
printer.error("use --no-preserve-root to override this failsafe")
sys.exit(1)
else:
if stream_filename:
printer = create_terminal_printer(color=config.color_output)
printer.error("Filename override is intended only for stream (-) sorting.")
sys.exit(1)
if file_names == ["/"]:
input("You've requested to run isort against your entire computer (/) are you sure? ")
skipped: List[str] = []
broken: List[str] = []

Expand Down

0 comments on commit f6b3fef

Please sign in to comment.