Skip to content

Commit

Permalink
Fix --delete in huggingface-cli upload command (#2129)
Browse files Browse the repository at this point in the history
* Fix --delete in huggingface-cli upload command

* doc
  • Loading branch information
Wauplin authored Mar 20, 2024
1 parent 45147c5 commit 57ee5fc
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -8447,7 +8447,7 @@ def _prepare_upload_folder_deletions(
filenames = self.list_repo_files(repo_id=repo_id, revision=revision, repo_type=repo_type, token=token)

# Compute relative path in repo
if path_in_repo:
if path_in_repo and path_in_repo not in (".", "./"):
path_in_repo = path_in_repo.strip("/") + "/" # harmonize
relpath_to_abspath = {
file[len(path_in_repo) :]: file for file in filenames if file.startswith(path_in_repo)
Expand Down
6 changes: 6 additions & 0 deletions tests/test_hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2317,6 +2317,12 @@ def test_delete_txt_in_sub_ignore_sub_file_txt(self):
self.assertEqual(added_files, {"sub/lfs_in_sub.bin"}) # no "sub/file.txt"
self.assertEqual(deleted_files, {"sub/file1.txt", "sub/file.txt"})

def test_delete_if_path_in_repo(self):
# Regression test for https://github.com/huggingface/huggingface_hub/pull/2129
operations = self._upload_folder_alias(path_in_repo=".", folder_path=self.cache_dir, delete_patterns="*")
deleted_files = {op.path_in_repo for op in operations if isinstance(op, CommitOperationDelete)}
assert deleted_files == {"file1.txt", "sub/file1.txt"} # all the 'old' files


@pytest.mark.usefixtures("fx_cache_dir")
class HfLargefilesTest(HfApiCommonTest):
Expand Down

0 comments on commit 57ee5fc

Please sign in to comment.