# Buggy code
def brancher(  # noqa: E302
    self, revs=None, all_branches=False, all_tags=False, all_commits=False
):
    """Generator that iterates over specified revisions.

    Args:
        revs (list): a list of revisions to iterate over.
        all_branches (bool): iterate over all available branches.
        all_commits (bool): iterate over all commits.
        all_tags (bool): iterate over all available tags.

    Yields:
        str: the display name for the currently selected tree, it could be:
            - a git revision identifier
            - empty string it there is no branches to iterate over
            - "Working Tree" if there are uncommitted changes in the SCM repo
    """
    if not any([revs, all_branches, all_tags, all_commits]):
        yield ""
        return

    saved_tree = self.tree
    revs = revs.copy() if revs else []

    scm = self.scm

    self.tree = WorkingTree(self.root_dir)
    yield "working tree"

    if revs and "working tree" in revs:
        revs.remove("working tree")

    if all_commits:
        revs = scm.list_all_commits()
    else:
        if all_branches:
            revs.extend(scm.list_branches())

        if all_tags:
            revs.extend(scm.list_tags())

    try:
        if revs:
            for sha, names in group_by(scm.resolve_rev, revs).items():
                self.tree = scm.get_tree(sha)
                yield ", ".join(names)
    finally:
        self.tree = saved_tree


# Traceback (FileNotFoundError)
NT> dvc metrics show -T
ERROR: unexpected error - [Errno 2] No such file

Having any troubles? Hit us up at https://dvc.org/support, we are always happy to help!
NT> dvc metrics show -T -v
2020-05-18 08:19:19,707 DEBUG: Trying to spawn '['c:\\program files\\python36\\python.exe', 'C:\\Program Files\\Python36
\\Scripts\\dvc', 'daemon', '-q', 'updater']'
2020-05-18 08:19:19,778 DEBUG: Spawned '['c:\\program files\\python36\\python.exe', 'C:\\Program Files\\Python36\\Script
s\\dvc', 'daemon', '-q', 'updater']'
2020-05-18 08:19:19,794 DEBUG: PRAGMA user_version;
2020-05-18 08:19:19,794 DEBUG: fetched: [(3,)]
2020-05-18 08:19:19,794 DEBUG: CREATE TABLE IF NOT EXISTS state (inode INTEGER PRIMARY KEY, mtime TEXT NOT NULL, size TE
XT NOT NULL, md5 TEXT NOT NULL, timestamp TEXT NOT NULL)
2020-05-18 08:19:19,825 DEBUG: CREATE TABLE IF NOT EXISTS state_info (count INTEGER)
2020-05-18 08:19:19,825 DEBUG: CREATE TABLE IF NOT EXISTS link_state (path TEXT PRIMARY KEY, inode INTEGER NOT NULL, mti
me TEXT NOT NULL)
2020-05-18 08:19:19,825 DEBUG: INSERT OR IGNORE INTO state_info (count) SELECT 0 WHERE NOT EXISTS (SELECT * FROM state_i
nfo)
2020-05-18 08:19:19,825 DEBUG: PRAGMA user_version = 3;
2020-05-18 08:19:19,965 DEBUG: SELECT count from state_info WHERE rowid=?
2020-05-18 08:19:19,981 DEBUG: fetched: [(38,)]
2020-05-18 08:19:19,981 DEBUG: UPDATE state_info SET count = ? WHERE rowid = ?
2020-05-18 08:19:20,059 ERROR: unexpected error - [Errno 2] No such file
------------------------------------------------------------
Traceback (most recent call last):
File "c:\program files\python36\lib\site-packages\dvc\main.py", line 49, in main
ret = cmd.run()
File "c:\program files\python36\lib\site-packages\dvc\command\metrics.py", line 49, in run
recursive=self.args.recursive,
File "c:\program files\python36\lib\site-packages\dvc\repo\metrics\__init__.py", line 13, in show
return show(self.repo, *args, **kwargs)
File "c:\program files\python36\lib\site-packages\dvc\repo\__init__.py", line 30, in wrapper
ret = f(repo, *args, **kwargs)
File "c:\program files\python36\lib\site-packages\dvc\repo\metrics\show.py", line 99, in show
metrics = _collect_metrics(repo, targets, recursive)
File "c:\program files\python36\lib\site-packages\dvc\repo\metrics\show.py", line 18, in _collect_metrics
for stage in repo.stages:
File "c:\program files\python36\lib\site-packages\funcy\objects.py", line 28, in __get__
res = instance.__dict__[self.fget.__name__] = self.fget(instance)
File "c:\program files\python36\lib\site-packages\dvc\repo\__init__.py", line 424, in stages
return self._collect_stages()
File "c:\program files\python36\lib\site-packages\dvc\repo\__init__.py", line 432, in _collect_stages
for root, dirs, files in self.tree.walk(self.root_dir):
File "c:\program files\python36\lib\site-packages\dvc\ignore.py", line 137, in walk
for root, dirs, files in self.tree.walk(top, topdown):
File "c:\program files\python36\lib\site-packages\dvc\scm\git\tree.py", line 139, in walk
raise IOError(errno.ENOENT, "No such file")
FileNotFoundError: [Errno 2] No such file
------------------------------------------------------------

Having any troubles? Hit us up at https://dvc.org/support, we are always happy to help!

# Fixed code
def brancher(  # noqa: E302
    self, revs=None, all_branches=False, all_tags=False, all_commits=False
):
    """Generator that iterates over specified revisions.

    Args:
        revs (list): a list of revisions to iterate over.
        all_branches (bool): iterate over all available branches.
        all_commits (bool): iterate over all commits.
        all_tags (bool): iterate over all available tags.

    Yields:
        str: the display name for the currently selected tree, it could be:
            - a git revision identifier
            - empty string it there is no branches to iterate over
            - "Working Tree" if there are uncommitted changes in the SCM repo
    """
    if not any([revs, all_branches, all_tags, all_commits]):
        yield ""
        return

    saved_tree = self.tree
    revs = revs.copy() if revs else []

    scm = self.scm

    self.tree = WorkingTree(self.root_dir)
    yield "working tree"

    if revs and "working tree" in revs:
        revs.remove("working tree")

    if all_commits:
        revs = scm.list_all_commits()
    else:
        if all_branches:
            revs.extend(scm.list_branches())

        if all_tags:
            revs.extend(scm.list_tags())

    try:
        if revs:
            for sha, names in group_by(scm.resolve_rev, revs).items():
                self.tree = scm.get_tree(sha)
                # ignore revs that don't contain repo root
                # (i.e. revs from before a subdir=True repo was init'ed)
                if self.tree.exists(self.root_dir):
                    yield ", ".join(names)
    finally:
        self.tree = saved_tree