Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

brancher: do not get tree if there's no revs #3211

Merged
merged 1 commit into from
Jan 22, 2020

Conversation

skshetry
Copy link
Member

@skshetry skshetry commented Jan 22, 2020

From #3207 (comment)

When if it's a dvc only repo, brancher was failing as NoSCM does not have resolve_rev.

$ dvc init --no-scm
$ python -c '
from dvc.repo import Repo
repo = Repo(".")
print(list(repo.brancher(all_branches=True, all_commits=True, all_tags=True)))
'
Traceback (most recent call last):
  File "<string>", line 4, in <module>
  File "/home/saugat/repos/iterative/dvc/dvc/repo/brancher.py", line 45, in brancher
    for sha, names in group_by(scm.resolve_rev, revs).items():
AttributeError: 'NoSCM' object has no attribute 'resolve_rev'
  • ❗ Have you followed the guidelines in the Contributing to DVC list?

  • 📖 Check this box if this PR does not require documentation updates, or if it does and you have created a separate PR in dvc.org with such updates (or at least opened an issue about it in that repo). Please link below to your PR (or issue) in the dvc.org repo.

  • ❌ Have you checked DeepSource, CodeClimate, and other sanity checks below? We consider their findings recommendatory and don't expect everything to be addressed. Please review them carefully and fix those that actually improve code or fix bugs.

Thank you for the contribution - we'll try to review it as soon as possible. 🙏

@skshetry skshetry added the bug Did we break something? label Jan 22, 2020
@skshetry skshetry requested review from Suor and efiop January 22, 2020 11:38
@skshetry skshetry self-assigned this Jan 22, 2020
@skshetry skshetry requested a review from pared January 22, 2020 11:41
Copy link
Contributor

@efiop efiop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice catch! Thanks!

@efiop efiop merged commit b99c5e4 into iterative:master Jan 22, 2020
@skshetry skshetry deleted the fix-brancher-noscm branch January 22, 2020 12:30
for sha, names in group_by(scm.resolve_rev, revs).items():
self.tree = scm.get_tree(sha)
yield ", ".join(names)
if revs:
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this should be caught by:

    if not any([revs, all_branches, all_tags, all_commits]):
        yield ""
        return

🤔

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ohhh, but I saw that you were doing all_*=True 🙂

Copy link

@ghost ghost Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, @skshetry , why didn't you solve it by using if not scm: return ?

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I understand, brancher doesn't have anything to do when NoSCM is used.

So, it would be:

    scm = self.scm

    if not any([revs, all_branches, all_tags, all_commits]) or not scm:
        yield ""
        return

I guess that, since the end result is the same, it doesn't matter

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

scm is always there. If it's a non-git repo, it will be NoSCM.
Honestly, I didn't really feel confident around brancher() (this is an uncovered corner). I really just added here because of the finally statement here that resets the self.tree.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which doesn't make your point wrong, I'm just saying.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@efiop , I don't get why revs=["something"] is intentionally breaking it but no all_commits=True.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@MrOutis because it expects to receive revs that are valid in the scm that we are operating in and there are no valid revs in NoSCM. And all_commits=True asks scm for list of all commits, which are [] for NoSCM. I agree that brancher could be improved to handle those cases more smoothly, but this fix does get the job done in this case.

Copy link
Member Author

@skshetry skshetry Jan 23, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as my understanding goes, the NoSCM case and working tree should not even be the concern of the brancher().

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like someone has been here and changed things, and forgot to update the docstrings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Did we break something?
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants