-
Notifications
You must be signed in to change notification settings - Fork 110
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
BF: More precise test for valid repo paths (fixes gh-3473) #3475
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3475 +/- ##
==========================================
- Coverage 91.26% 91.22% -0.04%
==========================================
Files 272 269 -3
Lines 34903 34898 -5
==========================================
- Hits 31853 31837 -16
- Misses 3050 3061 +11
Continue to review full report at Codecov.
|
return (Path(path) / '.git').exists() | ||
path = Path(path) / '.git' | ||
# the aim here is to have this test as cheap as possible, because | ||
# it is performed a lot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, this is why we avoid using a git rev-parse
-based solution.
datalad/support/gitrepo.py
Outdated
# file or symlink | ||
return path.exists() and ( | ||
(path.is_dir() and any(path.iterdir())) \ | ||
or not path.is_dir() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Very unlikely to be noticeable in practice, but since the comment says the aim is "as cheap as possible", you could avoid a is_dir() call:
diff --git a/datalad/support/gitrepo.py b/datalad/support/gitrepo.py
index c6658d010..8dbadd041 100644
--- a/datalad/support/gitrepo.py
+++ b/datalad/support/gitrepo.py
@@ -995,9 +995,8 @@ def is_valid_repo(cls, path):
# repo: 1) a non-empty .git directory (#3473) and 2) a pointer
# file or symlink
return path.exists() and (
- (path.is_dir() and any(path.iterdir())) \
- or not path.is_dir()
- )
+ not path.is_dir() or
+ any(path.iterdir()))
@staticmethod
def get_git_dir(repo):
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That is better. Thx!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Additionally check that a .git directory is not empty
This would fail before the previous commit.
You are an angel! |
(Seconding mih on that) |
The 3.7-dev run is failing with a segfault. (I repeated the run once.) https://travis-ci.org/datalad/datalad/jobs/544787756#L1472 That happens outside the added test, and I think it's safe to assume that it's unrelated. |
Additionally check that a .git directory is not empty