fix(data status): show committed changes in a new Git repository (#10790)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
This commit is contained in:
skshetry
2025-06-26 11:11:04 +00:00
committed by GitHub
co-authored by pre-commit-ci[bot]
parent aac32e1b64
commit e278c9cdf4
2 changed files with 24 additions and 4 deletions
+13 -3
View File
@@ -4,6 +4,8 @@ from collections.abc import Iterable
from typing import TYPE_CHECKING, Optional, TypedDict, Union
from dvc.fs.callbacks import DEFAULT_CALLBACK
from dvc.log import logger
from dvc.scm import RevError
from dvc.ui import ui
from dvc_data.index.view import DataIndexView
@@ -14,6 +16,8 @@ if TYPE_CHECKING:
from dvc_data.index import BaseDataIndex, DataIndex, DataIndexKey
from dvc_data.index.diff import Change
logger = logger.getChild(__name__)
def posixpath_to_os_path(path: str) -> str:
return path.replace(posixpath.sep, os.path.sep)
@@ -220,12 +224,18 @@ def _diff_head_to_index(
filter_keys: Optional[list["DataIndexKey"]] = None,
granular: bool = False,
) -> dict[str, list[str]]:
from dvc_data.index import DataIndex
index = repo.index.data["repo"]
index_view = filter_index(index, filter_keys=filter_keys)
with repo.switch(head):
head_index = repo.index.data["repo"]
head_view = filter_index(head_index, filter_keys=filter_keys)
try:
with repo.switch(head):
head_index = repo.index.data["repo"]
head_view = filter_index(head_index, filter_keys=filter_keys)
except RevError:
logger.debug("failed to switch to '%s'", head)
head_view = DataIndex()
with ui.progress(desc="Calculating diff between head/index", unit="entry") as pb:
return _diff(
+11 -1
View File
@@ -144,9 +144,19 @@ def test_new_empty_git_repo(M, tmp_dir, scm):
"git": M.dict(is_empty=True, is_dirty=True),
}
tmp_dir.gen("foo", "foo")
dvc.add(["foo"])
assert dvc.data_status() == {
**EMPTY_STATUS,
"git": M.dict(is_empty=True, is_dirty=True),
"committed": {"added": ["foo"]},
}
def test_noscm_repo(dvc):
def test_noscm_repo(tmp_dir, dvc):
assert dvc.data_status() == EMPTY_STATUS
tmp_dir.dvc_gen("foo", "foo")
assert dvc.data_status() == {**EMPTY_STATUS, "unchanged": ["foo"]}
def test_unchanged(M, tmp_dir, dvc, scm):