Skip to content

Commit f781934

Browse files
Junaid SyedJunaid Syed
authored andcommitted
Docs: Add examples for multiple patterns and API usage to README
1 parent bf5d760 commit f781934

File tree

1 file changed

+71
-0
lines changed

1 file changed

+71
-0
lines changed

README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,23 @@ gitingest --help
8989

9090
This will write the digest in a text file (default `digest.txt`) in your current working directory.
9191

92+
### Using Multiple Patterns (CLI)
93+
94+
You can specify multiple patterns to include or exclude files and directories by repeating the respective flags (-e for exclude, -i for include). Patterns use standard shell wildcards.
95+
96+
```bash
97+
# Example 1: Exclude all log files, temporary files, and the entire 'dist' directory
98+
gitingest /path/to/your/project -e "*.log" -e "*.tmp" -e "dist/"
99+
100+
# Example 2: Include only Python files and Markdown files from the repository
101+
gitingest https://github.com/user/repo -i "*.py" -i "*.md"
102+
103+
# Example 3: Exclude test directories and specific config files from the current directory (.)
104+
gitingest . -e "tests/" -e "**/config.dev.json" -e "node_modules/"
105+
```
106+
107+
Remember that exclusion patterns take precedence. If specific include patterns are provided, only files matching those and not matching any exclude pattern will be processed.
108+
92109
## 🐍 Python package usage
93110

94111
```python
@@ -111,6 +128,60 @@ import asyncio
111128
result = asyncio.run(ingest_async("path/to/directory"))
112129
```
113130

131+
### Advanced Pattern Usage (Python API)
132+
133+
The Python API allows for fine-grained control by combining include_patterns and exclude_patterns. When both are provided:
134+
135+
Files/directories are first checked against all exclusion patterns (default built-in patterns + user-provided exclude_patterns). If a match occurs, the item is skipped.
136+
137+
If include_patterns are specified, any remaining item must also match at least one of the include patterns to be kept. If include_patterns is None or empty, this step is skipped.
138+
139+
```python
140+
# Advanced Python API Example
141+
from gitingest import ingest
142+
import asyncio
143+
144+
# Scenario: Ingest only files within the 'src/' directory of a specific branch,
145+
# but explicitly exclude any '.log' files found within 'src/'.
146+
147+
repo_source = "https://github.com/some/repo"
148+
target_branch = "develop"
149+
include_only_src = {"src/*"} # Glob pattern to match items directly inside src/
150+
exclude_src_logs = {"src/*.log"} # Pattern to exclude log files specifically within src/
151+
152+
# --- Synchronous Usage ---
153+
print("Running synchronous ingest with patterns...")
154+
summary_sync, tree_sync, content_sync = ingest(
155+
repo_source,
156+
branch=target_branch,
157+
include_patterns=include_only_src,
158+
exclude_patterns=exclude_src_logs
159+
# Note: Default ignores like .git/, .venv/ are still active automatically
160+
)
161+
162+
print("\n--- Sync Summary ---")
163+
print(summary_sync)
164+
# The resulting tree and content will only contain non-log files
165+
# directly within the 'src/' directory of the 'develop' branch.
166+
167+
# --- Asynchronous Usage ---
168+
async def run_async_ingest():
169+
print("\nRunning asynchronous ingest with patterns...")
170+
summary_async, tree_async, content_async = await ingest_async(
171+
repo_source,
172+
branch=target_branch,
173+
include_patterns=include_only_src,
174+
exclude_patterns=exclude_src_logs
175+
)
176+
print("\n--- Async Summary ---")
177+
print(summary_async)
178+
179+
# Run the async example
180+
# asyncio.run(run_async_ingest())
181+
```
182+
183+
This setup ensures that even if src/ contains log files, they will be explicitly removed from the final digest, while only other files directly within src/ are included.
184+
114185
### Jupyter notebook usage
115186

116187
```python

0 commit comments

Comments
 (0)