Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions dvc/repo/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ def _diff_head_to_index(
granular: bool = False,
with_renames: bool = False,
) -> DiffResult:
from dvc.exceptions import NotDvcRepoError
from dvc.scm import RevError
from dvc_data.index import DataIndex

Expand All @@ -338,6 +339,11 @@ def _diff_head_to_index(
except RevError:
logger.debug("failed to switch to '%s'", head)
head_view = DataIndex()
except NotDvcRepoError as exc:
# NOTE: this only gets raised on subdir repos at the moment,
# which looks like a bug in `repo.switch`.
logger.warning(exc)
head_view = DataIndex()

with ui.progress(desc="Calculating diff between head/index", unit="entry") as pb:
return _diff(
Expand Down
19 changes: 13 additions & 6 deletions tests/func/test_data_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,25 @@ def test_tracked_directory_deep(M, tmp_dir, dvc, scm):
}


def test_new_empty_git_repo(M, tmp_dir, scm):
dvc = Repo.init()
@pytest.mark.parametrize("git_repo_state", ["unborn", "committed"])
@pytest.mark.parametrize("subdir", [True, False])
def test_new_dvc_repo(M, tmp_dir, scm, subdir, git_repo_state):
if git_repo_state == "committed":
tmp_dir.scm_gen("test", "test", commit="init")

is_empty = git_repo_state == "unborn"
dir_ = tmp_dir / "sub" if subdir else tmp_dir
dvc = Repo.init(dir_, subdir=subdir)
assert dvc.data_status() == {
**EMPTY_STATUS,
"git": M.dict(is_empty=True, is_dirty=True),
"git": M.dict(is_dirty=True, is_empty=is_empty),
}

tmp_dir.gen("foo", "foo")
dvc.add(["foo"])
dir_.gen("foo", "foo")
dvc.add([dir_ / "foo"])
assert dvc.data_status() == {
**EMPTY_STATUS,
"git": M.dict(is_empty=True, is_dirty=True),
"git": M.dict(is_empty=is_empty, is_dirty=True),
"committed": {"added": ["foo"]},
}

Expand Down
Loading