generated from datalad/datalad-extension-template
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #673 from mih/bf-670
Enable running `iter_annexworktree()` on just-Git repos
- Loading branch information
Showing
6 changed files
with
100 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
### 🐛 Bug Fixes | ||
|
||
- `iter_annexworktree()` can now also be used on plain Git repos, | ||
and would behave exactly as if reporting on non-annexed files | ||
in a git-annex repo. Previously, a cryptic `iterable did not yield | ||
matching item for route-in item, cardinality mismatch?` error was | ||
issued in this case. | ||
Fixes https://github.com/datalad/datalad-next/issues/670 via | ||
https://github.com/datalad/datalad-next/pull/673 (by @mih) | ||
|
||
### 💫 Enhancements and new features | ||
|
||
- A new `has_initialized_annex()` helper function is provided to | ||
test for a locally initialized annex in a repo. | ||
Via https://github.com/datalad/datalad-next/pull/673 (by @mih) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
from pathlib import Path | ||
|
||
from datalad_next.runners import call_git_success | ||
|
||
|
||
def has_initialized_annex( | ||
path: Path, | ||
) -> bool: | ||
"""Return whether there is an initialized annex for ``path`` | ||
The given ``path`` can be any directory, inside or outside a Git | ||
repository. ``True`` is returned when the path is found to be | ||
within a (locally) initialized git-annex repository. | ||
When this test returns ``True`` it can be expected that no subsequent | ||
call to an annex command fails with | ||
`git-annex: First run: git-annex init` | ||
for this ``path``. | ||
""" | ||
# this test is about 3ms in MIH's test system. | ||
# datalad-core tests for a git repo and then for .git/annex, this | ||
# achieves both in one step (although the test in datalad-core is | ||
# likely still faster, because it only inspects the filesystem | ||
# for a few key members of a Git repo. In order for that test to | ||
# work, though, it has to traverse the filesystem to find a repo root | ||
# -- if there even is any). | ||
# also ee https://git-annex.branchable.com/forum/Cheapest_test_for_an_initialized_annex__63__/ | ||
return call_git_success( | ||
['config', '--local', 'annex.uuid'], | ||
cwd=path, | ||
capture_output=True, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
from ..annex import has_initialized_annex | ||
|
||
|
||
def test_has_initialized_annex(existing_dataset): | ||
# for the root | ||
assert has_initialized_annex(existing_dataset.pathobj) | ||
# for a subdir | ||
assert has_initialized_annex(existing_dataset.pathobj / '.datalad') | ||
|
||
|
||
def test_no_initialized_annex(existing_noannex_dataset, tmp_path): | ||
# for the root | ||
assert not has_initialized_annex(existing_noannex_dataset.pathobj) | ||
# for a subdir | ||
assert not has_initialized_annex( | ||
existing_noannex_dataset.pathobj / '.datalad') | ||
# for a random directory | ||
assert not has_initialized_annex(tmp_path) |