Skip to content

Commit 618f46c

Browse files
Ubuntuclaude
andcommitted
Fix dvx diff: read .dvc from git refs, propagate exit codes
- _get_cache_path_for_ref: Read .dvc file content directly from git using `git show ref:path` instead of broken switch() approach - main(): Capture return value from cli() instead of always returning 0 - CmdContentDiff.do_run(): Fix xdiff -> diff typo, capture return value 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 21beca6 commit 618f46c

2 files changed

Lines changed: 31 additions & 17 deletions

File tree

dvx/cli/main.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -768,8 +768,8 @@ def remote_list_cmd(ctx, global_, system, local):
768768
def main(argv=None):
769769
"""Main entry point."""
770770
try:
771-
cli(argv, standalone_mode=False)
772-
return 0
771+
result = cli(argv, standalone_mode=False)
772+
return result if result is not None else 0
773773
except click.ClickException as e:
774774
e.show()
775775
return e.exit_code

dvx/commands/content_diff.py

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -31,23 +31,37 @@ def _normalize_path(path: str) -> tuple[str, str]:
3131

3232
def _get_cache_path_for_ref(repo, dvc_path: str, ref: Optional[str]) -> Optional[str]:
3333
"""Get cache path for a .dvc file at a specific git ref."""
34-
from dvx.dvcfile import SingleStageFile
35-
from dvx.repo.brancher import switch
36-
37-
abs_path = os.path.abspath(dvc_path)
34+
import subprocess
35+
import yaml
3836

3937
try:
4038
if ref:
41-
with switch(repo, ref):
42-
dvcfile = SingleStageFile(repo, abs_path, verify=False)
43-
stage = dvcfile.stage
44-
if not stage.outs:
45-
return None
46-
out = stage.outs[0]
47-
if not out.hash_info or not out.hash_info.value:
48-
return None
49-
return out.cache_path
39+
# Read .dvc file content directly from git
40+
result = subprocess.run(
41+
["git", "show", f"{ref}:{dvc_path}"],
42+
capture_output=True, text=True, cwd=repo.root_dir
43+
)
44+
if result.returncode != 0:
45+
logger.debug(f"Failed to read {dvc_path} at {ref}: {result.stderr}")
46+
return None
47+
48+
dvc_content = yaml.safe_load(result.stdout)
49+
outs = dvc_content.get('outs', [])
50+
if not outs:
51+
return None
52+
53+
md5 = outs[0].get('md5', '')
54+
if not md5:
55+
return None
56+
57+
# Strip .dir suffix if present
58+
md5 = md5.replace('.dir', '')
59+
cache_path = os.path.join(repo.root_dir, '.dvc', 'cache', 'files', 'md5', md5[:2], md5[2:])
60+
return cache_path
5061
else:
62+
# Read from current working tree
63+
from dvx.dvcfile import SingleStageFile
64+
abs_path = os.path.abspath(dvc_path)
5165
dvcfile = SingleStageFile(repo, abs_path, verify=False)
5266
stage = dvcfile.stage
5367
if not stage.outs:
@@ -384,8 +398,8 @@ def do_run(self):
384398
argv.extend(self.args.args)
385399

386400
try:
387-
xdiff(argv, standalone_mode=False)
388-
return 0
401+
result = diff(argv, standalone_mode=False)
402+
return result if result is not None else 0
389403
except click.ClickException as e:
390404
e.show()
391405
return 1

0 commit comments

Comments
 (0)