|
5 | 5 | import sys |
6 | 6 | import uuid |
7 | 7 | from asyncio import Lock |
8 | | -from typing import Iterable |
| 8 | +from typing import Iterable, Optional |
9 | 9 |
|
10 | 10 | import pathspec |
11 | 11 | import tabulate |
|
14 | 14 | from chromadb.api.types import IncludeEnum |
15 | 15 |
|
16 | 16 | from vectorcode.chunking import Chunk, TreeSitterChunker |
17 | | -from vectorcode.cli_utils import Config, expand_globs, expand_path |
| 17 | +from vectorcode.cli_utils import ( |
| 18 | + GLOBAL_EXCLUDE_SPEC, |
| 19 | + GLOBAL_INCLUDE_SPEC, |
| 20 | + Config, |
| 21 | + expand_globs, |
| 22 | + expand_path, |
| 23 | +) |
18 | 24 | from vectorcode.common import get_client, get_collection, verify_ef |
19 | 25 |
|
20 | 26 |
|
@@ -120,11 +126,18 @@ def include_paths_by_spec(paths: Iterable[str], specs: pathspec.PathSpec) -> lis |
120 | 126 |
|
121 | 127 | def load_files_from_include(project_root: str) -> list[str]: |
122 | 128 | include_file_path = os.path.join(project_root, ".vectorcode", "vectorcode.include") |
| 129 | + specs: Optional[pathspec.GitIgnoreSpec] = None |
123 | 130 | if os.path.isfile(include_file_path): |
124 | 131 | with open(include_file_path) as fin: |
125 | 132 | specs = pathspec.GitIgnoreSpec.from_lines( |
126 | 133 | lines=(os.path.expanduser(i) for i in fin.readlines()), |
127 | 134 | ) |
| 135 | + elif os.path.isfile(GLOBAL_INCLUDE_SPEC): |
| 136 | + with open(GLOBAL_INCLUDE_SPEC) as fin: |
| 137 | + specs = pathspec.GitIgnoreSpec.from_lines( |
| 138 | + lines=(os.path.expanduser(i) for i in fin.readlines()), |
| 139 | + ) |
| 140 | + if specs is not None: |
128 | 141 | return [ |
129 | 142 | result.file |
130 | 143 | for result in specs.check_tree_files(project_root) |
@@ -160,6 +173,8 @@ async def vectorise(configs: Config) -> int: |
160 | 173 | ) |
161 | 174 | if os.path.isfile(exclude_spec_path): |
162 | 175 | specs.append(exclude_spec_path) |
| 176 | + elif os.path.isfile(GLOBAL_EXCLUDE_SPEC): |
| 177 | + specs.append(GLOBAL_EXCLUDE_SPEC) |
163 | 178 | for spec_path in specs: |
164 | 179 | if os.path.isfile(spec_path): |
165 | 180 | with open(spec_path) as fin: |
|
0 commit comments