Fix default ignore patterns for upload_folder (#1549)

* fix default ignore patterns for upload_folder

* update repo_utils
This commit is contained in:
Xingjun.Wang
2025-11-18 15:26:10 +08:00
committed by GitHub
parent a66907aecd
commit debabe53a6
2 changed files with 3 additions and 10 deletions

View File

@@ -2304,12 +2304,11 @@ class HubApi:
allow_patterns = allow_patterns if allow_patterns else None
ignore_patterns = ignore_patterns if ignore_patterns else None
# Ignore .git folder
# Ignore .git .cache folders
if ignore_patterns is None:
ignore_patterns = []
ignore_patterns = DEFAULT_IGNORE_PATTERNS
elif isinstance(ignore_patterns, str):
ignore_patterns = [ignore_patterns]
ignore_patterns += DEFAULT_IGNORE_PATTERNS
commit_message = (
commit_message if commit_message is not None else f'Upload to {repo_id} on ModelScope hub'

View File

@@ -30,8 +30,6 @@ DEFAULT_IGNORE_PATTERNS = [
'*/.cache',
'**/.cache/**',
]
# Forbidden to commit these folders
FORBIDDEN_FOLDERS = ['.git', '.cache']
UploadMode = Literal['lfs', 'normal']
@@ -555,11 +553,7 @@ def _validate_path_in_repo(path_in_repo: str) -> str:
f"Invalid `path_in_repo` in CommitOperation: '{path_in_repo}'")
if path_in_repo.startswith('./'):
path_in_repo = path_in_repo[2:]
for forbidden in FORBIDDEN_FOLDERS:
if any(part == forbidden for part in path_in_repo.split('/')):
raise ValueError(
f"Invalid `path_in_repo` in CommitOperation: cannot update files under a '{forbidden}/' folder (path:"
f" '{path_in_repo}').")
return path_in_repo