Skip to content
GitLab
探索
项目
群组
代码片段
项目
群组
代码片段
/
帮助
帮助
支持
社区论坛
快捷键
?
提交反馈
登录
切换导航
菜单
打开侧边栏
ExternalRepo
isort
提交
9f49f0a8
未验证
提交
9f49f0a8
编辑于
3年前
作者:
Timothy Edmund Crosley
提交者:
GitHub
3年前
浏览文件
操作
下载
差异文件
Merge pull request #1900 from bmalehorn/bm/skip-gitignore-ls-files
skip-gitignore: use allow list, not deny list
上级
71c1e92a
1e22ced0
main
ci/general-ci-improvements
ci/release-workflow
dependabot/pip/black-24.3.0
dependabot/pip/idna-3.7
dependabot/pip/jinja2-3.1.4
hotfix-5.11.5
prepare-release-6.0.0
5.13.2
5.13.1
5.13.0
5.12.0
5.11.5
5.11.4
5.11.3
5.11.2
5.11.1
5.11.0
v5.11.3
无相关合并请求
变更
1
Hide whitespace changes
Inline
Side-by-side
显示
1 个更改的文件
isort/settings.py
+31
-21
isort/settings.py
有
31 个添加
和
21 个删除
+31
-21
isort/settings.py
+
31
-
21
浏览文件 @
9f49f0a8
...
...
@@ -238,7 +238,7 @@ class _Config:
reverse_sort
:
bool
=
False
star_first
:
bool
=
False
import_dependencies
=
Dict
[
str
,
str
]
git_
ignore
:
Dict
[
Path
,
Set
[
Path
]]
=
field
(
default_factory
=
dict
)
git_
ls_files
:
Dict
[
Path
,
Set
[
str
]]
=
field
(
default_factory
=
dict
)
format_error
:
str
=
"{error}: {message}"
format_success
:
str
=
"{success}: {message}"
sort_order
:
str
=
"natural"
...
...
@@ -552,7 +552,7 @@ class Config(_Config):
else
:
return
bool
(
_SHEBANG_RE
.
match
(
line
))
def
_check_folder_git
ignore
(
self
,
folder
:
str
)
->
Optional
[
Path
]:
def
_check_folder_git
_ls_files
(
self
,
folder
:
str
)
->
Optional
[
Path
]:
env
=
{
**
os
.
environ
,
"LANG"
:
"C.UTF-8"
}
try
:
topfolder_result
=
subprocess
.
check_output
(
# nosec # skipcq: PYL-W1510
...
...
@@ -563,26 +563,30 @@ class Config(_Config):
git_folder
=
Path
(
topfolder_result
.
rstrip
()).
resolve
()
files
:
List
[
str
]
=
[]
# don't check symlinks; either part of the repo and would be checked
# twice, or is external to the repo and git won't know anything about it
for
root
,
_dirs
,
git_files
in
os
.
walk
(
git_folder
,
followlinks
=
False
):
if
".git"
in
_dirs
:
_dirs
.
remove
(
".git"
)
for
git_file
in
git_files
:
files
.
append
(
os
.
path
.
join
(
root
,
git_file
))
git_options
=
[
"-C"
,
str
(
git_folder
),
"-c"
,
"core.quotePath="
]
try
:
ignored
=
subprocess
.
check_output
(
# nosec # skipcq: PYL-W1510
[
"git"
,
*
git_options
,
"check-ignore"
,
"-z"
,
"--stdin"
,
"--no-index"
],
# files committed to git
tracked_files
=
(
subprocess
.
check_output
(
# nosec # skipcq: PYL-W1510
[
"git"
,
"-C"
,
str
(
git_folder
),
"ls-files"
,
"-z"
],
encoding
=
"utf-8"
,
env
=
env
,
input
=
"
\0
"
.
join
(
files
),
)
except
subprocess
.
CalledProcessError
:
return
None
.
rstrip
(
"
\0
"
)
.
split
(
"
\0
"
)
)
# files that haven't been committed yet, but aren't ignored
tracked_files_others
=
(
subprocess
.
check_output
(
# nosec # skipcq: PYL-W1510
[
"git"
,
"-C"
,
str
(
git_folder
),
"ls-files"
,
"-z"
,
"--others"
,
"--exclude-standard"
],
encoding
=
"utf-8"
,
env
=
env
,
)
.
rstrip
(
"
\0
"
)
.
split
(
"
\0
"
)
)
self
.
git_ignore
[
git_folder
]
=
{
Path
(
f
)
for
f
in
ignored
.
rstrip
(
"
\0
"
).
split
(
"
\0
"
)}
self
.
git_ls_files
[
git_folder
]
=
{
str
(
git_folder
/
Path
(
f
))
for
f
in
tracked_files
+
tracked_files_others
}
return
git_folder
def
is_skipped
(
self
,
file_path
:
Path
)
->
bool
:
...
...
@@ -624,14 +628,20 @@ class Config(_Config):
git_folder
=
None
file_paths
=
[
file_path
,
file_path
.
resolve
()]
for
folder
in
self
.
git_
ignore
:
for
folder
in
self
.
git_
ls_files
:
if
any
(
folder
in
path
.
parents
for
path
in
file_paths
):
git_folder
=
folder
break
else
:
git_folder
=
self
.
_check_folder_git
ignore
(
str
(
file_path
.
parent
))
git_folder
=
self
.
_check_folder_git
_ls_files
(
str
(
file_path
.
parent
))
if
git_folder
and
any
(
path
in
self
.
git_ignore
[
git_folder
]
for
path
in
file_paths
):
# git_ls_files are good files you should parse. If you're not in the allow list, skip.
if
(
git_folder
and
not
file_path
.
is_dir
()
and
str
(
file_path
.
resolve
())
not
in
self
.
git_ls_files
[
git_folder
]
):
return
True
return
False
...
...
This diff is collapsed.
Click to expand it.
编辑
预览
支持
Markdown
0%
请重试
或
添加新附件
.
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录
菜单
探索
项目
群组
代码片段