|
4 | 4 | from typing import TYPE_CHECKING, Optional, TypedDict, Union
|
5 | 5 |
|
6 | 6 | from dvc.fs.callbacks import DEFAULT_CALLBACK
|
| 7 | +from dvc.log import logger |
| 8 | +from dvc.scm import RevError |
7 | 9 | from dvc.ui import ui
|
8 | 10 | from dvc_data.index.view import DataIndexView
|
9 | 11 |
|
|
14 | 16 | from dvc_data.index import BaseDataIndex, DataIndex, DataIndexKey
|
15 | 17 | from dvc_data.index.diff import Change
|
16 | 18 |
|
| 19 | +logger = logger.getChild(__name__) |
| 20 | + |
17 | 21 |
|
18 | 22 | def posixpath_to_os_path(path: str) -> str:
|
19 | 23 | return path.replace(posixpath.sep, os.path.sep)
|
@@ -220,12 +224,18 @@ def _diff_head_to_index(
|
220 | 224 | filter_keys: Optional[list["DataIndexKey"]] = None,
|
221 | 225 | granular: bool = False,
|
222 | 226 | ) -> dict[str, list[str]]:
|
| 227 | + from dvc_data.index import DataIndex |
| 228 | + |
223 | 229 | index = repo.index.data["repo"]
|
224 | 230 | index_view = filter_index(index, filter_keys=filter_keys)
|
225 | 231 |
|
226 |
| - with repo.switch(head): |
227 |
| - head_index = repo.index.data["repo"] |
228 |
| - head_view = filter_index(head_index, filter_keys=filter_keys) |
| 232 | + try: |
| 233 | + with repo.switch(head): |
| 234 | + head_index = repo.index.data["repo"] |
| 235 | + head_view = filter_index(head_index, filter_keys=filter_keys) |
| 236 | + except RevError: |
| 237 | + logger.debug("failed to switch to '%s'", head) |
| 238 | + head_view = DataIndex() |
229 | 239 |
|
230 | 240 | with ui.progress(desc="Calculating diff between head/index", unit="entry") as pb:
|
231 | 241 | return _diff(
|
|
0 commit comments