Describe the bug
When trying to format a project from the outside, the verbose output shows says that there are symbolic links that points outside of the project, but displays the wrong project path. This behavior seem to be triggered when the command is executed from outside a project on a folder.
To Reproduce
Consider the following tree:
.
└── home/
└── project/
├── .git
└── dir/
└── main.py
When trying to format a folder from home, this is the output:
$ black ./project --check --verbose
Identified `/path/to/home/project` as project root containing a .git directory.
Sources to be formatted: "."
project/.git ignored: is a symbolic link that points outside /path/to/home/project/project
project/.git ignored: matches the --exclude regular expression
project/dir ignored: is a symbolic link that points outside /path/to/home/project/project
project/dir/file.py ignored: is a symbolic link that points outside /path/to/home/project/project
would reformat project/dir/file.py
Oh no! 💥 💔 💥
1 file would be reformatted.
Notice that the messageFILEPATH ignored: is a symbolic link that points outside PROJECTPATH displays a wrong PROJECTPATH (should be /path/to/home/project/ instead of /path/to/home/project/project).
Same happens when using black ./project/dir:
$ black ./project/dir --check --verbose
Identified `/path/to/home/project` as project root containing a .git directory.
Sources to be formatted: "dir"
project/dir/file.py ignored: is a symbolic link that points outside /path/to/home/project/project/dir
would reformat project/dir/file.py
Oh no! 💥 💔 💥
1 file would be reformatted.
Expected behavior
Display each path once (and correctly):
$ black ./project/ --check --verbose
Identified `/path/to/home/project` as project root containing a .git directory.
Sources to be formatted: "."
/path/to/home/project/.git ignored: matches the --exclude regular expression
would reformat /path/to/home/project/dir/file.py
Oh no! 💥 💔 💥
1 file would be reformatted.
$ black ./project/dir/ --check --verbose
Identified `/path/to/home/project` as project root containing a .git directory.
Sources to be formatted: "dir"
would reformat /path/to/home/project/dir/file.py
Oh no! 💥 💔 💥
1 file would be reformatted.
Environment
- Black's version: main
- OS and Python version: Linux/Python 3.8.10
Additional context
This change produces the expected behavior:
diff --git a/src/black/__init__.py b/src/black/__init__.py
index 7d7ddbe..2897c5b 100644
--- a/src/black/__init__.py
+++ b/src/black/__init__.py
@@ -666,10 +666,11 @@ def get_sources(
sources.add(p)
elif p.is_dir():
+ p = root / normalize_path_maybe_ignore(p, ctx.obj["root"], report)
if using_default_exclude:
gitignore = {
root: root_gitignore,
- root / p: get_gitignore(p),
+ p: get_gitignore(p),
}
sources.update(
gen_python_files(
I'll try to submit a PR. I'm trying to figure out how to test this.
Describe the bug
When trying to format a project from the outside, the verbose output shows says that there are symbolic links that points outside of the project, but displays the wrong project path. This behavior seem to be triggered when the command is executed from outside a project on a folder.
To Reproduce
Consider the following tree:
When trying to format a folder from
home, this is the output:Notice that the message
FILEPATH ignored: is a symbolic link that points outside PROJECTPATHdisplays a wrong PROJECTPATH (should be/path/to/home/project/instead of/path/to/home/project/project).Same happens when using
black ./project/dir:Expected behavior
Display each path once (and correctly):
Environment
Additional context
This change produces the expected behavior:
I'll try to submit a PR. I'm trying to figure out how to test this.