diff --git a/dvc/command/diff.py b/dvc/command/diff.py index 74f15edf5..ae7bc56a4 100644 --- a/dvc/command/diff.py +++ b/dvc/command/diff.py @@ -32,13 +32,16 @@ def add_parser(subparsers, parent_parser): formatter_class=argparse.RawDescriptionHelpFormatter, ) diff_parser.add_argument( - "a_ref", help="Git reference from which diff calculates" + "a_ref", + help="Git reference from which diff calculates (defaults to HEAD)", + nargs="?", + default="HEAD" ) diff_parser.add_argument( "b_ref", help=( "Git reference until which diff calculates, if omitted " - "diff shows the difference between current HEAD and a_ref" + "diff shows the difference between the working tree and a_ref" ), nargs="?", ) diff --git a/dvc/repo/diff.py b/dvc/repo/diff.py index dda1e0c79..9d3604e6c 100644 --- a/dvc/repo/diff.py +++ b/dvc/repo/diff.py @@ -1,8 +1,8 @@ import os import collections -from . import locked -from ..compat import fspath +from dvc.repo import locked +from dvc.compat import fspath Diffable = collections.namedtuple("Diffable", "filename, checksum, size") @@ -12,16 +12,14 @@ Diffable.__doc__ = "Common interface for comparable entries." def diffable_from_output(output): try: size = os.path.getsize(fspath(output.path_info)) - except OSError: + except FileNotFoundError: size = None - return Diffable( - filename=str(output.path_info), checksum=output.checksum, size=size - ) + return Diffable(filename=str(output), checksum=output.checksum, size=size) @locked -def diff(self, a_ref=None, b_ref=None, *, target=None): +def diff(self, a_ref="HEAD", b_ref=None, *, target=None): """ By default, it compares the working tree with the last commit's tree. @@ -30,7 +28,6 @@ def diff(self, a_ref=None, b_ref=None, *, target=None): This implementation differs from `git diff`, since DVC doesn't have the concept of `index`, `dvc diff` would be the same as `dvc diff HEAD`. """ - a_ref = a_ref or "HEAD" outs = {} for branch in self.brancher(revs=[a_ref, b_ref]):