Sparse checkout pattern handling.
| Exception | |
Raised when a requested blob is not found in the repository's object store. |
| Exception | |
Raised when local modifications would be overwritten by a sparse checkout operation. |
| Function | apply |
Apply the sparse-checkout inclusion set to the index and working tree. |
| Function | compute |
Implement a simplified 'cone' approach for sparse-checkout. |
| Function | compute |
Use .gitignore-style parsing and matching to determine included paths. |
| Function | determine |
Determine which paths in the index should be included based on either a full-pattern match or a cone-mode approach. |
| Function | match |
Check whether a path is included based on .gitignore-style patterns. |
| Function | parse |
Parse pattern lines from a sparse-checkout file (.git/info/sparse-checkout). |
Apply the sparse-checkout inclusion set to the index and working tree.
This function updates skip-worktree bits in the index based on whether each path is included or not. It then adds or removes files in the working tree accordingly. If force=False, files that have local modifications will cause an error instead of being removed.
| Parameters | |
repo:Repo | A path to the repository or a Repo object. |
includedSet[ | A set of paths (strings) that should remain included. |
force:bool | Whether to forcibly remove locally modified files (default False). |
| Returns | |
| None |
Implement a simplified 'cone' approach for sparse-checkout.
By default, this can include top-level files, exclude all subdirectories, and re-include specified directories. The logic is less comprehensive than Git's built-in cone mode (recursive vs parent) and is essentially an implementation of the recursive cone mode.
| Parameters | |
index:Index | An Index object containing the repository's index. |
lines:Sequence[ | A list of pattern lines (strings), typically including entries like "/", "!//", or "/mydir/". |
| Returns | |
set[ | A set of included path strings. |
Use .gitignore-style parsing and matching to determine included paths.
Each file path in the index is tested against the parsed sparse patterns. If it matches the final (most recently applied) positive pattern, it is included.
| Parameters | |
index:Index | An Index object containing the repository's index. |
lines:Sequence[ | A list of pattern lines (strings) from sparse-checkout config. |
| Returns | |
set[ | A set of included path strings. |
Determine which paths in the index should be included based on either a full-pattern match or a cone-mode approach.
| Parameters | |
index:Index | An Index object containing the repository's index. |
lines:Sequence[ | A list of pattern lines (strings) from sparse-checkout config. |
cone:bool | A bool indicating cone mode. |
| Returns | |
set[ | A set of included path strings. |
str, parsed_patterns: Sequence[ tuple[ str, bool, bool, bool]], path_is_dir: bool = False) -> bool:
¶
Check whether a path is included based on .gitignore-style patterns.
- This is a simplified approach that:
- Iterates over patterns in order.
- If a pattern matches, we set the "include" state depending on negation.
- Later matches override earlier ones.
In a sparse checkout, lines that do not start with '!' are positive patterns, indicating files/directories to check out (include in the index), and those that start with '!' are negative ('negated'), meaning they indicate files not to check out (not included in the index). This is fairly straightforward.
In a .gitignore, it's the same syntax but with a reverse effect: positive means "ignore" (exclude from the index) and negative means "unignore" (re-include in the index).
Many routines still rely on the same final logic: the last matching pattern decides "excluded" vs. "included."
We'll interpret "include" as returning True, "exclude" as returning False.
Each pattern can include negation ('!'), directory-only markers ('/' as suffix), or be anchored ('/' as prefix). The last matching pattern determines whether the path is ultimately included or excluded.
| Parameters | |
pathstr | The path (string) to test. |
parsedSequence[ | A list of (pattern, negation, dir_only, anchored) tuples as returned by parse_sparse_patterns. |
pathbool | Whether to treat the path as a directory (default False). |
| Returns | |
bool | True if the path is included by the last matching pattern, False otherwise. |
Parse pattern lines from a sparse-checkout file (.git/info/sparse-checkout).
- This simplified parser:
- Strips comments (#...) and empty lines.
- Returns a list of (pattern, is_negation, is_dir_only, anchored) tuples.
These lines are similar to .gitignore patterns but are used for sparse-checkout logic. This function strips comments and blank lines, identifies negation, anchoring, and directory-only markers, and returns data suitable for matching.
Example
line = "*.txt" -> ("*.txt", False, False, False) not negated/dir/anchored line = "/*.txt" -> ("*.txt", False, False, True) anchored, not negated/dir line = "!/*.txt" -> ("*.txt", False, False, True) anchored/negated, not dir line = "!/mydir/" -> ("mydir", True, True, True) anchored/negated/dir
| Parameters | |
lines:Sequence[ | A list of raw lines (strings) from the sparse-checkout file. |
| Returns | |
list[ | A list of tuples (pattern, negation, dir_only, anchored), representing the essential details needed to perform matching. |