Skip to content

Commit 732486c

Browse files
committed
feat: add branch option to CLI for cloning and ingesting specific branches
1 parent ee37d64 commit 732486c

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

src/gitingest/cli.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
@click.option("--exclude-pattern", "-e", multiple=True, help="Patterns to exclude (space-separated patterns allowed)")
1919
@click.option("--include-pattern", "-i", multiple=True, help="Patterns to include (space-separated patterns allowed)")
2020
@click.option("--ignore-file", default=".gitingestignore", help="Path to ignore file (default: .gitingestignore)")
21+
@click.option("--branch", "-b", default=None, help="Branch to clone and ingest")
2122
def main(
2223
source: str,
2324
output: str | None,
2425
max_size: int,
2526
exclude_pattern: tuple[str, ...],
2627
include_pattern: tuple[str, ...],
2728
ignore_file: str,
29+
branch: str | None,
2830
):
2931
"""
3032
Main entry point for the CLI.
@@ -44,8 +46,10 @@ def main(
4446
A tuple of patterns to include during the analysis. Only files matching these patterns will be processed.
4547
ignore_file : str
4648
Path to the ignore file containing additional patterns to exclude.
49+
branch : str | None
50+
The branch to clone (optional).
4751
"""
48-
asyncio.run(async_main(source, output, max_size, exclude_pattern, include_pattern, ignore_file))
52+
asyncio.run(async_main(source, output, max_size, exclude_pattern, include_pattern, ignore_file, branch))
4953

5054

5155
async def async_main(
@@ -55,6 +59,7 @@ async def async_main(
5559
exclude_pattern: tuple[str, ...],
5660
include_pattern: tuple[str, ...],
5761
ignore_file: str,
62+
branch: str | None,
5863
) -> None:
5964
"""
6065
Analyze a directory or repository and create a text dump of its contents.
@@ -78,6 +83,8 @@ async def async_main(
7883
A tuple of patterns to include during the analysis. Only files matching these patterns will be processed.
7984
ignore_file : str
8085
Path to the ignore file containing additional patterns to exclude.
86+
branch : str | None
87+
The branch to clone (optional).
8188
8289
Raises
8390
------
@@ -101,8 +108,8 @@ async def async_main(
101108
ignore_patterns = parse_ignore_file(ignore_file_path)
102109
exclude_patterns.update(ignore_patterns)
103110

104-
# Perform the ingest operation
105-
summary, *_ = await ingest(source, max_size, include_patterns, exclude_patterns, output=output)
111+
# Perform the ingest operation with branch support
112+
summary, *_ = await ingest(source, max_size, include_patterns, exclude_patterns, branch=branch, output=output)
106113

107114
# Display results
108115
click.echo(f"Analysis complete! Output written to: {output}")

src/gitingest/repository_ingest.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ async def ingest(
1616
max_file_size: int = 10 * 1024 * 1024, # 10 MB
1717
include_patterns: set[str] | str | None = None,
1818
exclude_patterns: set[str] | str | None = None,
19+
branch: str | None = None,
1920
output: str | None = None,
2021
) -> tuple[str, str, str]:
2122
"""
@@ -36,6 +37,8 @@ async def ingest(
3637
Pattern or set of patterns specifying which files to include. If `None`, all files are included.
3738
exclude_patterns : set[str] | str | None, optional
3839
Pattern or set of patterns specifying which files to exclude. If `None`, no files are excluded.
40+
branch : str | None, optional
41+
The branch to clone and ingest. If `None`, the default branch is used.
3942
output : str | None, optional
4043
File path where the summary and content should be written. If `None`, the results are not written to a file.
4144
@@ -62,6 +65,10 @@ async def ingest(
6265
)
6366

6467
if parsed_query.url:
68+
# Override branch if specified
69+
if branch is not None:
70+
parsed_query.branch = branch
71+
6572
# Extract relevant fields for CloneConfig
6673
clone_config = CloneConfig(
6774
url=parsed_query.url,

0 commit comments

Comments
 (0)