diff --git a/dvc/repo/diff.py b/dvc/repo/diff.py index 5cbfe6640..d49b7e3ac 100644 --- a/dvc/repo/diff.py +++ b/dvc/repo/diff.py @@ -156,8 +156,13 @@ def diff( for target in old_missing & new_missing: raise FileNotFoundError(errno.ENOENT, os.strerror(errno.ENOENT), target) - old = indexes[a_rev] - new = indexes[b_rev] + if len(indexes.keys()) == 1: + # both a_rev and b_rev point to the same sha, nothing to compare + old = None + new = None + else: + old = indexes[a_rev] + new = indexes[b_rev] with ui.status("Calculating diff"): return _diff(old, new, with_missing=with_missing) diff --git a/tests/func/test_diff.py b/tests/func/test_diff.py index 8b0280063..b1b09d993 100644 --- a/tests/func/test_diff.py +++ b/tests/func/test_diff.py @@ -21,6 +21,14 @@ def test_no_scm(tmp_dir, dvc): dvc.diff() +def test_same_rev(tmp_dir, scm, dvc): + tmp_dir.dvc_gen("file", "text", commit="add file") + + assert not dvc.diff("HEAD", "HEAD") + assert not dvc.diff("HEAD", "master") + assert not dvc.diff("master", "HEAD") + + def test_added(tmp_dir, scm, dvc): tmp_dir.dvc_gen("file", "text")