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
10 changes: 5 additions & 5 deletions dvc/command/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ def _format(diff):
dir/
dir/1

An example of a diff formatted when entries contain checksums:
An example of a diff formatted when entries contain hash:

Added:
d3b07384 foo
Expand Down Expand Up @@ -66,7 +66,7 @@ def _digest(checksum):

for entry in entries:
path = entry["path"]
checksum = entry.get("checksum")
checksum = entry.get("hash")
summary[state] += 1 if not path.endswith(os.sep) else 0
content.append(
"{space}{checksum}{separator}{path}".format(
Expand Down Expand Up @@ -100,10 +100,10 @@ def run(self):
if not any(diff.values()):
return 0

if not self.args.checksums:
if not self.args.show_hash:
for _, entries in diff.items():
for entry in entries:
del entry["checksum"]
del entry["hash"]

if self.args.show_json:
res = json.dumps(diff)
Expand Down Expand Up @@ -149,7 +149,7 @@ def add_parser(subparsers, parent_parser):
default=False,
)
diff_parser.add_argument(
"--checksums",
"--show-hash",
help="Display hash value for each entry",
action="store_true",
default=False,
Expand Down
6 changes: 3 additions & 3 deletions dvc/repo/diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ def _paths_checksums():
modified = sorted(set(old) & set(new))

return {
"added": [{"path": path, "checksum": new[path]} for path in added],
"deleted": [{"path": path, "checksum": old[path]} for path in deleted],
"added": [{"path": path, "hash": new[path]} for path in added],
"deleted": [{"path": path, "hash": old[path]} for path in deleted],
"modified": [
{"path": path, "checksum": {"old": old[path], "new": new[path]}}
{"path": path, "hash": {"old": old[path], "new": new[path]}}
for path in modified
if old[path] != new[path]
],
Expand Down
2 changes: 1 addition & 1 deletion scripts/completion/dvc.bash
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ _dvc_commit='-f --force -d --with-deps -R --recursive'
_dvc_commit_COMPGEN=_dvc_compgen_DVCFiles
_dvc_config='-u --unset --local --system --global'
_dvc_destroy='-f --force'
_dvc_diff='-t --show-json --checksums'
_dvc_diff='-t --show-json --show-hash'
_dvc_fetch='-j --jobs -r --remote -a --all-branches -T --all-tags -d --with-deps -R --recursive'
_dvc_fetch_COMPGEN=_dvc_compgen_DVCFiles
_dvc_get_url=''
Expand Down
3 changes: 1 addition & 2 deletions scripts/completion/dvc.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ _dvc_destroy=(

_dvc_diff=(
"--show-json[Format the output into a JSON]"
"--checksums[Display checksums for each entry]"
"--show-hash[Display hash value for each entry]"
"1:Old Git commit to compare (defaults to HEAD):"
"2:New Git commit to compare (defaults to the current workspace):"
)
Expand Down Expand Up @@ -254,7 +254,6 @@ _dvc_run=(

_dvc_status=(
{-j,--jobs}"[Number of jobs to run simultaneously.]:Number of jobs:"
"--show-checksums[Show checksums instead of file names.]"
{-q,--quiet}"[Suppresses all output. Exit with 0 if pipelines are up to date, otherwise 1.]"
{-c,--cloud}"[Show status of a local cache compared to a remote repository.]"
{-r,--remote}"[Remote repository to compare local cache to.]:Remote repository:"
Expand Down
40 changes: 17 additions & 23 deletions tests/func/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def test_added(tmp_dir, scm, dvc):
tmp_dir.dvc_gen("file", "text")

assert dvc.diff() == {
"added": [{"path": "file", "checksum": digest("text")}],
"added": [{"path": "file", "hash": digest("text")}],
"deleted": [],
"modified": [],
}
Expand All @@ -41,15 +41,15 @@ def test_no_cache_entry(tmp_dir, scm, dvc):

assert dvc.diff() == {
"added": [
{"path": os.path.join("dir", ""), "checksum": dir_checksum},
{"path": os.path.join("dir", "1"), "checksum": digest("1")},
{"path": os.path.join("dir", "2"), "checksum": digest("2")},
{"path": os.path.join("dir", ""), "hash": dir_checksum},
{"path": os.path.join("dir", "1"), "hash": digest("1")},
{"path": os.path.join("dir", "2"), "hash": digest("2")},
],
"deleted": [],
"modified": [
{
"path": "file",
"checksum": {"old": digest("first"), "new": digest("second")},
"hash": {"old": digest("first"), "new": digest("second")},
}
],
}
Expand All @@ -61,7 +61,7 @@ def test_deleted(tmp_dir, scm, dvc):

assert dvc.diff() == {
"added": [],
"deleted": [{"path": "file", "checksum": digest("text")}],
"deleted": [{"path": "file", "hash": digest("text")}],
"modified": [],
}

Expand All @@ -76,7 +76,7 @@ def test_modified(tmp_dir, scm, dvc):
"modified": [
{
"path": "file",
"checksum": {"old": digest("first"), "new": digest("second")},
"hash": {"old": digest("first"), "new": digest("second")},
}
],
}
Expand All @@ -94,17 +94,13 @@ def test_refs(tmp_dir, scm, dvc):
assert dvc.diff("HEAD~1") == {
"added": [],
"deleted": [],
"modified": [
{"path": "file", "checksum": {"old": HEAD_1, "new": HEAD}}
],
"modified": [{"path": "file", "hash": {"old": HEAD_1, "new": HEAD}}],
}

assert dvc.diff("HEAD~2", "HEAD~1") == {
"added": [],
"deleted": [],
"modified": [
{"path": "file", "checksum": {"old": HEAD_2, "new": HEAD_1}}
],
"modified": [{"path": "file", "hash": {"old": HEAD_2, "new": HEAD_1}}],
}

with pytest.raises(DvcException, match=r"unknown Git revision 'missing'"):
Expand All @@ -128,42 +124,40 @@ def test_directories(tmp_dir, scm, dvc):
"added": [
{
"path": os.path.join("dir", ""),
"checksum": "5fb6b29836c388e093ca0715c872fe2a.dir",
"hash": "5fb6b29836c388e093ca0715c872fe2a.dir",
},
{"path": os.path.join("dir", "1"), "checksum": digest("1")},
{"path": os.path.join("dir", "2"), "checksum": digest("2")},
{"path": os.path.join("dir", "1"), "hash": digest("1")},
{"path": os.path.join("dir", "2"), "hash": digest("2")},
],
"deleted": [],
"modified": [],
}

assert dvc.diff(":/directory", ":/modify") == {
"added": [{"path": os.path.join("dir", "3"), "checksum": digest("3")}],
"added": [{"path": os.path.join("dir", "3"), "hash": digest("3")}],
"deleted": [],
"modified": [
{
"path": os.path.join("dir", ""),
"checksum": {
"hash": {
"old": "5fb6b29836c388e093ca0715c872fe2a.dir",
"new": "9b5faf37366b3370fd98e3e60ca439c1.dir",
},
},
{
"path": os.path.join("dir", "2"),
"checksum": {"old": digest("2"), "new": digest("two")},
"hash": {"old": digest("2"), "new": digest("two")},
},
],
}

assert dvc.diff(":/modify", ":/delete") == {
"added": [],
"deleted": [
{"path": os.path.join("dir", "2"), "checksum": digest("two")}
],
"deleted": [{"path": os.path.join("dir", "2"), "hash": digest("two")}],
"modified": [
{
"path": os.path.join("dir", ""),
"checksum": {
"hash": {
"old": "9b5faf37366b3370fd98e3e60ca439c1.dir",
"new": "83ae82fb367ac9926455870773ff09e6.dir",
},
Expand Down
31 changes: 13 additions & 18 deletions tests/unit/command/test_diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def test_default(mocker, caplog):
args = parse_args(["diff"])
cmd = args.func(args)
diff = {
"added": [{"path": "file", "checksum": "00000000"}],
"added": [{"path": "file", "hash": "00000000"}],
"deleted": [],
"modified": [],
}
Expand All @@ -23,21 +23,18 @@ def test_default(mocker, caplog):
) in caplog.text


def test_checksums(mocker, caplog):
args = parse_args(["diff", "--checksums"])
def test_show_hash(mocker, caplog):
args = parse_args(["diff", "--show-hash"])
cmd = args.func(args)
diff = {
"added": [],
"deleted": [
{"path": os.path.join("data", ""), "checksum": "XXXXXXXX.dir"},
{"path": os.path.join("data", "bar"), "checksum": "00000000"},
{"path": os.path.join("data", "foo"), "checksum": "11111111"},
{"path": os.path.join("data", ""), "hash": "XXXXXXXX.dir"},
{"path": os.path.join("data", "bar"), "hash": "00000000"},
{"path": os.path.join("data", "foo"), "hash": "11111111"},
],
"modified": [
{
"path": "file",
"checksum": {"old": "AAAAAAAA", "new": "BBBBBBBB"},
}
{"path": "file", "hash": {"old": "AAAAAAAA", "new": "BBBBBBBB"}}
],
}
mocker.patch("dvc.repo.Repo.diff", return_value=diff)
Expand All @@ -55,11 +52,11 @@ def test_checksums(mocker, caplog):
) in caplog.text


def test_json(mocker, caplog):
def test_show_json(mocker, caplog):
args = parse_args(["diff", "--show-json"])
cmd = args.func(args)
diff = {
"added": [{"path": "file", "checksum": "00000000"}],
"added": [{"path": "file", "hash": "00000000"}],
"deleted": [],
"modified": [],
}
Expand All @@ -71,23 +68,21 @@ def test_json(mocker, caplog):
assert '"modified": []' in caplog.text


def test_json_checksums(mocker, caplog):
args = parse_args(["diff", "--show-json", "--checksums"])
def test_show_json_and_hash(mocker, caplog):
args = parse_args(["diff", "--show-json", "--show-hash"])
cmd = args.func(args)

diff = {
"added": [
# py35: maintain a consistent key order for tests purposes
collections.OrderedDict(
[("path", "file"), ("checksum", "00000000")]
)
collections.OrderedDict([("path", "file"), ("hash", "00000000")])
],
"deleted": [],
"modified": [],
}
mocker.patch("dvc.repo.Repo.diff", return_value=diff)

assert 0 == cmd.run()
assert '"added": [{"path": "file", "checksum": "00000000"}]' in caplog.text
assert '"added": [{"path": "file", "hash": "00000000"}]' in caplog.text
assert '"deleted": []' in caplog.text
assert '"modified": []' in caplog.text