Parser for the git index file format.
| Class | |
Index entry that represents a conflict. |
| Class | |
A Git Index file. |
| Class | |
Represents an entry in the Git index. |
| Class | |
Base class for index extensions. |
| Class | locked |
Lock the index while making modifications. |
| Class | |
Resolve undo extension for recording merge conflicts. |
| Class | |
Represents a serialized index entry as stored in the index file. |
| Class | |
Sparse directory extension. |
| Class | |
Represents the stage of an index entry during merge conflicts. |
| Class | |
Tree cache extension. |
| Class | |
Untracked cache extension. |
| Exception | |
Unmerged entries exist in the index. |
| Exception | |
An unsupported index format was encountered. |
| Exception | |
Windows-specific error for symlink creation failures. |
| Function | blob |
Create a blob from a path and a stat object. |
| Function | blob |
Create a blob from a path and a stat object. |
| Function | build |
Build a file or symlink on disk based on a Git object. |
| Function | build |
Generate and materialize index from a tree. |
| Function | changes |
Find the differences between the contents of a tree and a working copy. |
| Function | cleanup |
Cleanup a mode value. |
| Function | commit |
Create a new tree from an index. |
| Function | commit |
Commit a new tree. |
| Function | detect |
Detect and transform case-only renames in a list of tree changes. |
| Function | get |
Get the appropriate path element normalization function based on config. |
| Function | get |
Walk through an index and check for differences against working tree. |
| Function | index |
Create an index entry for a directory. |
| Function | index |
Create an index from a filesystem path. |
| Function | index |
Create a new index entry from a stat value. |
| Function | iter |
Iterate over current versions of index entries on disk. |
| Function | iter |
Iterate over versions of objects on disk referenced by index. |
| Function | make |
Build a path normalizer honoring core.ignorecase and core.precomposeunicode. |
| Function | pathjoin |
Join a /-delimited path. |
| Function | pathsplit |
Split a /-delimited path into a directory part and a basename. |
| Function | read |
Read an entry from a cache file. |
| Function | read |
Read a cache time. |
| Function | read |
Read an index file, yielding the individual entries. |
| Function | read |
Read an index file and return it as a dictionary. |
| Function | read |
Read an index file and return it as a dictionary along with the version. |
| Function | read |
Read an index header from a file. |
| Function | read |
Read the head commit of a submodule. |
| Function | refresh |
Refresh the contents of an index. |
| Function | symlink |
Create a symbolic link on Windows with better error handling. |
| Function | update |
Update the working tree and index to match a new tree. |
| Function | validate |
Default path validator that just checks for .git/. |
| Function | validate |
Validate a path element using default rules. |
| Function | validate |
Validate path element for HFS+ filesystem. |
| Function | validate |
Validate a path element using NTFS filesystem rules. |
| Function | write |
Write an index entry to a file. |
| Function | write |
Write a cache time. |
| Function | write |
Write an index file. |
| Function | write |
Write an index file based on the contents of a dictionary. |
| Function | write |
Write an index extension. |
| Constant | DEFAULT |
Undocumented |
| Constant | EOIE |
Undocumented |
| Constant | EXTENDED |
Undocumented |
| Constant | EXTENDED |
Undocumented |
| Constant | FLAG |
Undocumented |
| Constant | FLAG |
Undocumented |
| Constant | FLAG |
Undocumented |
| Constant | FLAG |
Undocumented |
| Constant | FLAG |
Undocumented |
| Constant | HFS |
Undocumented |
| Constant | IEOT |
Undocumented |
| Constant | INVALID |
Undocumented |
| Constant | REUC |
Undocumented |
| Constant | SDIR |
Undocumented |
| Constant | TREE |
Undocumented |
| Constant | UNTR |
Undocumented |
| Type Alias | |
Undocumented |
| Variable | os |
Undocumented |
| Function | _check |
Check a single index entry for changes. |
| Function | _check |
Check if a file on disk matches the expected git object. |
| Function | _check |
Check if symlink target matches expected target. |
| Function | _compress |
Compress a path relative to the previous path for index version 4. |
| Function | _decode |
Decode a variable-width encoded integer. |
| Function | _decompress |
Decompress a path from index version 4 compressed format. |
| Function | _decompress |
Decompress a path from index version 4 compressed format, reading from stream. |
| Function | _encode |
Encode an integer using variable-width encoding. |
| Function | _ensure |
Ensure parent directory exists, checking no parent is a file. |
| Function | _fs |
Convert a file system path to a git tree path. |
| Function | _has |
Check if a directory has changed after getting an error. |
| Function | _normalize |
Normalize path element for default case-insensitive comparison. |
| Function | _normalize |
Normalize path element for HFS+ filesystem. |
| Function | _normalize |
Normalize path element for NTFS filesystem. |
| Function | _remove |
Remove empty parent directories up to stop_at. |
| Function | _remove |
Remove a file, handling read-only files on Windows. |
| Function | _stat |
Check if filesystem stat matches index entry stat. |
| Function | _transition |
Remove any type of entry. |
| Function | _transition |
Transition any type to regular file or symlink. |
| Function | _transition |
Transition any type to submodule. |
| Function | _tree |
Convert a git tree path to a file system path. |
bytes, st: os.stat_result, tree_encoding: str = 'utf-8') -> Blob:
¶
Create a blob from a path and a stat object.
Returns: A Blob object
| Parameters | |
fsbytes | Full file system path to file |
st:os.stat_result | A stat object |
treestr | Encoding to use for tree contents |
| Returns | |
Blob | Undocumented |
Blob, mode: int, target_path: bytes, *, honor_filemode: bool = True, tree_encoding: str = 'utf-8', symlink_fn: Callable[ [ (str | bytes | os.PathLike[ str]), (str | bytes | os.PathLike[ str])], None] | None = None) -> os.stat_result:
¶
Build a file or symlink on disk based on a Git object.
Returns: stat object for the file
| Parameters | |
blob:Blob | The git object |
mode:int | File mode |
targetbytes | Path to write to |
honorbool | An optional flag to honor core.filemode setting in config file, default is core.filemode=True, change executable bit |
treestr | Encoding to use for tree contents |
symlinkCallable[ | Function to use for creating symlinks |
| Returns | |
os.stat_result | Undocumented |
str | bytes, index_path: str | bytes, object_store: ObjectContainer, tree_id: ObjectID, honor_filemode: bool = True, validate_path_element: Callable[ [ bytes], bool] = validate_path_element_default, symlink_fn: Callable[ [ (str | bytes | os.PathLike[ str]), (str | bytes | os.PathLike[ str])], None] | None = None, blob_normalizer: FilterBlobNormalizer | None = None, tree_encoding: str = 'utf-8'):
¶
Generate and materialize index from a tree.
- Note: existing index is wiped and contents are not merged
- in a working dir. Suitable only for fresh clones.
| Parameters | |
rootstr | bytes | Target dir for materialized index files |
indexstr | bytes | Target path for generated index |
objectObjectContainer | Non-empty object store holding tree contents |
treeObjectID | Tree to materialize |
honorbool | An optional flag to honor core.filemode setting in config file, default is core.filemode=True, change executable bit |
validateCallable[ | Function to validate path elements to check out; default just refuses .git and .. directories. |
symlinkCallable[ | Function to use for creating symlinks |
blobFilterBlobNormalizer | None | An optional BlobNormalizer to use for converting line endings when writing blobs to the working directory. |
treestr | Encoding used for tree paths (default: utf-8) |
Iterable[ bytes], lookup_entry: Callable[ [ bytes], tuple[ bytes, int]], object_store: ObjectContainer, tree: ObjectID | None, want_unchanged: bool = False) -> Iterable[ tuple[ tuple[ bytes | None, bytes | None], tuple[ int | None, int | None], tuple[ bytes | None, bytes | None]]]:
¶
Find the differences between the contents of a tree and a working copy.
- Returns: Iterator over tuples with (oldpath, newpath), (oldmode, newmode),
- (oldsha, newsha)
| Parameters | |
names:Iterable[ | Iterable of names in the working copy |
lookupCallable[ | Function to lookup an entry in the working copy |
objectObjectContainer | Object store to use for retrieving tree contents |
tree:ObjectID | None | SHA1 of the root tree, or None for an empty tree |
wantbool | Whether unchanged files should be reported |
| Returns | |
Iterable[ | Undocumented |
Create a new tree from an index.
Note: This function is deprecated, use index.commit() instead. Returns: Root tree sha.
| Parameters | |
objectObjectContainer | Object store to save the tree in |
index:Index | Index file |
| Returns | |
ObjectID | Undocumented |
Detect and transform case-only renames in a list of tree changes.
This function identifies file renames that only differ in case (e.g., README.txt -> readme.txt) and transforms matching ADD/DELETE pairs into CHANGE_RENAME operations. It uses filesystem-appropriate path normalization based on the repository configuration.
| Parameters | |
changes:Sequence[ | List of TreeChange objects representing file changes |
config:Config | Repository configuration object |
| Returns | |
list[ | New list of TreeChange objects with case-only renames converted to CHANGE_RENAME |
Index, root_path: str | bytes, filter_blob_callback: Callable[ ..., Any] | None = None, preload_index: bool = False, trust_ctime: bool = True, max_stat: int | None = None) -> Generator[ bytes, None, None]:
¶
Walk through an index and check for differences against working tree.
Returns: iterator over paths with unstaged changes
| Parameters | |
index:Index | index to check |
rootstr | bytes | path in which to find files |
filterCallable[ | Optional callback to filter blobs |
preloadbool | If True, use parallel threads to check files (requires threading support) |
trustbool | If True, use ctime for change detection (default: True) |
maxint | None | If set, limit the number of stat operations performed. When the limit is reached, remaining files are assumed unchanged. |
| Returns | |
Generator[ | Undocumented |
Create an index entry for a directory.
This is only used for submodules (directories containing .git).
| Parameters | |
st:os.stat_result | Stat result for the directory |
path:bytes | Path to the directory |
| Returns | |
IndexEntry | None | IndexEntry for a submodule, or None if not a submodule |
bytes, object_store: ObjectContainer | None = None) -> IndexEntry | None:
¶
Create an index from a filesystem path.
This returns an index value for files, symlinks and tree references. for directories and non-existent files it returns None
Returns: An index entry; None for directories
| Parameters | |
path:bytes | Path to create an index entry for |
objectObjectContainer | None | Optional object store to save new blobs in |
| Returns | |
IndexEntry | None | Undocumented |
os.stat_result, hex_sha: bytes, mode: int | None = None) -> IndexEntry:
¶
Create a new index entry from a stat value.
| Parameters | |
statos.stat_result | POSIX stat_result instance |
hexbytes | Hex sha of the object |
mode:int | None | Optional file mode, will be derived from stat if not provided |
| Returns | |
IndexEntry | Undocumented |
Iterable[ bytes], root_path: bytes, object_store: ObjectContainer | None = None) -> Iterator[ tuple[ bytes, IndexEntry | None]]:
¶
Iterate over current versions of index entries on disk.
Returns: Iterator over path, index_entry
| Parameters | |
paths:Iterable[ | Paths to iterate over |
rootbytes | Root path to access from |
objectObjectContainer | None | Optional store to save new blobs in |
| Returns | |
Iterator[ | Undocumented |
Iterable[ bytes], root_path: bytes, include_deleted: bool = False, object_store: ObjectContainer | None = None) -> Iterator[ tuple[ bytes, ObjectID | None, int | None]]:
¶
Iterate over versions of objects on disk referenced by index.
Returns: Iterator over path, sha, mode
| Parameters | |
paths:Iterable[ | Paths to check |
rootbytes | Root path to access from |
includebool | Include deleted entries with sha and mode set to None |
objectObjectContainer | None | Optional object store to report new items to |
| Returns | |
Iterator[ | Undocumented |
Build a path normalizer honoring core.ignorecase and core.precomposeunicode.
The returned callable maps a filesystem-form path to a canonical form used to match equivalent paths (e.g. Foo.txt ↔ foo.txt when core.ignorecase=true, NFD ↔ NFC when core.precomposeunicode=true). Returns None when neither option is active so callers can skip the comparison entirely.
BinaryIO, version: int, previous_path: bytes = b'') -> SerializedIndexEntry:
¶
Read an entry from a cache file.
| Parameters | |
f:BinaryIO | File-like object to read from |
version:int | Index version |
previousbytes | Previous entry's path (for version 4 compression) |
| Returns | |
SerializedIndexEntry | Undocumented |
Read an index file and return it as a dictionary.
- Dict Key is tuple of path and stage number, as
- path alone is not unique
| Parameters | |
f:BinaryIO | File object to read fromls. |
| Returns | |
dict[ | Undocumented |
BinaryIO) -> tuple[ dict[ bytes, IndexEntry | ConflictedIndexEntry], int, list[ IndexExtension]]:
¶
Read an index file and return it as a dictionary along with the version.
| Returns | |
tuple[ | tuple of (entries_dict, version, extensions) |
str | bytes, dst: str | bytes, target_is_directory: bool = False, *, dir_fd: int | None = None):
¶
Create a symbolic link on Windows with better error handling.
| Parameters | |
src:str | bytes | Source path for the symlink |
dst:str | bytes | Destination path where symlink will be created |
targetbool | Whether the target is a directory |
dirint | None | Optional directory file descriptor |
| Raises | |
WindowsSymlinkPermissionError | If symlink creation fails due to permissions |
Repo, old_tree_id: bytes | None, new_tree_id: bytes, change_iterator: Iterator[ TreeChange], honor_filemode: bool = True, validate_path_element: Callable[ [ bytes], bool] | None = None, symlink_fn: Callable[ [ (str | bytes | os.PathLike[ str]), (str | bytes | os.PathLike[ str])], None] | None = None, force_remove_untracked: bool = False, blob_normalizer: FilterBlobNormalizer | None = None, tree_encoding: str = 'utf-8', allow_overwrite_modified: bool = False):
¶
Update the working tree and index to match a new tree.
This function handles: - Adding new files - Updating modified files - Removing deleted files - Cleaning up empty directories
| Parameters | |
repo:Repo | Repository object |
oldbytes | None | SHA of the tree before the update |
newbytes | SHA of the tree to update to |
changeIterator[ | Iterator of TreeChange objects to apply |
honorbool | An optional flag to honor core.filemode setting |
validateCallable[ | Function to validate path elements to check out |
symlinkCallable[ | Function to use for creating symlinks |
forcebool | If True, remove files that exist in working directory but not in target tree, even if old_tree_id is None |
blobFilterBlobNormalizer | None | An optional BlobNormalizer to use for converting line endings when writing blobs to the working directory. |
treestr | Encoding used for tree paths (default: utf-8) |
allowbool | If False, raise an error when attempting to overwrite files that have been modified compared to old_tree_id |
bytes, element_validator: Callable[ [ bytes], bool] = validate_path_element_default) -> bool:
¶
Default path validator that just checks for .git/.
Validate path element for HFS+ filesystem.
Equivalent to Git's is_hfs_dotgit and related checks. Uses NFD normalization and ignores HFS+ ignorable characters.
IO[ bytes], entry: SerializedIndexEntry, version: int, previous_path: bytes = b''):
¶
Write an index entry to a file.
| Parameters | |
f:IO[ | File object |
entry:SerializedIndexEntry | IndexEntry to write |
version:int | Index format version |
previousbytes | Previous entry's path (for version 4 compression) |
IO[ bytes], entries: Sequence[ SerializedIndexEntry], version: int | None = None, extensions: Sequence[ IndexExtension] | None = None):
¶
Write an index file.
| Parameters | |
f:IO[ | File-like object to write to |
entries:Sequence[ | Iterable over the entries to write |
version:int | None | Version number to write |
extensions:Sequence[ | Optional list of extensions to write |
IO[ bytes], entries: Mapping[ bytes, IndexEntry | ConflictedIndexEntry], version: int | None = None, extensions: Sequence[ IndexExtension] | None = None):
¶
Write an index file based on the contents of a dictionary.
being careful to sort by path and then by stage.
Write an index extension.
| Parameters | |
f:IO[ | File-like object to write to |
extension:IndexExtension | Extension to write |
bytes, entry: IndexEntry | ConflictedIndexEntry, root_path: bytes, filter_blob_callback: Callable[ [ Blob, bytes], Blob] | None = None, trust_ctime: bool = True) -> bytes | None:
¶
Check a single index entry for changes.
Returns: tree_path if changed, None otherwise
| Parameters | |
treebytes | Path in the tree |
entry:IndexEntry | ConflictedIndexEntry | Index entry to check |
rootbytes | Root filesystem path |
filterCallable[ | Optional callback to filter blobs |
trustbool | If True, use ctime for change detection (default: True) |
| Returns | |
bytes | None | Undocumented |
BaseObjectStore, full_path: bytes, entry_sha: ObjectID, entry_mode: int, current_stat: os.stat_result, honor_filemode: bool, blob_normalizer: FilterBlobNormalizer | None = None, tree_path: bytes | None = None) -> bool:
¶
Check if a file on disk matches the expected git object.
Returns True if file matches, False if it doesn't match.
bytes, repo_object_store: BaseObjectStore, entry_sha: ObjectID) -> bool:
¶
Check if symlink target matches expected target.
Returns True if symlink matches, False if it doesn't match.
Check if a directory has changed after getting an error.
When handling an error trying to create a blob from a path, call this function. It will check if the path is a directory. If it's a directory and a submodule, check the submodule head to see if it's has changed. If not, consider the file as changed as Git tracked a file and not a directory.
Return true if the given path should be considered as changed and False otherwise or if the path is not a directory.
Check if filesystem stat matches index entry stat.
This is used to determine if a file might have changed without reading its content. Git uses this optimization to avoid expensive filter operations on unchanged files.
Returns: True if stat matches and file is likely unchanged
| Parameters | |
st:os.stat_result | Filesystem stat result |
entry:IndexEntry | Index entry to compare against |
trustbool | If True, also check ctime (default: True, matching Git behavior) |
| Returns | |
bool | Undocumented |
Repo, path: bytes, full_path: bytes, current_stat: os.stat_result | None, index: Index):
¶
Remove any type of entry.
BaseObjectStore, path: bytes, full_path: bytes, current_stat: os.stat_result | None, entry: IndexEntry | TreeEntry, index: Index, honor_filemode: bool, symlink_fn: Callable[ [ (str | bytes | os.PathLike[ str]), (str | bytes | os.PathLike[ str])], None] | None, blob_normalizer: FilterBlobNormalizer | None, tree_encoding: str = 'utf-8'):
¶
Transition any type to regular file or symlink.
Repo, path: bytes, full_path: bytes, current_stat: os.stat_result | None, entry: IndexEntry | TreeEntry, index: Index):
¶
Transition any type to submodule.