| 96 | |
| 97 | |
| 98 | def test_diff_no_cache(tmp_dir, scm, dvc): |
| 99 | (stage,) = tmp_dir.dvc_gen({"dir": {"file": "file content"}}, commit="first") |
| 100 | scm.tag("v1") |
| 101 | dvc.cache.local.clear() |
| 102 | old_digest = stage.outs[0].hash_info.value |
| 103 | dir_path = os.path.join("dir", "") |
| 104 | |
| 105 | default_result = { |
| 106 | "added": [], |
| 107 | "deleted": [], |
| 108 | "modified": [], |
| 109 | "renamed": [], |
| 110 | "not in cache": [], |
| 111 | } |
| 112 | |
| 113 | assert dvc.diff("v1") == default_result | { |
| 114 | "not in cache": [{"path": dir_path, "hash": old_digest}], |
| 115 | } |
| 116 | assert dvc.diff("HEAD", "v1") == {} |
| 117 | assert dvc.diff("v1", "HEAD") == {} |
| 118 | |
| 119 | (stage,) = tmp_dir.dvc_gen( |
| 120 | {"dir": {"file": "modified file content"}}, commit="first" |
| 121 | ) |
| 122 | scm.tag("v2") |
| 123 | new_digest = stage.outs[0].hash_info.value |
| 124 | |
| 125 | assert dvc.diff("v2") == {} |
| 126 | assert dvc.diff("v1") == default_result | { |
| 127 | "modified": [ |
| 128 | {"path": dir_path, "hash": {"old": old_digest, "new": new_digest}} |
| 129 | ], |
| 130 | "not in cache": [{"path": dir_path, "hash": old_digest}], |
| 131 | } |
| 132 | assert dvc.diff("v1", "v2") == default_result | { |
| 133 | "modified": [ |
| 134 | {"path": dir_path, "hash": {"old": old_digest, "new": new_digest}} |
| 135 | ], |
| 136 | } |
| 137 | |
| 138 | remove(dvc.cache.local.path) |
| 139 | # drop the cache so that we can test as if we don't know what entries are |
| 140 | # in the missing cache entry. |
| 141 | dvc.drop_data_index() |
| 142 | |
| 143 | assert dvc.diff("v2") == default_result | { |
| 144 | "not in cache": [{"path": dir_path, "hash": new_digest}], |
| 145 | } |
| 146 | assert dvc.diff("v1") == default_result | { |
| 147 | "modified": [ |
| 148 | {"path": dir_path, "hash": {"old": old_digest, "new": new_digest}} |
| 149 | ], |
| 150 | "not in cache": [{"path": dir_path, "hash": old_digest}], |
| 151 | } |
| 152 | assert dvc.diff("v2", "v1") == default_result | { |
| 153 | "modified": [ |
| 154 | {"path": dir_path, "hash": {"old": new_digest, "new": old_digest}} |
| 155 | ], |