Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid too long Git command lines on Windows [WinError 206] #542

Merged
merged 7 commits into from
Mar 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions src/darker/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from pathlib import Path
from typing import Collection, Generator, List, Optional, Tuple

import darker.black_compat
from darker.black_diff import (
BlackConfig,
filter_python_files,
Expand Down Expand Up @@ -572,9 +573,15 @@ def main( # pylint: disable=too-many-locals,too-many-branches,too-many-statemen
else:
# In other modes, only reformat files which have been modified.
if git_is_repository(root):
changed_files_to_reformat = git_get_modified_python_files(
files_to_process, revrange, root
)
# Get the modified files only.
repo_root = darker.black_compat.find_project_root([str(root)])
changed_files = {
(repo_root / file).relative_to(root)
for file in git_get_modified_python_files(paths, revrange, repo_root)
}
# Filter out changed files that are not supposed to be processed
changed_files_to_reformat = files_to_process.intersection(changed_files)

else:
changed_files_to_reformat = files_to_process
black_exclude = {
Expand Down
26 changes: 26 additions & 0 deletions src/darker/tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@
# pylint: disable=use-dict-literal

import logging
import random
import re
import string
import sys
from argparse import ArgumentError
from io import BytesIO
from pathlib import Path
Expand All @@ -28,6 +31,11 @@
from darker.verification import NotEquivalentError


def randomword(length):
letters = string.ascii_lowercase
return "".join(random.choice(letters) for _i in range(length))


def _replace_diff_timestamps(text, replacement="<timestamp>"):
return re.sub(r"\d{4}-\d\d-\d\d \d\d:\d\d:\d\d\.\d\d\d\d\d\d", replacement, text)

Expand Down Expand Up @@ -932,3 +940,21 @@ def test_stdout_path_resolution(git_repo, capsys):

assert result == 0
assert capsys.readouterr().out == 'print("foo")\n'


def test_long_command_length(git_repo):
# For PR #542 - large character count for changed files
# on windows breaks subprocess
# Need to exceed 32762 characters
files = {}
path = "src"
for _f in range(0, 4):
# Of course windows limits the path length too
path = f"{path}/{randomword(30)}"

for _d in range(0, 210):
files[f"{path}/{randomword(30)}.py"] = randomword(10)

git_repo.add(files, commit="Add all the files")
result = darker.__main__.main(["--diff", "--check", "src"])
assert result == 0
Loading