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

repo: raise exception if root_dir is not a directory path #3295

Merged
merged 2 commits into from
Feb 10, 2020

Conversation

skshetry
Copy link
Member

When Repo is instantiated with invalid urls such as 'http://github.com/iterative/dvc.git',
it does os.path.realpath which is not intelligent enough and just concatenates with current
working directory, which is then traversed outward. It might happen that the outward folder
is a dvc directory which is not really what we want.

So, a check for root to be a directory is added. Otherwise, NotDvcRepoError is thrown with
a custom message.

TLDR: Repo("https://github.com") and Repo("not existing directory") should throw NotDvcRepoError even if dvc repo exists outward.

  • ❗ 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. 🙏

When Repo is instantiated with invalid urls such as 'http://github.com/iterative/dvc.git',
it does os.path.realpath which is not intelligent enough and just concatenates with current
working directory, which is then traversed outward. It might happen that the outward folder
is a dvc directory which is not really what we want.

So, a check for root to be a directory is added. Otherwise, NotDvcRepoError is thrown with
a custom message.
@skshetry skshetry added the enhancement Enhances DVC label Feb 10, 2020
@skshetry skshetry requested a review from efiop February 10, 2020 09:45
@skshetry skshetry self-assigned this Feb 10, 2020
dvc/exceptions.py Outdated Show resolved Hide resolved
dvc/repo/__init__.py Outdated Show resolved Hide resolved
@skshetry skshetry requested a review from efiop February 10, 2020 14:27
@skshetry skshetry changed the title repo: throw if root_dir in Repo.__init__() is not a directory path repo: raise exception if root_dir is not a directory path Feb 10, 2020
Copy link
Contributor

@pared pared left a comment

Choose a reason for hiding this comment

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

One minor thing to consider.

dvc/repo/__init__.py Outdated Show resolved Hide resolved
dvc/repo/__init__.py Outdated Show resolved Hide resolved
@skshetry skshetry force-pushed the repo-throw-if-not-isdir branch from 4cbb454 to 648785d Compare February 10, 2020 17:45
@efiop efiop merged commit 8610c0c into iterative:master Feb 10, 2020
@skshetry skshetry deleted the repo-throw-if-not-isdir branch February 11, 2020 00:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhances DVC
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants