Skip to content

Commit

Permalink
feat(GitWorktreeFileSystemItem): method to convert GitWorktreeItem
Browse files Browse the repository at this point in the history
This plan is to use this helper as a standard for such conversions,
rather than the establish complex conditional in the code.
  • Loading branch information
mih committed Jun 11, 2024
1 parent 6ecbb6a commit 3085878
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions datalad_next/iter_collections/gitworktree.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,34 @@ class GitWorktreeFileSystemItem(FileSystemItem):
gitsha: str | None = None
gittype: GitTreeItemType | None = None

@classmethod
def from_worktreeitem(
cls,
basepath: Path,
item: GitWorktreeItem,
link_target: bool = True,
):
"""Create GitWorktreeFileSystemItem from corresponding GitWorktreeItem
Parameters
----------
basepath: Path
Reference path to convert the ``GitWorktreeItem``'s path into a
path on the file system.
item: GitWorktreeItem
Item to create matching ``GitWorktreeFileSystemItem`` for.
link_target: bool
Flag whether to read out a link-target for an item that is a symlink.
"""
fsitem = GitWorktreeFileSystemItem.from_path(
path=item.path(),
link_target=link_target,
)
fsitem.name = item.name
fsitem.gitsha = item.gitsha
fsitem.gittype = item.gittype
return fsitem


lsfiles_untracked_args = {
'all':
Expand Down

0 comments on commit 3085878

Please sign in to comment.