diff --git a/dvc/output.py b/dvc/output.py index 422e1fa574..00acb4ca7a 100644 --- a/dvc/output.py +++ b/dvc/output.py @@ -752,8 +752,9 @@ def commit(self, filter_info=None, relink=True) -> None: granular = ( self.is_dir_checksum and filter_info and filter_info != self.fs_path ) + hardlink = relink and next(iter(self.cache.cache_types), None) == "hardlink" if granular: - obj = self._commit_granular_dir(filter_info, hardlink=False) + obj = self._commit_granular_dir(filter_info, hardlink=hardlink) else: staging, _, obj = self._build( self.cache, @@ -771,7 +772,7 @@ def commit(self, filter_info=None, relink=True) -> None: self.cache, {obj.hash_info}, shallow=False, - hardlink=False, + hardlink=hardlink, callback=cb, ) if relink: @@ -1399,12 +1400,14 @@ def add( # noqa: C901 assert staging assert obj.hash_info + + hardlink = relink and next(iter(self.cache.cache_types), None) == "hardlink" with TqdmCallback(desc=f"Adding {self} to cache", unit="file") as cb: otransfer( staging, self.cache, {obj.hash_info}, - hardlink=False, + hardlink=hardlink, shallow=False, callback=cb, )