datalad_next.iter_collections.gitworktree
Report on the content of a Git repository worktree
The main functionality is provided by the iter_gitworktree() function.
- class datalad_next.iter_collections.gitworktree.GitWorktreeFileSystemItem(type: 'FileSystemItemType', name: 'PurePath', size: 'int', mtime: 'float | None' = None, mode: 'int | None' = None, uid: 'int | None' = None, gid: 'int | None' = None, link_target: 'Any | None' = None, fp: 'IO | None' = None, gitsha: 'str | None' = None, gittype: 'GitTreeItemType | None' = None)[source]
Bases:
FileSystemItem- gitsha: str | None = None
- gittype: GitTreeItemType | None = None
- name: PurePath
- class datalad_next.iter_collections.gitworktree.GitWorktreeItem(name: 'PurePath', gitsha: 'str | None' = None, gittype: 'GitTreeItemType | None' = None)[source]
Bases:
GitTreeItem- name: PurePath
- datalad_next.iter_collections.gitworktree.iter_gitworktree(path: Path, *, untracked: str | None = 'all', link_target: bool = False, fp: bool = False, recursive: str = 'repository') Generator[GitWorktreeItem | GitWorktreeFileSystemItem, None, None][source]
Uses
git ls-filesto report on a work tree of a Git repositoryThis iterator can be used to report on all tracked, and untracked content of a Git repository's work tree. This includes files that have been removed from the work tree (deleted), unless their removal has already been staged.
For any tracked content, yielded items include type information and gitsha as last known to Git. This means that such reports reflect the last committed or staged content, not the state of a potential unstaged modification in the work tree.
When no reporting of link targets or file-objects are requested, items of type
GitWorktreeItemare yielded, otherwiseGitWorktreeFileSystemIteminstances. In both cases,gitshaandgittypeproperties are provided. Either of them beingNoneindicates untracked work tree content.Note
The
gitshais not equivalent to a SHA1 hash of a file's content, but is the SHA-type blob identifier as reported and used by Git.- Parameters:
path (Path) -- Path of a directory in a Git repository to report on. This directory need not be the root directory of the repository, but must be part of the repository's work tree.
untracked ({'all', 'whole-dir', 'no-empty-dir'} or None, optional) -- If not
None, also reports on untracked work tree content.allreports on any untracked file;whole-diryields a single report for a directory that is entirely untracked, and not individual untracked files in it;no-empty-dirskips any reports on untracked empty directories.link_target (bool, optional) -- If
True, information matching aFileSystemItemwill be included for each yielded item, and the targets of any symlinks will be reported, too.fp (bool, optional) -- If
True, information matching aFileSystemItemwill be included for each yielded item, but without a link target detection, unlesslink_targetis given. Moreover, each file-type item includes a file-like object to access the file's content. This file handle will be closed automatically when the next item is yielded.recursive ({'repository', 'no'}, optional) -- Behavior for recursion into subdirectories of
path. By default (repository), all directories within the repository are reported. This possibly includes untracked ones (seeuntracked), but not directories within submodules. Ifno, only direct children ofpathare reported on. For any worktree items in subdirectories ofpathonly a single record for the containing immediate subdirectorypathis yielded. For example, with 'path/subdir/file1' and 'path/subdir/file2' there will only be a single item withname='subdir'andtype='directory'.
- Yields:
GitWorktreeItemorGitWorktreeFileSystemItem-- Thenameattribute of an item is aPurePathinstance with the corresponding (relative) path, in platform conventions.