| 750 | raise CheckoutError(exc.paths, {}) # noqa: B904 |
| 751 | |
| 752 | def commit(self, filter_info=None, relink=True) -> None: |
| 753 | if not self.exists: |
| 754 | raise self.DoesNotExistError(self) |
| 755 | |
| 756 | assert self.hash_info |
| 757 | |
| 758 | if self.use_cache: |
| 759 | granular = ( |
| 760 | self.is_dir_checksum and filter_info and filter_info != self.fs_path |
| 761 | ) |
| 762 | hardlink = relink and next(iter(self.cache.cache_types), None) == "hardlink" |
| 763 | if granular: |
| 764 | obj = self._commit_granular_dir(filter_info, hardlink=hardlink) |
| 765 | else: |
| 766 | staging, _, obj = self._build( |
| 767 | self.cache, |
| 768 | filter_info or self.fs_path, |
| 769 | self.fs, |
| 770 | self.hash_name, |
| 771 | ignore=self.dvcignore, |
| 772 | ) |
| 773 | with TqdmCallback( |
| 774 | desc=f"Committing {self} to cache", |
| 775 | unit="file", |
| 776 | ) as cb: |
| 777 | otransfer( |
| 778 | staging, |
| 779 | self.cache, |
| 780 | {obj.hash_info}, |
| 781 | shallow=False, |
| 782 | hardlink=hardlink, |
| 783 | callback=cb, |
| 784 | ) |
| 785 | if relink: |
| 786 | assert self.repo |
| 787 | rel = self.fs.relpath(filter_info or self.fs_path) |
| 788 | with CheckoutCallback(desc=f"Checking out {rel}", unit="files") as cb: |
| 789 | self._checkout( |
| 790 | filter_info or self.fs_path, |
| 791 | self.fs, |
| 792 | obj, |
| 793 | self.cache, |
| 794 | relink=True, |
| 795 | state=self.repo.state, |
| 796 | prompt=prompt.confirm, |
| 797 | progress_callback=cb, |
| 798 | old=obj, |
| 799 | ) |
| 800 | self.set_exec() |
| 801 | |
| 802 | def _commit_granular_dir(self, filter_info, hardlink) -> Optional["HashFile"]: |
| 803 | prefix = self.fs.parts(self.fs.relpath(filter_info, self.fs_path)) |